postgresql - 我可以在 PostgreSQL 9.3 中将 TRUNCATE + COPY + ANALYZE 替换为 TRUNCATE + COPY/FREEZE 吗

标签 postgresql postgresql-9.3

我正在尝试优化我的批量加载例程。

目前我分步骤加载数据(我没有遵循下面的 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/

相关文章:

postgresql - 具有别名的 INSERT 不适用于 PostgreSQL

sql - 分组时如何联合数组?

sql - 创建存储过程(int[] 作为参数),当 int 数组中没有匹配项时删除表中的现有记录

oracle - PL/pgSQL 中 PL/SQL %NOTFOUND 的等价物是什么?

postgresql - 如何在时间间隔之间获取行

postgresql - PL/pgSQL 函数 : How to return a normal table with multiple columns using an execute statement

java - 由 : org. postgresql.util.PSQLException 引起:尝试自动创建数据库时数据库不存在

postgresql - 从 pgadmin 获取的备份小于从 pg_dump 获取的备份

arrays - Postgres整数数组作为参数?

postgresql - 如何在 Laravel 中将数据类型从字符串更改为自动增量?