Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to truncate the pg_largeobject table in postgres?

Tags:

postgresql

I would like to discard the contents of the pg_largeobject table and reclaim its disk space. When I try issuing this command:

truncate pg_largeobject

I get this response:

ERROR:  permission denied: "pg_largeobject" is a system catalog

This is even though I am issuing the command as user postgres (a superuser). There is insufficient disk space to do a VACUUM FULL while the table contains a lot of rows. I've also tried just deleting all the rows in preparation for a VACUUM FULL, but this was still going after a whole day, and ended up being interrupted. I'd prefer to truncate if at all possible.

Is truncation of this table possible? It currently contains around 1 TB of images I no longer want. I've removed references to the table from all my other tables (and deleted all rows from pg_largeobject_metadata).

like image 245
Andrew Kelly Avatar asked Oct 20 '25 01:10

Andrew Kelly


1 Answers

Turning on allow_system_table_mods was the answer. The truncate then took only a few minutes. Thanks to Nick Barnes for this suggestion and to an old article that confirmed this approach.

like image 147
Andrew Kelly Avatar answered Oct 22 '25 07:10

Andrew Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!