-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Diego
committed
Jun 9, 2023
1 parent
ca7e80c
commit 04f7952
Showing
15 changed files
with
59 additions
and
31 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
-- Shows the cache effectivity on each table (1 row per table) | ||
-- "_hits" and "_reads" includes "regular" blocks, indexes blocks, toast and tidx blocks | ||
|
||
select | ||
schemaname, relname, | ||
heap_blks_read as heap_read, | ||
heap_blks_hit as heap_hit, | ||
heap_blks_hit / (heap_blks_hit + heap_blks_read::float) as ratio | ||
from | ||
pg_statio_user_tables | ||
where (heap_blks_hit + heap_blks_read) > 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
SELECT s.schemaname, | ||
s.relname AS tablename, | ||
s.indexrelname AS indexname, | ||
pg_relation_size(s.indexrelid) AS index_size | ||
FROM pg_catalog.pg_stat_user_indexes s | ||
JOIN pg_catalog.pg_index i ON s.indexrelid = i.indexrelid | ||
WHERE s.idx_scan = 0 -- has never been scanned | ||
AND 0 <>ALL (i.indkey) -- no index column is an expression | ||
AND NOT i.indisunique -- is not a UNIQUE index | ||
AND NOT EXISTS -- does not enforce a constraint | ||
(SELECT 1 FROM pg_catalog.pg_constraint c | ||
WHERE c.conindid = s.indexrelid) | ||
ORDER BY pg_relation_size(s.indexrelid) DESC; | ||
select s.schemaname, | ||
s.relname as tablename, | ||
s.indexrelname as indexname, | ||
pg_relation_size(s.indexrelid) as index_size, | ||
pg_size_pretty(pg_relation_size(s.indexrelid)) as index_size_human | ||
from pg_catalog.pg_stat_user_indexes s | ||
join pg_catalog.pg_index i on s.indexrelid = i.indexrelid | ||
where --s.idx_scan = 0 -- has never been scanned | ||
s.idx_scan < 50 -- almost never used | ||
and pg_relation_size(relid) > 5 * 8192 -- skip empty objects | ||
and 0 <>all (i.indkey) -- no index column is an expression | ||
and not i.indisunique -- is not a unique index | ||
and not exists -- does not enforce a constraint | ||
(select 1 from pg_catalog.pg_constraint c | ||
where c.conindid = s.indexrelid) | ||
order by pg_relation_size(s.indexrelid) desc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- This query returns a list of active session holding multixact slots and their ages | ||
-- The age here is not tied to a time constraint, but rather to the transaction | ||
-- amount distance from the relminmxid and now. | ||
SELECT pid, datname, usename, state, txid_current(), backend_xmin, | ||
txid_current()::text::int - backend_xmin::text::int difference | ||
, statement_timestamp() - query_start elapsed , pg_blocking_pids(pid) as blocked_by, query::varchar(150) query FROM pg_stat_activity WHERE backend_xmin IS NOT NULL ORDER BY age(backend_xmin) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
-- Unstable queries, with larges deltas. | ||
|
||
SELECT queryid, calls,mean_time, max_time, query, | ||
SELECT queryid, calls,mean_exec_time, max_exec_time, query, | ||
rows, shared_blks_read, | ||
|
||
blk_read_time+blk_write_time,temp_blks_written+temp_blks_read,stddev_time | ||
blk_read_time+blk_write_time,temp_blks_written+temp_blks_read,stddev_exec_time | ||
from pg_Stat_statements | ||
|
||
ORDER BY | ||
mean_time DESC, | ||
stddev_time DESC | ||
mean_exec_time DESC, | ||
stddev_exec_time DESC | ||
|
||
LIMIT 10; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters