为什么它 运行 即使在 GCP 上的 Cloud Sql 中关闭了自动清理?

Why does it run even with autovacuum turned off in Cloudsql on GCP?

我正在使用 CloudSQL - GCP 的 postgresql12 版本。

我们目前正在输入数十亿条数据,我们不希望输入中途中断

但是,我在 CloudSQL 标志中将 autovacuum 设置设置为关闭,但它似乎每天都会自动完成。

随着 autovacuum 的进行,使用 python sqlalchemy 输入会导致错误。

sqlalchemy.exc.OperationalError: (psycopg2.errors.ProgramLimitExceeded) multixact "members" limit exceeded
DETAIL: This command would create a multixact with 2 members, but the remaining space is only enough for 1 member.
HINT: Execute a database-wide VACUUM in database with OID 16427 with reduced vacuum_multixact_freeze_min_age and vacuum_multixact_freeze_table_age settings.

解决方法是什么?

解决办法就是按照提示去做。这是防止数据库遭受数据损坏所必需的。根本原因是 multixact 包含交易编号,如果这些交易编号环绕(在大约 20 亿次交易之后),一些 table 行可能突然看起来被锁定。

正如the documentation所说:

As a safety device, an aggressive vacuum scan will occur for any table whose multixact-age (see Section 25.1.5.1) is greater than autovacuum_multixact_freeze_max_age. Also, if the storage occupied by multixacts members exceeds 2GB, aggressive vacuum scans will occur more often for all tables, starting with those that have the oldest multixact-age. Both of these kinds of aggressive scans will occur even if autovacuum is nominally disabled.

显然,那些数据库拼命一次又一次地启动以防止最坏情况发生的 autovacuum 运行没有成功。您应该查看日志文件以找出原因。

抓紧时间,保存您的数据库。然后弄清楚为什么反环绕 autovacuum 首先失败并解决该问题。并启用 autovacuum!如果需要,您可以在将数据加载到其中时暂时在单个 table 上禁用它。