[英]In Postgres, after truncating or deleting rows, does executing reindex before pg_dump optimize pg_restore?
Do the REINDEX
statements below help with the restore operation or file size of the dump? 下面的
REINDEX
语句对转储的还原操作或文件大小有帮助吗?
Could not find a question about this anywhere on SO or web. 在SO或Web上的任何地方都找不到关于此的问题。 I'm using Postgres 9.4 and cleaning out a very large database with both
truncate
and delete
statements on various tables. 我正在使用Postgres 9.4,并使用
truncate
和delete
各个表上的语句来清理非常大的数据库。
The table data varies in type and size. 表数据的类型和大小不同。
After this clean up operation, I immediately execute a pg_dump, tar and upload, then pg_restore. 完成此清理操作后,我立即执行pg_dump,tar和上载,然后执行pg_restore。 It's using the directory format with 12 jobs in parallel for dump, 8 for restore.
它使用目录格式,其中12个作业并行进行转储,8个作业并行进行还原。
For example, these queries first: 例如,这些查询首先:
TRUNCATE users;
DELETE FROM users_email WHERE active = 1;
REINDEX TABLE users;
REINDEX TABLE users_email;
Then: 然后:
$ 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
This will make no difference at all for pg_dump
or pg_restore
. 这对于
pg_dump
或pg_restore
完全没有区别。
pg_dump
doesn't use the index at all, it just writes its definition as a CREATE INDEX
statement into the dump. pg_dump
根本不使用索引,它只是将其定义作为CREATE INDEX
语句写入转储中。 The table itself is scanned sequentially. 该表本身将被顺序扫描。
pg_restore
creates the index using the CREATE INDEX
from the dump. pg_restore
使用转储中的CREATE INDEX
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.