pg_settings Tells Value, Source And Context

pg_settings exposes value, source, and context together, so you can tell session-tunable knobs from ones waiting on reload or restart.

SqlConfig Management

Code

snippet
-- pg_settings 不只给值:source 说明值从哪来,context 说明改动何时生效
SELECT
    name,
    setting,
    source,
    context
FROM pg_settings
WHERE name IN ('work_mem', 'shared_buffers', 'autovacuum', 'search_path')
ORDER BY name;

-- context 决定生效路径:user 会话内 SET 即生效、sighup 等 pg_reload_conf()、
-- postmaster 必须重启
SELECT
    name,
    context,
    pending_restart
FROM pg_settings
WHERE context IN ('sighup', 'postmaster')
ORDER BY name
LIMIT 5;

-- 改过但还没重启的 postmaster 参数:pending_restart 会亮出来
SELECT count(*) FILTER (WHERE pending_restart) AS waiting_restart
FROM pg_settings;

Inside the snippet

What runs here is SELECT — pg_settings are the objects involved.

Concretely, the SQL combines: a WHERE clause limiting a statement to the rows that qualify; COUNT aggregation; an ORDER BY that fixes the output order; a row cap (LIMIT) bounding the result size.

Putting it to use

Run the statement against the pg_settings table; the LIMIT keeps the probe cheap while you tune the predicates.

Core lines

SELECT
    name,
    setting,
    source,
    context
FROM pg_settings
WHERE name IN ('work_mem', 'shared_buffers', 'autovacuum', 'search_path')
ORDER BY name;
SELECT
    name,
    context,
    pending_restart
FROM pg_settings
WHERE context IN ('sighup', 'postmaster')
ORDER BY name
LIMIT 5;
SELECT count(*) FILTER (WHERE pending_restart) AS waiting_restart
FROM pg_settings;

Interactive Tools for This Topic

FAQ

What relations does the SQL touch?
`pg_settings` — referenced directly, no join needed.