Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the Postgresql 13 pg_stat_statements extension #48

Merged

Conversation

unhandled-exception
Copy link
Contributor

In Postgres 13, the column names in pg_stat_statements have changed. I propose a change that adds version checking for s1 and s2 actions.

@oleg9301
Copy link

I think we need there not only column *_exec_time, but and *_plan_time

Example

select sum(calls) as calls, sum(total_exec_time + total_plan_time) as total_time, sum((mean_exec_time + mean_plan_time) * calls) / sum(calls) as mean_time, max(max_exec_time + max_plan_time) as max_time, min(min_exec_time + min_plan_time) as min_time, -- stddev_time, -- https://stats.stackexchange.com/questions/55999/is-it-possible-to-find-the-combined-standard-deviation sum(rows) as rows, (select usename from pg_user where usesysid = userid) as usr, (select datname from pg_database where oid = dbid) as db, query, sum(shared_blks_hit) as shared_blks_hit, sum(shared_blks_read) as shared_blks_read, sum(shared_blks_dirtied) as shared_blks_dirtied, sum(shared_blks_written) as shared_blks_written, sum(local_blks_hit) as local_blks_hit, sum(local_blks_read) as local_blks_read, sum(local_blks_dirtied) as local_blks_dirtied, sum(local_blks_written) as local_blks_written, sum(temp_blks_read) as temp_blks_read, sum(temp_blks_written) as temp_blks_written, sum(blk_read_time) as blk_read_time, sum(blk_write_time) as blk_write_time, array_agg(queryid) as queryids -- 9.4+ from pg_stat_statements group by userid, dbid, query order by sum(total_exec_time + total_plan_time) desc limit 50;

but query sometimes not work, because in new postgres calls can be zero.

@oleg9301
Copy link

select sum(calls) as calls, sum(total_exec_time + total_plan_time) as total_time, sum((mean_exec_time + mean_plan_time) * calls) / greatest(sum(calls),1) as mean_time, max(max_exec_time + max_plan_time) as max_time, min(min_exec_time + min_plan_time) as min_time, -- stddev_time, -- https://stats.stackexchange.com/questions/55999/is-it-possible-to-find-the-combined-standard-deviation sum(rows) as rows, (select usename from pg_user where usesysid = userid) as usr, (select datname from pg_database where oid = dbid) as db, query, sum(shared_blks_hit) as shared_blks_hit, sum(shared_blks_read) as shared_blks_read, sum(shared_blks_dirtied) as shared_blks_dirtied, sum(shared_blks_written) as shared_blks_written, sum(local_blks_hit) as local_blks_hit, sum(local_blks_read) as local_blks_read, sum(local_blks_dirtied) as local_blks_dirtied, sum(local_blks_written) as local_blks_written, sum(temp_blks_read) as temp_blks_read, sum(temp_blks_written) as temp_blks_written, sum(blk_read_time) as blk_read_time, sum(blk_write_time) as blk_write_time, array_agg(queryid) as queryids -- 9.4+ from pg_stat_statements group by userid, dbid, query order by sum(total_exec_time + total_plan_time) desc limit 50;

NikolayS
NikolayS previously approved these changes Oct 17, 2021
@NikolayS NikolayS merged commit 6c65b6a into NikolayS:master Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants