在PostgreSQL中同时在所有表上修改OWNER

前端之家收集整理的这篇文章主要介绍了在PostgreSQL中同时在所有表上修改OWNER前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何修改Postgresql数据库中所有表的所有者?

我试过ALTER TABLE * OWNER TO new_owner,但它不支持星号语法。

注意:作为@trygvis mentions in the answer belowREASSIGN 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语句对于所有三个是相同的。

原文链接:https://www.f2er.com/postgresql/194087.html

猜你在找的Postgre SQL相关文章