Skip to content

Commit

Permalink
Create queries.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
rayidghani committed May 6, 2016
1 parent d51e9da commit f7f9ac6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# get largest dbs in posrgres server
SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS SIZE
FROM pg_catalog.pg_database d
ORDER BY
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_database_size(d.datname)
ELSE NULL
END DESC -- nulls first
LIMIT 10



# get largest tables in postgres db
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 30;


0 comments on commit f7f9ac6

Please sign in to comment.