在PostgreSQL中同时在所有表上修改OWNER
发布时间:2020-12-13 16:58:00 所属栏目:百科 来源:网络整理
导读:如何修改PostgreSQL数据库中所有表的所有者? 我试过ALTER TABLE * OWNER TO new_owner,但它不支持星号语法。 注意:作为@trygvis mentions in the answer below, REASSIGN OWNED 命令可用,因为至少版本8.2,并且是一个更容易的方法。 由于您要更改所有表
如何修改PostgreSQL数据库中所有表的所有者?
我试过ALTER TABLE * OWNER TO new_owner,但它不支持星号语法。
注意:作为@trygvis
mentions in the answer below,
REASSIGN OWNED 命令可用,因为至少版本8.2,并且是一个更容易的方法。
由于您要更改所有表的所有权,因此您可能也需要视图和序列。这是我做的: 表: for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" YOUR_DB` ; do psql -c "alter table "$tbl" owner to NEW_OWNER" YOUR_DB ; done 序列: for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" YOUR_DB` ; do psql -c "alter table "$tbl" owner to NEW_OWNER" YOUR_DB ; done 浏览次数: for tbl in `psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" YOUR_DB` ; do psql -c "alter table "$tbl" owner to NEW_OWNER" YOUR_DB ; done 你可能DRY有一点,因为alter语句对于所有三个是相同的。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |