作者
digoal
日期
2021-01-19
标签
PostgreSQL , 外部表 , postgres_fdw , 连接
背景
postgres_fdw是PG内置的PG与PG数据库之间的外部表插件, PG 14新增了一个函数postgres_fdw_get_connections(), 用于获取当前与外部server之间建立的外部表连接有哪些, 状态如何.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=708d165ddb92c54077a372acf6417e258dcb5fef
```
postgres_fdw: Add function to list cached connections to foreign servers.
author Fujii Masao fujii@postgresql.org
Mon, 18 Jan 2021 06:11:08 +0000 (15:11 +0900)
committer Fujii Masao fujii@postgresql.org
Mon, 18 Jan 2021 06:11:08 +0000 (15:11 +0900)
commit 708d165ddb92c54077a372acf6417e258dcb5fef
tree 89f4eda1b147b2072aaa2a9d1d1f2f7061b681b6 tree | snapshot
parent a3dc926009be833ea505eebd77ce4b72fe708b18 commit | diff
postgres_fdw: Add function to list cached connections to foreign servers.
This commit adds function postgres_fdw_get_connections() to return
the foreign server names of all the open connections that postgres_fdw
established from the local session to the foreign servers. This function
also returns whether each connection is valid or not.
This function is useful when checking all the open foreign server connections.
If we found some connection to drop, from the result of function, probably
we can explicitly close them by the function that upcoming commit will add.
This commit bumps the version of postgres_fdw to 1.1 since it adds
new function.
Author: Bharath Rupireddy, tweaked by Fujii Masao
Reviewed-by: Zhijie Hou, Alexey Kondratov, Zhihong Yu, Fujii Masao
Discussion: https://postgr.es/m/2d5cb0b3-a6e8-9bbb-953f-879f47128faa@oss.nttdata.com
```
+<sect2>
+ <title>Functions</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><function>postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</function></term>
+ <listitem>
+ <para>
+ This function returns the foreign server names of all the open
+ connections that <filename>postgres_fdw</filename> established from
+ the local session to the foreign servers. It also returns whether
+ each connection is valid or not. <literal>false</literal> is returned
+ if the foreign server connection is used in the current local
+ transaction but its foreign server or user mapping is changed or
+ dropped, and then such invalid connection will be closed at
+ the end of that transaction. <literal>true</literal> is returned
+ otherwise. If there are no open connections, no record is returned.
+ Example usage of the function:
+ <screen>
+postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
+ server_name | valid
+-------------+-------
+ loopback1 | t
+ loopback2 | f
+</screen>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+</sect2>
PostgreSQL 许愿链接
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.
9.9元购买3个月阿里云RDS PostgreSQL实例
PostgreSQL 解决方案集合
德哥 / digoal's github - 公益是一辈子的事.





