PostgreSQL Error 55P02: Can't Change Runtime Param
PostgreSQL error 55P02 (cant_change_runtime_param) occurs when you attempt to modify a configuration parameter that cannot be changed at runtime or within the current execution context. Some parameters are fixed at server startup and require a full restart to take effect, while others are restricted based on transaction state or server role. Understanding the context classification of each parameter is the key to avoiding this error.
Top 3 Causes
1. Changing a postmaster-context Parameter at Runtime
Parameters like max_connections or shared_buffers are loaded only at server startup. Attempting to change them with SET during a live session triggers 55P02 immediately.
-- Check the context of a parameter before changing it
SELECT name, setting, context
FROM pg_settings
WHERE name IN ('max_connections', 'shared_buffers', 'wal_level');
-- WRONG: This will throw 55P02 for postmaster-context params
SET max_connections = 300; -- ERROR: 55P02
-- CORRECT: Use ALTER SYSTEM, then restart the server
ALTER SYSTEM SET max_connections = 300;
-- Then restart PostgreSQL via OS command:
-- sudo systemctl restart postgresql
-- For sighup-context params, a reload is sufficient
ALTER SYSTEM SET log_min_duration_statement = '500';
SELECT pg_reload_conf();
2. Modifying Parameters Inside an Active Transaction Block
Certain parameters, such as transaction isolation level, must be set before or at the very start of a transaction — not after it has already begun.
-- WRONG: Setting isolation level after BEGIN causes 55P02
BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; -- ERROR if transaction already started
-- CORRECT: Declare isolation level as part of BEGIN
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT * FROM orders WHERE status = 'pending';
COMMIT;
-- Use SET LOCAL for session params scoped to a transaction
BEGIN;
SET LOCAL work_mem = '512MB'; -- valid inside transaction block
SELECT * FROM large_report_table ORDER BY revenue DESC;
COMMIT;
-- work_mem reverts to original value after COMMIT
3. Attempting Parameter Changes on a Hot Standby Server
On a read-only standby (replica) server, write operations and certain configuration changes are blocked. Applications that don't differentiate between primary and standby connections often hit this error.
-- Check whether the current server is a standby
SELECT pg_is_in_recovery();
-- Returns true → Standby (read-only)
-- Returns false → Primary
-- Conditionally apply parameter changes only on Primary
DO $$
BEGIN
IF NOT pg_is_in_recovery() THEN
PERFORM set_config('work_mem', '256MB', false);
END IF;
END;
$$;
-- View which parameters are safely changeable by users
SELECT name, setting, context
FROM pg_settings
WHERE context IN ('user', 'superuser')
ORDER BY name;
Quick Fix Solutions
| Situation | Fix |
|---|---|
postmaster param |
ALTER SYSTEM SET → restart server |
sighup param |
ALTER SYSTEM SET → SELECT pg_reload_conf()
|
| Inside transaction | Use BEGIN TRANSACTION ISOLATION LEVEL ... or SET LOCAL
|
| On standby server | Check pg_is_in_recovery() before changing params |
Prevention Tips
Always verify the parameter context before making changes.
Query pg_settings to understand whether a parameter requires a restart, reload, or can be set dynamically. Build this check into your deployment and change-management scripts to catch issues before they hit production.
-- Pre-flight check for any parameter change
SELECT name, context, setting,
CASE context
WHEN 'postmaster' THEN 'Requires server restart'
WHEN 'sighup' THEN 'Reload with pg_reload_conf()'
WHEN 'superuser' THEN 'SET allowed (superuser only)'
WHEN 'user' THEN 'SET allowed (any user)'
END AS action_required
FROM pg_settings
WHERE name = 'your_target_parameter';
Set session-level parameters at connection initialization, not mid-query.
Use your connection pooler's connect_query setting (e.g., pgBouncer) or your application's connection initialization hook to apply session parameters once, cleanly, before any transactions begin. This avoids context-related errors and keeps your configuration logic centralized and predictable.
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)