Reserve connections for the pg_use_reserved_connections group in PostgreSQL 16

In PostgreSQL 16, you can reserve connections for the pg_use_reserved_connections group by modifying the postgresql.conf file. The pg_use_reserved_connections group is a special group of connections that are reserved for superusers and other critical system processes, such as autovacuum and replication.

By reserving a fixed number of connections for this group, you can ensure that critical system processes have access to the necessary resources and do not get blocked by other database activity. Here are the steps to reserve connections for the pg_use_reserved_connections group:

  1. Open the postgresql.conf file: Use a text editor to open the postgresql.conf file, which is located in the PostgreSQL data directory.

sudo nano /etc/postgresql/16/main/postgresql.conf

2. Modify the max_connections parameter: Modify the max_connections parameter to include the number of connections reserved for the pg_use_reserved_connections group. For example, if you want to reserve 10 connections for this group, set the max_connections parameter to a value that is 10 higher than the maximum number of connections you want to allow for regular users.

max_connections = 110

3. Modify the reserved_connections parameter: Add the reserved_connections parameter and set it to the number of connections you want to reserve for the pg_use_reserved_connections group. For example, to reserve 10 connections, set the reserved_connections parameter to 10.

reserved_connections = 10

  1. Save and close the postgresql.conf file: Save the changes to the postgresql.conf file and close the text editor.
  2. Restart the PostgreSQL service: Restart the PostgreSQL service to apply the changes.

sudo systemctl restart postgresql-16

After reserving connections for the pg_use_reserved_connections group, you can monitor the database activity using tools such as pg_stat_activity and pg_locks to ensure that critical system processes are not being blocked by other database activity.

It is important to note that reserving too many connections for the pg_use_reserved_connections group can lead to a waste of resources and lower the concurrency of the regular users. It is recommended to reserve only the necessary number of connections for the critical system processes and monitor the database activity to ensure optimal performance.

About Shiv Iyer 446 Articles
Open Source Database Systems Engineer with a deep understanding of Optimizer Internals, Performance Engineering, Scalability and Data SRE. Shiv currently is the Founder, Investor, Board Member and CEO of multiple Database Systems Infrastructure Operations companies in the Transaction Processing Computing and ColumnStores ecosystem. He is also a frequent speaker in open source software conferences globally.