Skip to content

Instantly share code, notes, and snippets.

View shamil614's full-sized avatar

scott hamilton shamil614

View GitHub Profile
@tahoemph
tahoemph / postres_system.sql
Created December 21, 2020 15:25
Collection of useful postgres queries both found and made
-- table + index sizes
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
SELECT
table_name,
pg_table_size(table_name) AS table_size,
@Weiyuan-Lane
Weiyuan-Lane / mean_query_check.sql
Created May 16, 2021 13:00
pg_stat_statement mean query
SELECT
pg_stat_statements.query as query,
round(pg_stat_statements.total_exec_time::numeric, 2) AS total_time,
pg_stat_statements.calls,
round(pg_stat_statements.mean_exec_time::numeric, 2) AS mean,
round((100 * pg_stat_statements.total_exec_time /
sum(pg_stat_statements.total_exec_time::numeric) OVER ())::numeric, 2) AS percentage_cpu,
round((100 * pg_stat_statements.calls /
sum(pg_stat_statements.calls::numeric) OVER ())::numeric, 2) AS percentage_calls,
pg_user.usename as username,
@portnov
portnov / query.sql
Created May 27, 2024 12:51
postgres_exporter stat_statements query
explain (analyze, buffers)
SELECT
pg_get_userbyid(userid) as user,
pg_database.datname,
pg_stat_statements.queryid,
pg_stat_statements.calls as calls_total,
pg_stat_statements.total_exec_time / 1000.0 as seconds_total,
pg_stat_statements.rows as rows_total,
pg_stat_statements.blk_read_time / 1000.0 as block_read_seconds_total,
pg_stat_statements.blk_write_time / 1000.0 as block_write_seconds_total