I have a table in PostgreSQL with two columns containing images as text (not my decision ..). So, now I do not need these columns and I'm planning to delete them. But I'd faced a problem when I wanted to estimate the "effect" of dropping the columns, i.e. how much size of the table will change. The problem is that PostgreSQL shows the same size for old and new tables. Which is very weird because I'm dropping two "heavy" columns.
Here is the code of comparison:
-- Create two copies of the table
CREATE TABLE oldwords (LIKE "words" INCLUDING INDEXES);
INSERT INTO oldwords SELECT * FROM "words";
CREATE TABLE newwords (LIKE "words" INCLUDING INDEXES);
INSERT INTO newwords SELECT * FROM "words";
-- Drop columns containing images
ALTER TABLE "newwords"
DROP COLUMN image_black,
DROP COLUMN image_colored;
-- Update stats of the tables
VACUUM ANALYZE "oldwords";
VACUUM ANALYZE "newwords";
-- Compare size
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) -
pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables
WHERE relname LIKE '___words'
ORDER BY pg_total_relation_size(relid) DESC
-- RESULT
Table Size External Size
newwords 296 MB 205 MB
oldwords 296 MB 205 MB
Am I doing something wrong? Why are the sizes same? And what is the correct way to do it?
Vacuum fullshould rewrite the tables and remove all dropped columns