Last active
August 29, 2017 14:55
-
-
Save marcocitus/cc3cdd528e4d2e8e35b5e75eeca986c6 to your computer and use it in GitHub Desktop.
Show distributed table sizes in \d+
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
-- Replace the pg_table_size function with one that supports distributed tables | |
BEGIN; | |
ALTER FUNCTION pg_catalog.pg_table_size(regclass) RENAME TO orig_table_size; | |
CREATE OR REPLACE FUNCTION pg_catalog.pg_table_size(table_name regclass) | |
RETURNS bigint | |
LANGUAGE plpgsql | |
AS $function$ | |
BEGIN | |
IF EXISTS (SELECT 1 FROM pg_dist_partition WHERE logicalrelid = table_name) THEN | |
RETURN pg_catalog.citus_table_size(table_name); | |
ELSE | |
RETURN pg_catalog.orig_table_size(table_name); | |
END IF; | |
END; | |
$function$; | |
COMMIT; |
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
-- Restore original pg_table_size | |
BEGIN; | |
DROP FUNCTION pg_catalog.pg_table_size(regclass); | |
ALTER FUNCTION pg_catalog.orig_table_size(regclass) RENAME TO pg_table_size; | |
COMMIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: