Goal: distinguish session overrides from persistent settings and verify where values come from.
Connect as postgres for the administrative changes. Keep this administrative connection open while comparing session and persistent values.
In the connection command, -U postgres selects the SQL role and -d postgres selects the database. Expect the psql welcome message and a postgres=# prompt; run the following SQL there.
Goal: read the rules governing how a setting can change.
Inspect four named settings rather than a broad name search. work_mem is user, log_min_duration_statement is superuser, checkpoint_timeout is sighup, and max_connections is postmaster. setting uses the accompanying unit.
user permits session changes; superuser requires an administrative role or appropriate setting privilege; sighup takes file changes on reload; postmaster requires restart for file changes. source reports the origin of the active value. Expect four rows with pending_restart = f (false).
Goal: record the baseline before creating overrides.
Use SHOW work_mem for the human-readable value. This guest starts at 4MB; a setting of 4096 with unit kB describes the same value.
SHOW reports this session’s active value in readable units. Keep 4MB as the cleanup target; it is not a request to change the setting.
Goal: create and remove a session-only override.
Set work_mem to 8MB in this session and inspect source = session. Then RESET and inspect 4MB / default again. This changes neither configuration file nor other sessions.
Expect 8192 kB with source session, then 4096 kB with source default. RESET removes this client’s override; it does not delete entries written with ALTER SYSTEM.
Goal: request a persistent change instead of a session override.
Use ALTER SYSTEM to write 16MB to postgresql.auto.conf, then request a reload. A true return means the signal was sent, not that the value has already changed. The next step reads the applied value.
postgresql.auto.conf is read alongside the main configuration; ALTER SYSTEM writes the entry for you. Expect ALTER SYSTEM and pg_reload_conf = t. That acknowledgement is not the success check for the active value; verify it next.
Goal: verify both the active value and its configuration-file entry.
Wait briefly for the reload, inspect 16384 / kB / configuration file, then inspect the parsed auto-file row 16MB / applied / no error. pg_settings is this session’s active state; pg_file_settings reads the files. Both matter.
pg_sleep(0.1) pauses briefly to let the reload be processed; its blank output is expected. error IS NULL AS no_error becomes t when parsing has no error. % in LIKE allows a path prefix. Expect applied = t and no_error = t, as well as the active 16MB value.
Goal: identify origins of non-default values rather than assuming all are file edits.
Show every row whose source is not default, then count rows by source. This includes startup overrides and environment-derived settings, not only deliberate performance tuning. Locate work_mem among configuration-file values.
<> means not equal. GROUP BY source counts parameters per origin; client describes connection-supplied values and override forced server values. In this guest expect 33 parameter rows summarized as 2 client, 23 configuration-file, and 8 override settings; find work_mem = 16384 kB in the file group.
Goal: enable duration logging for statements lasting at least half a second.
Persist 500ms, reload, wait briefly, and verify SHOW log_min_duration_statement. This sets a duration threshold; it does not classify queries as good or bad or cancel shorter queries.
The parameter’s unit is milliseconds, so the numeric 500 means 500ms. ALTER SYSTEM, reload, and the short wait persist and apply it. Expect SHOW to report 500ms; this changes logging, not a query timeout.
Goal: produce one identifiable slow statement and find its log evidence.
Run a labelled 0.6-second sleep, then read its duration entry from the actual collector log. The sleep is a controlled logging demonstration, not a workload tuning recommendation. Log timestamps and measured milliseconds will vary.
pg_sleep(0.6) deliberately waits about 600ms, above the threshold. /* config_slow_demo */ labels the SQL without changing its work. The shorter wait allows the collector to write. \! runs the shell search; as-postgres reads as the Linux owner, and grep matches duration plus label. Success is a duration line for this exact statement, not just blank sleep output.
Goal: remove persistent overrides and prove the baseline is active again.
Reset both overrides, reload, wait, and inspect work_mem 4096 / default and logging threshold -1 / default. Reset removes the auto-file entries; it falls back to another source, which happens to be the built-in defaults here.
ALTER SYSTEM RESET removes auto-file entries rather than assigning universal factory values. After reload and the brief wait, source = default confirms this lab’s fallback. -1 disables duration-threshold statement logging; 4096 kB is 4MB.