Last active
June 3, 2020 19:56
-
-
Save ridhwaans/03045db15c8e83227c8e02a719c1cc77 to your computer and use it in GitHub Desktop.
useful-queries
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
-- list tables by size | |
select schemaname as table_schema, | |
relname as table_name, | |
pg_size_pretty(pg_total_relation_size(relid)) as total_size, | |
pg_size_pretty(pg_relation_size(relid)) as data_size, | |
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) | |
as external_size | |
from pg_catalog.pg_statio_user_tables | |
order by pg_total_relation_size(relid) desc, | |
pg_relation_size(relid) desc | |
limit 10; | |
-- list columns in a table | |
SELECT * | |
FROM information_schema.columns | |
WHERE table_name = 'table_name'; | |
-- show running queries | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- server information | |
SELECT version(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment