From: | Benoit Lobréau <benoit(dot)lobreau(at)dalibo(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Parallel workers stats in pg_stat_database |
Date: | 2024-08-28 15:10:26 |
Message-ID: | 783bc7f7-659a-42fa-99dd-ee0565644e25@dalibo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi hackers,
This patch introduces four new columns in pg_stat_database:
* parallel_worker_planned
* parallel_worker_launched
* parallel_maint_worker_planned
* parallel_maint_worker_launched
The intent is to help administrators evaluate the usage of parallel
workers in their databases and help sizing max_worker_processes,
max_parallel_workers or max_parallel_maintenance_workers).
Here is a test script:
psql << _EOF_
-- Index creation
DROP TABLE IF EXISTS test_pql;
CREATE TABLE test_pql(i int, j int);
INSERT INTO test_pql SELECT x,x FROM generate_series(1,1000000) as F(x);
-- 0 planned / 0 launched
EXPLAIN (ANALYZE)
SELECT 1;
-- 2 planned / 2 launched
EXPLAIN (ANALYZE)
SELECT i, avg(j) FROM test_pql GROUP BY i;
SET max_parallel_workers TO 1;
-- 4 planned / 1 launched
EXPLAIN (ANALYZE)
SELECT i, avg(j) FROM test_pql GROUP BY i
UNION
SELECT i, avg(j) FROM test_pql GROUP BY i;
RESET max_parallel_workers;
-- 1 planned / 1 launched
CREATE INDEX ON test_pql(i);
SET max_parallel_workers TO 0;
-- 1 planned / 0 launched
CREATE INDEX ON test_pql(j);
-- 1 planned / 0 launched
CREATE INDEX ON test_pql(i, j);
SET maintenance_work_mem TO '96MB';
RESET max_parallel_workers;
-- 2 planned / 2 launched
VACUUM (VERBOSE) test_pql;
SET max_parallel_workers TO 1;
-- 2 planned / 1 launched
VACUUM (VERBOSE) test_pql;
-- TOTAL: parallel workers: 6 planned / 3 launched
-- TOTAL: parallel maint workers: 7 planned / 4 launched
_EOF_
And the output in pg_stat_database a fresh server without any
configuration change except thoses in the script:
[local]:5445 postgres(at)postgres=# SELECT datname,
parallel_workers_planned, parallel_workers_launched,
parallel_maint_workers_planned, parallel_maint_workers_launched FROM pg
_stat_database WHERE datname = 'postgres' \gx
-[ RECORD 1 ]-------------------+---------
datname | postgres
parallel_workers_planned | 6
parallel_workers_launched | 3
parallel_maint_workers_planned | 7
parallel_maint_workers_launched | 4
Thanks to: Jehan-Guillaume de Rorthais, Guillaume Lelarge and Franck
Boudehen for the help and motivation boost.
---
Benoit Lobréau
Consultant
http://dalibo.com
Attachment | Content-Type | Size |
---|---|---|
0001-Adds-four-parallel-workers-stat-columns-to-pg_stat_d.patch | text/x-patch | 13.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Jacob Champion | 2024-08-28 15:11:17 | Re: PG_TEST_EXTRA and meson |
Previous Message | Andreas Karlsson | 2024-08-28 14:58:16 | Minor refactor: Use more consistent names for the labels of PG_Locale_Strategy |