暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 14 preview - postgres_fdw 支持 hold foreign server 长连接, fdw sharding再进一步

digoal 2021-01-04
543

作者

digoal

日期

2021-04-03

标签

PostgreSQL , sharding , fdw , postgres_fdw , keep_connections


背景

postgres_fdw server option : keep_connections , 保持foreign server连接.
- keep_connections off表示foreign 事务结束后 立即释放foreign连接.
- keep_connections on表示保持foreign连接. 直到退出当前会话. 好处是高并发的foreign oltp业务, 减少大量建连接到开销. 坏处是总连接数可能增多, 访问过foreign server的连接都会被保持, 可以通过管理函数主动释放.

《怎么看待PostgreSQL sharding插件: citus - 对比PG 社区基于 postgres_fdw 的sharding》

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b1be3074ac719ce8073fba35d4c8b52fb4ddd0c3

```
postgres_fdw: Add option to control whether to keep connections open.
author Fujii Masao fujii@postgresql.org
Fri, 2 Apr 2021 10:45:42 +0000 (19:45 +0900)
committer Fujii Masao fujii@postgresql.org
Fri, 2 Apr 2021 10:45:42 +0000 (19:45 +0900)
commit b1be3074ac719ce8073fba35d4c8b52fb4ddd0c3
tree 4a7b836541eb0d7df10a6b83e951c7f9f673cc3e tree
parent 9c5f67fd6256246b2a788a8feb1d42b79dcd0448 commit | diff
postgres_fdw: Add option to control whether to keep connections open.

This commit adds a new option keep_connections that controls
whether postgres_fdw keeps the connections to the foreign server open
so that the subsequent queries can re-use them. This option can only be
specified for a foreign server. The default is on. If set to off,
all connections to the foreign server will be discarded
at the end of transaction. Closed connections will be re-established
when they are necessary by future queries using a foreign table.

This option is useful, for example, when users want to prevent
the connections from eating up the foreign servers connections
capacity.

Author: Bharath Rupireddy
Reviewed-by: Alexey Kondratov, Vignesh C, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com
```

+-- Test foreign server level option keep_connections +-- =================================================================== +-- By default, the connections associated with foreign server are cached i.e. +-- keep_connections option is on. Set it to off. +ALTER SERVER loopback OPTIONS (keep_connections 'off'); +-- connection to loopback server is closed at the end of xact +-- as keep_connections was set to off. +SELECT 1 FROM ft1 LIMIT 1; + ?column? +---------- + 1 +(1 row) + +-- No cached connections, so no records should be output. +SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1; + server_name +------------- +(0 rows) + +ALTER SERVER loopback OPTIONS (SET keep_connections 'on'); +-- ===================================================================

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论