使用 pg_repack 重新打包 RDS 数据库不在线

dan*_*bst 5 postgresql amazon-rds

pg_repackRDS Postgresql 9.6.3 上运行时,其中一位编写者出现此故障:

ProgrammingError: permission denied for relation log_24034858
CONTEXT:  SQL statement "INSERT INTO repack.log_24034858(pk, row) 
VALUES(CASE WHEN $1 IS NULL THEN NULL ELSE (ROW($1.id)::repack.pk_24034858) END, $2)"
Run Code Online (Sandbox Code Playgroud)

但是pg_repack应该允许写入重新打包的表,为什么在这里失败?

ele*_*_al 7

我们发现了一个类似的问题。问题似乎是在重新打包架构中创建的日志表没有正确的权限。我们的解决方案是使用 ALTER DEFAULT PRIVALEGES 来解决这个问题:

CREATE EXTENSION pg_repack;
ALTER DEFAULT PRIVILEGES IN SCHEMA repack GRANT INSERT ON TABLES TO PUBLIC;
ALTER DEFAULT PRIVILEGES IN SCHEMA repack GRANT USAGE, SELECT ON SEQUENCES TO PUBLIC;
Run Code Online (Sandbox Code Playgroud)


dan*_*bst 1

根据亚马逊的说法,你必须pg_repack从你的超级用户帐户创建扩展。但扩展是用rds_superuser角色创建的。所有其他对象都是以该角色作为所有者创建的,例如:

\n\n
=> \\dnS+ repack                                                                                 \xe2\x94\x82 \n                     List of schemas                                                                    \xe2\x94\x82 subsidy | birth_month | birth_year\n  Name  |     Owner     | Access privileges | Description                                               \xe2\x94\x82---------+-------------+------------\n--------+---------------+-------------------+-------------                                              \xe2\x94\x82       1 |           7 |       1952\n repack | rds_superuser |                   |                                                           \xe2\x94\x82       1 |           7 |       1952\n(1 row)  \n
Run Code Online (Sandbox Code Playgroud)\n\n

您不应该更改架构的所有者。而你可能不想这样做REASSIGN OWNED ...。更改每个函数的所有者就足够了repack解决权限问题:

\n\n
create extension pg_repack;\nALTER FUNCTION repack.version() OWNER TO postgres;                                                                                                                                                             \nALTER FUNCTION repack.version_sql() OWNER TO postgres;                                                \nALTER FUNCTION repack.array_accum(anyelement) OWNER TO postgres;                                      \nALTER FUNCTION repack.oid2text(oid) OWNER TO postgres;                                                \nALTER FUNCTION repack.get_index_columns(oid,text) OWNER TO postgres;                                  \nALTER FUNCTION repack.get_order_by(oid,oid) OWNER TO postgres;                                        \nALTER FUNCTION repack.get_create_index_type(oid,name) OWNER TO postgres;                              \nALTER FUNCTION repack.get_create_trigger(oid,oid) OWNER TO postgres;                                  \nALTER FUNCTION repack.get_enable_trigger(oid) OWNER TO postgres;                                      \nALTER FUNCTION repack.get_assign(oid,text) OWNER TO postgres;                                         \nALTER FUNCTION repack.get_compare_pkey(oid,text) OWNER TO postgres;                                   \nALTER FUNCTION repack.get_columns_for_create_as(oid) OWNER TO postgres;                               \nALTER FUNCTION repack.get_drop_columns(oid,text) OWNER TO postgres;                                   \nALTER FUNCTION repack.get_storage_param(oid) OWNER TO postgres;                                       \nALTER FUNCTION repack.get_alter_col_storage(oid) OWNER TO postgres;                                   \nALTER FUNCTION repack.repack_indexdef(oid,oid,name,boolean) OWNER TO postgres;                        \nALTER FUNCTION repack.repack_trigger() OWNER TO postgres;                                             \nALTER FUNCTION repack.conflicted_triggers(oid) OWNER TO postgres;                                     \nALTER FUNCTION repack.disable_autovacuum(regclass) OWNER TO postgres;                                 \nALTER FUNCTION repack.repack_apply(cstring,cstring,cstring,cstring,cstring,integer) OWNER TO postgres;\nALTER FUNCTION repack.repack_swap(oid) OWNER TO postgres;                                             \nALTER FUNCTION repack.repack_drop(oid,integer) OWNER TO postgres;                                     \nALTER FUNCTION repack.repack_index_swap(oid) OWNER TO postgres;                                       \nALTER FUNCTION repack.get_table_and_inheritors(regclass) OWNER TO postgres;  \n
Run Code Online (Sandbox Code Playgroud)\n