Simply ordering your table's columnns for more efficient datatype storage can save up to 30% of disk utilization.
Last active
April 17, 2021 02:27
-
-
Save hopsoft/480fb99187cee3de51d521ee1bd264ff to your computer and use it in GitHub Desktop.
Query the recommended column order for PostgreSQL tables
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
SELECT | |
pg_attribute.attname, | |
pg_type.typname, | |
pg_type.typalign, | |
pg_type.typlen | |
FROM | |
pg_class | |
JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid | |
JOIN pg_type ON pg_type.oid = pg_attribute.atttypid | |
WHERE | |
pg_class.relname = 'YOUR_TABLE_NAME' | |
AND pg_attribute.attnum >= 0 | |
ORDER BY | |
pg_type.typlen DESC, pg_attribute.attname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment