我正在尝试使用以下脚本将 PostgreSQL 12 集群升级到版本 13:
/usr/lib/postgresql/13/bin/pg_upgrade --check \
--old-datadir=/var/lib/postgresql/12/main \
--new-datadir=/var/lib/postgresql/13/main \
--old-bindir=/usr/lib/postgresql/12/bin \
--new-bindir=/usr/lib/postgresql/13/bin \
--old-options=' -c config_file=/etc/postgresql/12/main/postgresql.conf' \
--new-options=' -c config_file=/etc/postgresql/13/main/postgresql.conf' \
--old-port=5432 \
--new-port=5433
支票返回:
*Clusters are compatible*
然而,在实际升级过程中,由于pg_catalog.pg_pltemplate
表:
pg_restore: creating ACL "pg_catalog.TABLE "pg_pltemplate""
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 17728; 0 0 ACL TABLE "pg_pltemplate" postgres
pg_restore: error: could not execute query: ERROR: relation "pg_catalog.pg_pltemplate" does not exist
这似乎是一个老问题,但是升级脚本不会检查这些模板。
到目前为止,这个查询似乎应该返回一个空结果,否则你会遇到麻烦:
$ psql -c "SELECT * FROM information_schema.role_table_grants WHERE table_name='pg_pltemplate';"
grantor | grantee | table_catalog | table_schema | table_name | privilege_type | is_grantable | with_hierarchy
----------+----------+---------------+--------------+---------------+----------------+--------------+----------------
postgres | postgres | postgres | pg_catalog | pg_pltemplate | TRIGGER | YES | NO
postgres | postgres | postgres | pg_catalog | pg_pltemplate | REFERENCES | YES | NO
postgres | postgres | postgres | pg_catalog | pg_pltemplate | TRUNCATE | YES | NO
postgres | postgres | postgres | pg_catalog | pg_pltemplate | DELETE | YES | NO
postgres | postgres | postgres | pg_catalog | pg_pltemplate | UPDATE | YES | NO
postgres | postgres | postgres | pg_catalog | pg_pltemplate | SELECT | YES | YES
postgres | postgres | postgres | pg_catalog | pg_pltemplate | INSERT | YES | NO
postgres | PUBLIC | postgres | pg_catalog | pg_pltemplate | SELECT | NO | YES
撤销这些特权:
REVOKE SELECT ON "pg_catalog"."pg_pltemplate" FROM PUBLIC;
REVOKE ALL ON "pg_catalog"."pg_pltemplate" FROM postgres;
REVOKE
由于语句被保存到架构中,因此并没有真正的帮助:
pg_restore: error: could not execute query: ERROR: relation "pg_catalog.pg_pltemplate" does not exist
Command was: REVOKE ALL ON TABLE "pg_catalog"."pg_pltemplate" FROM "postgres";
REVOKE SELECT ON TABLE "pg_catalog"."pg_pltemplate" FROM PUBLIC;
可以使用以下方法检查(结果也应该为空):
pg_dump --port 5432 --schema-only --quote-all-identifiers | grep pg_pltemplate
在执行升级之前。
任何想法如何完全摆脱pg_catalog.pg_pltemplate
桌子?