1. 程式人生 > >PG fdw連線建立與關閉

PG fdw連線建立與關閉

PG本地啟動psql, 並訪問外部表,然後退出

PG 與 remotePG的連線,隨著客戶端psql的退出而斷開。

 

PG本地啟動多個psql, 每個psql都訪問一次外部表

檢視remotePG 程序

[email protected]:~$ 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
[email protected]
:~$ date Sun Sep 30 11:00:16 DST 2018

檢視本地PG程序

[[email protected]lhost ~]# 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之間 是通過子程序連線

[[email protected] ~]# 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)
[[email protected] ~]# 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子程序動態庫載入

[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# 

由此可見

一個會話一個子程序, 一個子程序獨立載入postgre_fdw.so, 並使之連線remote PG.

連線不會斷開,除非會話斷開,子程序消失。

所以,如果自己實現fdw.so . 想在fdw.so中實現服務,有點難,因為不能基於會話在實現服務。