我正在尝试优化我的批量加载例程。
目前我分步骤加载数据(我没有遵循下面的 SQL 语法,只是遵循算法):
BEGIN
TRUNCATE table
COPY into table
ANALYZE table
COMMIT
在 PostgreSQL 9.3
之前,这是重新加载表的唯一推荐方法。版本 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
谢谢!
最佳答案
是的,在COPY
数据后,您仍然应该ANALYZE
强制立即生成表统计信息。
元组是否被卡住与统计数据无关,这是避免以后反环绕真空事件的一种方法。
关于postgresql - 我可以在 PostgreSQL 9.3 中将 TRUNCATE + COPY + ANALYZE 替换为 TRUNCATE + COPY/FREEZE 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30689560/