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.
Code
-- 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
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.Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.Multi-Mode Escape & Unescape CodecEscape and unescape strings safely across JSON, JavaScript, SQL single-quoted literals, POSIX shell single quotes, and RFC 4180 CSV cells in your browser.
FAQ
- What relations does the SQL touch?
- `pg_settings` — referenced directly, no join needed.
Report a problem with this exampleOpens a pre-filled issue on GitHub.