ALTER SYSTEM Persists Server Settings

Persist server settings with ALTER SYSTEM, reload postgresql.auto.conf, inspect pg_settings, and reset a value.

SqlConfig Management

Code

snippet
ALTER SYSTEM SET work_mem = '32MB';
ALTER SYSTEM SET statement_timeout = '5s';
ALTER SYSTEM SET log_min_duration_statement = '250ms';

SELECT name, setting, unit, source, sourcefile
FROM pg_settings
WHERE name IN ('work_mem', 'statement_timeout', 'log_min_duration_statement')
ORDER BY name;

-- ALTER SYSTEM writes postgresql.auto.conf and marks settings for reload.
SELECT pg_reload_conf() AS reloaded;

-- New sessions pick up the reloaded values; the current session keeps its own.
SHOW work_mem;
SHOW statement_timeout;

ALTER SYSTEM RESET work_mem;
SELECT pg_reload_conf() AS reloaded_after_reset;

-- RESET affects future sessions; use SET for the current session.
SET work_mem = '16MB';
SHOW work_mem;

How it works

Several statements share this file — SELECT / ALTER, with pg_settings among the objects involved.

Mechanically, the statements are built from: a WHERE clause narrowing which rows one statement affects; an ORDER BY that fixes the output order.

Using it

The pg_settings table is the working surface here.

Key statements

SELECT name, setting, unit, source, sourcefile
FROM pg_settings
WHERE name IN ('work_mem', 'statement_timeout', 'log_min_duration_statement')
ORDER BY name;
SELECT pg_reload_conf() AS reloaded_after_reset;
SELECT pg_reload_conf() AS reloaded;

Interactive Tools for This Topic

FAQ

Which tables does the SQL touch?
`pg_settings`.