Planet PostgreSQL

Planet PostgreSQL -

Pavlo Golub: Reserve connections in PostgreSQL 16

Reserve connections for the pg_use_reserved_connections group in PostgreSQL 16 Nathan Bossart implemented a brand-new patch that provides a way to reserve connection slots for non-superusers. The patch was reviewed by Tushar Ahuja and Robert Haas. Committed by Robert Haas. The commit message is: This provides a way to reserve connection slots for non-superusers. The slots reserved via the new GUC are available only to users who have the new predefined role pg_use_reserved_connections. superuser_reserved_connections remains as a final reserve in case reserved_connections has been exhausted. Patch by Nathan Bossart. Reviewed by Tushar Ahuja and by me. Discussion: http://postgr.es/m/20230119194601.GA4105788@nathanxps13 Let’s try reserve connections in our work! Let’s edit the postgresql.conf file and set these values: ... max_connections = 2 # (change requires restart) reserved_connections = 1 # (change requires restart) superuser_reserved_connections = 0 # (change requires restart) ... I set superuser_reserved_connections to zero so that it does not interfere with our testing. Now, let’s create a simple mortal: postgres=# create user pasha password '12345'; CREATE ROLE postgres=# \q Now we connect as a user “pasha”: $ psql -U pasha -d postgres psql (16devel) Type "help" for help One slot down! One to go! From another terminal we will repeat the above command: $ psql -U pasha -d postgres psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: remaining connection slots are reserved for roles with privileges of pg_use_reserved_connections WTF! In previous versions you are able to use all of the max_connections slots. But not anymore! Now the time for the new role pg_use_reserved_connections: postgres=# grant pg_use_reserved_connections to pasha; GRANT ROLE And now you can establish the second session: $psql -U pasha -d postgres psql (16devel) Type "help" for help. postgres=[...]

Nathan Bossart实现了一个全新的补丁,为非超级用户提供了一种保留连接槽的方法,由Robert Haas提交并审核通过。新的GUC只能被拥有pg_use_reserved_connections预定义角色的用户使用,superuser_reserved_connections作为最终保留以防reserved_connections耗尽。新特性可以让一些连接比其他连接更加重要,可以用来备份和监控,而不需要使用超级用户连接。另外,连接池也是一个相关的话题,可以使用pgbouncer来实现连接池。

postgresql

相关推荐 去reddit讨论

热榜 Top10

LigaAI
LigaAI
eolink
eolink
Dify.AI
Dify.AI
观测云
观测云

推荐或自荐