Skip to content

Instantly share code, notes, and snippets.

View MitchStephan's full-sized avatar

Mitch Stephan MitchStephan

View GitHub Profile
@krisiye
krisiye / postgresql_cheat_sheet.sql
Last active November 21, 2023 01:10
Useful queries for postgresql for monitoring queries and disk usage
-- Temporary file usage by database
SELECT datname AS "database", temp_files AS "Temporary files", temp_bytes
AS "Size of temporary files"
FROM pg_stat_database;
-- Cache Hit Ratio. Anything greater than 90% is always good
SELECT sum(blks_hit)*100/sum(blks_hit+blks_read) AS hit_ratio FROM pg_stat_database;
-- Top Queries
SELECT substr(query, 0, 250), calls,