我可以在 PostgreSQL 9.3 中用 TRUNCATE + COPY/FREEZE 替换 TRUNCATE + COPY + ANALYZE
Can I replace TRUNCATE + COPY + ANALYZE with TRUNCATE + COPY/FREEZE in PostgreSQL 9.3
我正在尝试优化批量加载程序。
目前我分步加载数据(我没有遵循下面的 SQL 语法,只是算法):
BEGIN
TRUNCATE table
COPY into table
ANALYZE table
COMMIT
在 PostgreSQL 9.3
之前,这是唯一推荐的重新加载 table 的方法。版本 9.3
引入了可以与 COPY
命令一起使用的 FREEZE
选项。标准文档说:
FREEZE
Requests copying the data with rows already frozen, just as
they would be after running the VACUUM FREEZE command. This is
intended as a performance option for initial data loading. Rows will
be frozen only if the table being loaded has been created or truncated
in the current subtransaction, there are no cursors open and there are
no older snapshots held by this transaction.
我的直接问题是 COPY/FREEZE
之后是否还需要 运行 ANALYZE
。标准文档没有给出任何直接建议。以下顺序是否足够,还是我还需要 运行 ANALYZE
?
BEGIN
TRUNCATE table
COPY/FREEZE table
COMMIT
谢谢!
是的,您仍然应该 ANALYZE
在 COPY
中的数据之后强制立即 table 生成统计数据。
是否冻结元组与统计无关,这是一种避免以后反环绕真空的方法activity。
我正在尝试优化批量加载程序。
目前我分步加载数据(我没有遵循下面的 SQL 语法,只是算法):
BEGIN
TRUNCATE table
COPY into table
ANALYZE table
COMMIT
在 PostgreSQL 9.3
之前,这是唯一推荐的重新加载 table 的方法。版本 9.3
引入了可以与 COPY
命令一起使用的 FREEZE
选项。标准文档说:
FREEZE
Requests copying the data with rows already frozen, just as they would be after running the VACUUM FREEZE command. This is intended as a performance option for initial data loading. Rows will be frozen only if the table being loaded has been created or truncated in the current subtransaction, there are no cursors open and there are no older snapshots held by this transaction.
我的直接问题是 COPY/FREEZE
之后是否还需要 运行 ANALYZE
。标准文档没有给出任何直接建议。以下顺序是否足够,还是我还需要 运行 ANALYZE
?
BEGIN
TRUNCATE table
COPY/FREEZE table
COMMIT
谢谢!
是的,您仍然应该 ANALYZE
在 COPY
中的数据之后强制立即 table 生成统计数据。
是否冻结元组与统计无关,这是一种避免以后反环绕真空的方法activity。