FDW and connections

From: Phil Godfrin <pgodfrin(at)comcast(dot)net>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: philippe(dot)godfrin(at)nov(dot)com
Subject: FDW and connections
Date: 2021-05-16 12:57:01
Message-ID: 9982ce64-5b5b-9489-0748-ac25aea46b53@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greetings!

Let say I have a foreign server using the reference postgres_fdw defined
without a port number:

CREATE SERVER /dat_server/ FOREIGN DATA WRAPPER /postgres_fdw/ OPTIONS (
|/host '172.1.1.1', dbname 'dbover_der'/| )

Naturally the tables in question are setup using a foreign table
definition, specifying the foreign server /dat_server/. My understanding
is when the sql is ready for execution whatever is determined to be
pushed down is sent to the foreign server. Taking a look at the code it
appears in postgres_fdw.c a connection is probably made in dat case:

/* for remote query execution */
    PGconn       *conn;            /* connection for the scan */
    PgFdwConnState *conn_state; /* extra per-connection state */

and

/*
     * Get connection to the foreign server.  Connection manager will
     * establish new connection if necessary.
     */
    fsstate->conn = GetConnection(user, false, &fsstate->conn_state);

My question is - how does the call to GetConnection() know what port to
use? Lets say we're using PGBouncer to connect on the local server at
port 6432, but there is no pgbouncer listening at the foreign server,
what port gets passed? My first thought is whatever the client connects
port is, but I believe pgbouncer ultimately hands of the connection to
whatever port you have defined for the local database...

This gets important when one has an HAProxy instance between the local
and foreign servers which is interrogating the port number to decide
which ip:port to send the request to, ultimately the master or replicant
at the foreign remoter server.

So how does the port number get propagated from local to foreign server???

Much thanks for your help.

Phil Godfrin

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2021-05-16 13:29:30 Re: Typo in README.barrier
Previous Message David Rowley 2021-05-16 12:51:50 Re: Typo in README.barrier