我在PostgreSQL中有一个表,其中两列包含图像作为文本(不是我的决定..)。因此,现在我不需要这些列,并且打算删除它们。但是,当我想估计删除列的“效果”(即表的大小将改变多少)时,我遇到了一个问题。问题在于PostgreSQL显示的旧表和新表大小相同。这很奇怪,因为我要删除两个“重”列。
这是比较代码:
-- 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 …Run Code Online (Sandbox Code Playgroud) postgresql ×1