I ran a simple delete query on a telemetries table to clear up some data but cancelled as it was taking really long. I noticed that after I cancelled the query some of the tables (all partitions of the telemetries table) are now taking up more than double the space they previously were. For example, a table that was previously 16GB is now 28GB (pg_size_pretty value).
I do not want to proceed with the delete because I want to keep the data but why have the tables swelled up so much? Would a VACUUM FULL help? If I run VACUUM, do I run the risk of actually deleting the data permanently?
I ran the following using psql;
delete from telemtries where timestamp < 1668987465000;
I cancelled with ctrl+c. I ran \s to check my query history aftwerwards and my delete query was not there. I'm using postgress 12.16
DELETEdoes not inflate tables. (UPDATEcould, like Frank commented.)Aside from triggers that might do anything
ON DELETE, the only remaining thing that comes to mind would be aFOREIGN KEYconstraint withON DELETE SET NULLor... SET DEFAULTreferencing the target table of yourDELETE. That would actually write new row versions for referencing rows, which linger as dead tuples in case of aROLLBACK. Either way, it would bloat those tables, but not the target table of theDELETE(unless it's a self-referencing FK).(Might also explain why the
DELETEtook so long. But there is a whole range of other possible reasons for that. You have not been overly specific.)VACUUM FULLremoves all bloat. See: