Goal: prove which change can take effect while PostgreSQL keeps running, and which needs a restart. Think of updating a kitchen’s recipe cards versus closing and reopening with a new layout. We will compare the written instructions with what the kitchen is actually using.
Connect as the SQL role postgres so you can change server settings. Before changing anything, record 20 connections / 4MB work_mem and save the server’s start time:
pg_postmaster_start_time() returns when the current server instance started, not when your client connected.
\copy (SELECT …) TO '…' runs the query and writes its result to a file through psql. Here it saves one timestamp to /tmp/reload-start.txt; COPY 1 means one row was written, not that a database table was copied.
- We use a file because it survives closing psql and reconnecting later. A psql variable would disappear with the client.
SHOW displays the current active values. Keep these starting values in mind for the final cleanup.
Goal: learn how to choose between a session change, reload, and restart before trying one.
Read the context column as the rule for when and how a setting can change:
user: work_mem supports session SET; a persistent file change can also take effect after reload if a session override does not mask it.
superuser: a session change to log_min_duration_statement requires a superuser or the appropriate SET privilege.
sighup: checkpoint_timeout accepts file changes when the server processes a reload signal.
postmaster: max_connections is established at server startup; changing its file value requires restarting.
Read setting with its unit: 4096 kB is 4MB, and a blank unit for max_connections means a count. pending_restart is a boolean: t means true, f means false. Expect all four rows to show f before our edits. These are representative contexts, not the complete list.
Goal: apply 24MB work_mem and prove the server did not restart.
Run the actions in order:
ALTER SYSTEM SET writes an override to postgresql.auto.conf. It persists a server setting; ordinary SET would affect only your session.
pg_reload_conf() sends a reload signal. Its t acknowledges sending that signal, not that every setting has already changed.
pg_sleep(0.1) pauses this SQL session for a tenth of a second, giving the server a moment to process the request. Its blank result cell is expected.
- Inspect the active value:
24576 kB is 24 × 1024 kB, or 24MB, with pending_restart = f.
- Compare the current start timestamp with the saved one.
pg_read_file() reads the file on the server; ::timestamptz converts its text into a timestamp with time zone. Here psql and the server run on the same machine, so they can access the same saved file. This file-reading query uses our administrative role.
= compares the timestamps; AS start_unchanged labels the result. Expect t: the setting changed, but the server instance stayed running.
Goal: see a requested value that a reload cannot activate. Write max_connections = 200, reload, wait briefly, then compare two views:
- Active state —
pg_settings: expect setting = 20 and pending_restart = t. PostgreSQL is still using the old limit.
- Written state —
pg_file_settings: expect setting = 200, applied = f, and setting could not be applied. The requested value exists in the file, but this startup-only setting cannot take effect during reload. That message is expected here; do not “fix” it by deleting the new value.
The filter sourcefile LIKE '%/postgresql.auto.conf' selects the file written by ALTER SYSTEM. % means any preceding path text, so the query does not need to hardcode its parent directory.
Both queries describe the same parameter at different stages. Writing 200 has not yet changed the running limit of 20. We will perform the restart in step 6.
Goal: find every recognized configuration change still waiting for a restart.
WHERE pending_restart is shorthand for WHERE pending_restart = true: it keeps only rows whose flag is true. Expect one row, max_connections, with 20 and a blank unit.
That number is still the active connection limit. This query reads pg_settings, so it does not display the requested 200 from the file. The row means “this parameter has a pending change,” not “the server already uses the new value.” work_mem should be absent because its change took effect on reload.
Goal: activate the pending 200-connection limit and prove a new server instance is answering queries.
First run \q to leave psql. Run the restart command at the shell prompt, then reconnect with psql for the SQL checks.
Read the restart command in pieces:
as-postgres runs the command as the Linux account that owns the cluster. It is separate from the SQL role chosen by psql -U postgres.
pg_ctl restart stops and starts PostgreSQL. -D selects this cluster’s data directory.
-m fast requests a clean shutdown that disconnects clients and rolls back active transactions; it is not an immediate crash stop.
-w waits for the stop/start operations to complete. -l appends server output to /tmp/reload-restart.log.
Expect server stopped, then server started. After reconnecting, expect max_connections = 200 / pending_restart = f.
The final query uses > to compare the current start time with the saved baseline. Expect restarted = t. The newer timestamp shows the server cycled; the successful SQL response shows it can answer queries.
Goal: undo both persistent overrides and verify the starting configuration is active again.
ALTER SYSTEM RESET removes the named entry from postgresql.auto.conf. It does not assign a universal factory value; the next applicable configuration source supplies the value. This differs from ordinary RESET, which removes a session override.
Remove both entries while still in psql, exit with \q, run the same waiting restart at the shell prompt, and reconnect. Another restart is required because reducing max_connections back to its original value is also a startup-only change. Restart reads the updated files, so a separate reload beforehand is unnecessary here.
Check both result rows:
max_connections = 20, source configuration file: the original main-file setting is visible again.
work_mem = 4096 kB (4MB), source default: no remaining file override supplies it.
pending_restart = f for both: neither row is waiting on a restart.
The lab is complete when the original values are active, not merely when the overrides have been removed.