Skip to content

Instantly share code, notes, and snippets.

@olooney
Created October 26, 2017 13:05
Show Gist options
  • Save olooney/d0ee0e46e929d65b9056cc6210cc97f9 to your computer and use it in GitHub Desktop.
Save olooney/d0ee0e46e929d65b9056cc6210cc97f9 to your computer and use it in GitHub Desktop.
find large tables and convert them to compressed tables in Greenplum
Select
sum(size) AS total_size_on_disk,
sum(size) / (select count(*) from individual) AS per_individual
FROM (
SELECT
pg_relation_size(C.oid) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE 1=1 -- relname in (...)
ORDER BY pg_relation_size(C.oid) DESC
) table_sizes;
create table xxx_zlib with (appendonly=true, compresstype=zlib, compresslevel=6) as (select * from xxx) distributed by (pkcol1, ...);
drop table xxx;
alter table xxx_zlib rename to xxx;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment