-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d51e9da
commit f7f9ac6
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
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,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; | ||
|
||
|