Created
January 15, 2014 11:52
-
-
Save ArtemGr/8434901 to your computer and use it in GitHub Desktop.
The largestTables PostgreSQL function.
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
CREATE OR REPLACE FUNCTION public."largestTables" ( | |
) | |
RETURNS TABLE ( | |
relation text, | |
size text | |
) AS | |
$body$ | |
BEGIN | |
-- http://wiki.postgresql.org/wiki/Disk_Usage | |
RETURN QUERY SELECT nspname || '.' || relname AS "relation", | |
pg_size_pretty(pg_relation_size(C.oid)) AS "size" | |
FROM pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |
ORDER BY pg_relation_size(C.oid) DESC | |
LIMIT 20; | |
END; | |
$body$ | |
LANGUAGE 'plpgsql' | |
STABLE | |
CALLED ON NULL INPUT | |
SECURITY INVOKER | |
COST 10 ROWS 20; | |
COMMENT ON FUNCTION public."largestTables"() | |
IS 'Run a query returning the size of the largest tables and indexes. | |
See http://wiki.postgresql.org/wiki/Disk_Usage.'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment