在 Postgres 中,截断或删除行后,在 pg_dump 优化 pg_restore 之前执行重建索引吗?
In Postgres, after truncating or deleting rows, does executing reindex before pg_dump optimize pg_restore?
下面的 REINDEX
语句对还原操作或转储文件大小有帮助吗?
在 SO 或网络上的任何地方都找不到关于此的问题。我正在使用 Postgres 9.4 并在各种 table 上使用 truncate
和 delete
语句清理一个非常大的数据库。
table 数据的类型和大小各不相同。
在这个清理操作之后,我立即执行pg_dump、tar并上传,然后pg_restore。它使用的目录格式有 12 个并行作业用于转储,8 个用于恢复。
例如,首先查询这些:
TRUNCATE users;
DELETE FROM users_email WHERE active = 1;
REINDEX TABLE users;
REINDEX TABLE users_email;
然后:
$ pg_dump_9.4 --compress=0 -F directory -j 12 $DB_EXPORT_NAME -f $DB_DUMP_FOLDER 2>> operations.log
$ # do tar and upload with dump then:
$ pg_restore_9.4 -d $DB_IMPORT_NAME -j 8 $DB_DUMP_FOLDER 2>> operations.log
这对 pg_dump
或 pg_restore
没有任何影响。
pg_dump
根本不使用索引,它只是将其定义作为 CREATE INDEX
语句写入转储。 table 本身是按顺序扫描的。
pg_restore
使用来自转储的 CREATE INDEX
创建索引。
下面的 REINDEX
语句对还原操作或转储文件大小有帮助吗?
在 SO 或网络上的任何地方都找不到关于此的问题。我正在使用 Postgres 9.4 并在各种 table 上使用 truncate
和 delete
语句清理一个非常大的数据库。
table 数据的类型和大小各不相同。
在这个清理操作之后,我立即执行pg_dump、tar并上传,然后pg_restore。它使用的目录格式有 12 个并行作业用于转储,8 个用于恢复。
例如,首先查询这些:
TRUNCATE users;
DELETE FROM users_email WHERE active = 1;
REINDEX TABLE users;
REINDEX TABLE users_email;
然后:
$ pg_dump_9.4 --compress=0 -F directory -j 12 $DB_EXPORT_NAME -f $DB_DUMP_FOLDER 2>> operations.log
$ # do tar and upload with dump then:
$ pg_restore_9.4 -d $DB_IMPORT_NAME -j 8 $DB_DUMP_FOLDER 2>> operations.log
这对 pg_dump
或 pg_restore
没有任何影响。
pg_dump
根本不使用索引,它只是将其定义作为 CREATE INDEX
语句写入转储。 table 本身是按顺序扫描的。
pg_restore
使用来自转储的 CREATE INDEX
创建索引。