PG本地启动psql, 并访问外部表,然后退出
PG 与 remotePG的连接,随着客户端psql的退出而断开。
PG本地启动多个psql, 每个psql都访问一次外部表
查看remotePG 进程
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
查看本地PG进程
[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
查看本地PG子进程端口,确认PG--> remotePG之间 是通过子进程连接
[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)
查看本地PG子进程动态库加载
[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 ~]#
由此可见
一个会话一个子进程, 一个子进程独立加载postgre_fdw.so, 并使之连接remote PG.
连接不会断开,除非会话断开,子进程消失。
所以,如果自己实现fdw.so . 想在fdw.so中实现服务,有点难,因为不能基于会话在实现服务。