ALTER SYSTEM Persists Server Settings
Persist server settings with ALTER SYSTEM, reload postgresql.auto.conf, inspect pg_settings, and reset a value.
Code
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
PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.Bitwise Operations CalculatorCompute AND, OR, XOR, NOT, and shifts on 32-bit unsigned operands with binary, hex, and signed decimal views.Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.
FAQ
- Which tables does the SQL touch?
- `pg_settings`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.