Parameters do not take effect when using a server-side connection pool

Updated at:
Copy as MD

After you set database parameters by using the console or the ALTER DATABASE statement, the parameters do not take effect when you connect to the database through a server-side connection pool (PgBouncer). This topic describes the cause and solution.

Symptom

After you modify instance parameters in the console or execute the ALTER DATABASE statement to set database-level parameters, the SHOW command still returns the old values.

Cause

AnalyticDB for PostgreSQL supports the server-side connection pool (PgBouncer) feature. Instance connection addresses are divided into two types:

  • Direct connection address: The client connects directly to the database backend process.

  • Connection pool address: The client connects to PgBouncer, which maintains persistent connections to the database backend.

Database-level parameters set through ALTER DATABASE or the console are loaded when a connection is established. When you use a connection pool address, the connections between PgBouncer and the database backend are persistent and are not automatically rebuilt when parameters change. As a result, sessions established through the connection pool continue to use the old parameter values even after the parameters are modified.

Verification

Execute the following SQL statement to check whether the current connection comes from PgBouncer:

SELECT client_addr, client_port, backend_start 
FROM pg_stat_activity 
WHERE pid = pg_backend_pid();

If client_addr displays 127.0.0.1 (the loopback address), the current connection comes from the server-side connection pool.

You can also check the connection establishment time (backend_start). If the time is much earlier than the parameter modification time, the connection has not loaded the new parameters.

Solution

Terminate the backend connections maintained by PgBouncer so that new connections are established and the updated parameters are loaded.

Method 1: Terminate all connection pool backend connections

SELECT pg_terminate_backend(pid) 
FROM pg_stat_activity 
WHERE client_addr = '127.0.0.1';

Method 2: Terminate only the connection pool backend connections for a specific database

SELECT pg_terminate_backend(pid) 
FROM pg_stat_activity 
WHERE client_addr = '127.0.0.1' 
  AND datname = 'Target database name';

After the execution, PgBouncer automatically re-establishes connections to the database backend. The new connections load the latest parameter configuration.

Precautions

  • Permission requirements: Executing pg_terminate_backend requires superuser permissions or the permissions of the user who owns the target session.

  • Business impact: Terminating connections interrupts ongoing queries and transactions. We recommend that you perform this operation during off-peak hours or make sure that your application supports automatic reconnection.

  • Verification: After the operation, re-establish the connection and execute SHOW parameter_name to confirm that the parameters have taken effect.

  • Alternative: If you do not want to interrupt existing connections, you can wait for idle connections in the pool to time out and be rebuilt automatically. The timeout duration depends on the server_idle_timeout setting of PgBouncer, which is relatively long by default.