PG fdw connection establishment and closure

Keywords: PostgreSQL Linux Ubuntu Unix

PG starts psql locally, accesses external tables, and exits

The connection between PG and remotePG is broken as the client psql exits.

 

PG starts multiple psqls locally, and each psql accesses the external table once

View remotePG process

postgres@ubuntu:~$ ps -ef|grep post
root       134    89  0 09:36 pts/0    00:00:00 su postgres
postgres   135   134  0 09:36 pts/0    00:00:00 bash
postgres   150     1  0 09:37 pts/0    00:00:01 /usr/lib/postgresql/10/bin/postgres -D /usr/local/pgsql/data
postgres   152   150  0 09:37 ?        00:00:00 postgres: checkpointer process   
postgres   153   150  0 09:37 ?        00:00:00 postgres: writer process   
postgres   154   150  0 09:37 ?        00:00:00 postgres: wal writer process   
postgres   155   150  0 09:37 ?        00:00:00 postgres: autovacuum launcher process   
postgres   156   150  0 09:37 ?        00:00:02 postgres: stats collector process   
postgres   157   150  0 09:37 ?        00:00:00 postgres: bgworker: logical replication launcher   
postgres   389   150  0 10:19 ?        00:00:00 postgres: postgres postgres 192.168.55.60(55814) idle
postgres   392   150  0 10:19 ?        00:00:00 postgres: postgres postgres 192.168.55.60(55816) idle
postgres   478   135  0 11:00 pts/0    00:00:00 ps -ef
postgres   479   135  0 11:00 pts/0    00:00:00 grep post
postgres@ubuntu:~$ date
Sun Sep 30 11:00:16 DST 2018

View local PG process

[root@localhost ~]# ps -ef|grep post
postgres   1098      1  0 21:39 ?        00:00:00 /usr/local/postgresql/bin/postmaster -D /usr/local/postgresql/data
postgres   1124   1098  0 21:39 ?        00:00:00 postgres: checkpointer process   
postgres   1125   1098  0 21:39 ?        00:00:00 postgres: writer process   
postgres   1126   1098  0 21:39 ?        00:00:00 postgres: wal writer process   
postgres   1127   1098  0 21:39 ?        00:00:00 postgres: autovacuum launcher process   
postgres   1128   1098  0 21:39 ?        00:00:00 postgres: stats collector process   
postgres   1129   1098  0 21:39 ?        00:00:00 postgres: bgworker: logical replication launcher   
root       1247      1  0 21:39 ?        00:00:00 /usr/libexec/postfix/master -w
postfix    1251   1247  0 21:39 ?        00:00:00 pickup -l -t unix -u
postfix    1252   1247  0 21:39 ?        00:00:00 qmgr -l -t unix -u
root       1959   1920  0 21:54 pts/0    00:00:00 su postgres
postgres   1961   1959  0 21:54 pts/0    00:00:00 bash
root       2081   2064  0 22:18 pts/2    00:00:00 su postgres
postgres   2082   2081  0 22:18 pts/2    00:00:00 bash
postgres   2097   2082  0 22:18 pts/2    00:00:00 psql
postgres   2098   1098  0 22:18 ?        00:00:00 postgres: postgres postgres [local] idle
postgres   2099   1961  0 22:18 pts/0    00:00:00 psql
postgres   2100   1098  0 22:18 ?        00:00:00 postgres: postgres postgres [local] idle
root       2180   2007  0 23:02 pts/1    00:00:00 grep --color=auto post

Check the local PG subprocess port, and confirm that the connection between PG -- > remotepgs is through the subprocess

[root@localhost ~]# lsof -i:55814
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postmaste 2098 postgres    5u  IPv4  29227      0t0  TCP localhost.localdomain:55814->192.168.55.55:postgres (ESTABLISHED)
[root@localhost ~]# lsof -i:55816
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postmaste 2100 postgres    5u  IPv4  29279      0t0  TCP localhost.localdomain:55816->192.168.55.55:postgres (ESTABLISHED)

View local PG subprocess dynamic library loading

[root@localhost ~]# pldd 2098
2098:   /usr/local/postgresql/bin/postgres
linux-vdso.so.1
/lib64/libpthread.so.0
/lib64/librt.so.1
/lib64/libdl.so.2
/lib64/libm.so.6
/lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
/lib64/libnss_files.so.2
/usr/local/postgresql/lib/postgres_fdw.so
/usr/local/postgresql/lib/libpq.so.5
[root@localhost ~]# pldd 2100
2100:   /usr/local/postgresql/bin/postgres
linux-vdso.so.1
/lib64/libpthread.so.0
/lib64/librt.so.1
/lib64/libdl.so.2
/lib64/libm.so.6
/lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
/lib64/libnss_files.so.2
/usr/local/postgresql/lib/postgres_fdw.so
/usr/local/postgresql/lib/libpq.so.5
[root@localhost ~]# 

Thus it can be seen

A session a subprocess, a subprocess independently load postgre fdw.so, and connect it to remote PG

The connection will not be broken unless the session is broken and the child process disappears.

So, if you want to implement fdw.so in fdw.so, it's a little difficult, because you can't implement services based on sessions.

Posted by jollyjumper on Sun, 22 Dec 2019 07:41:52 -0800