Question

How to drop unused partition

Recently, I’ve used extensions pg_partman, pg_cron to archive old data. Yesterday I saw a new partition but I cannot access it. I’ve checked that partition’s table owner, and it belongs to _dodb. As I know _dodb is a superuser and I can only log in with doadmin. How can I drop that partition without logging in with _dodb?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey @nguyenthanhquang152,

You should be able to set the number of partitions you want to keep, then execute the run_maintenance() function to automatically drop (or archive) the old data.

It does require additional GRANTS on a per-database basis to be able to do so, as you’ve done here.

I don’t know what roles will exist and don’t want to grant permissions that may not be wanted by default.

CREATE ROLE partman WITH LOGIN;
GRANT ALL ON SCHEMA partman TO partman;
GRANT ALL ON ALL TABLES IN SCHEMA partman TO partman;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA partman TO partman;
GRANT EXECUTE ON ALL PROCEDURES IN SCHEMA partman TO partman;  -- PG11+ only
GRANT ALL ON SCHEMA my_partition_schema TO partman;

You will tell me how it goes.

Cheers, - Sergio Turpín