postgresql批量修改表的owner

postgresql批量修改表的owner

postgresql中,对表的权限控制比较严格,很多事情只有owner才有权限去做。所以我们尽量用onwer账户去操作。
但是有的时候我们需求去批量修改owner,比如导入的表结构。但是官方并没有提供比较好的命令。
我们可以用拼接sql的方式去完成这个命令。

1.查看有哪些表

select * from information_schema.tables where table_schema='public';

img

2.拼接sql

select 'ALTER TABLE ' || table_name || ' OWNER TO yourowner;' from information_schema.tables where table_schema='public';

img

3.报生成的sql 复制下来,执行即可

原文连接: postgresql批量修改表的owner - 疯子110 - 博客园 (cnblogs.com)

posted @ 2023-11-08 17:05  蒲公英PGY  阅读(139)  评论(0编辑  收藏  举报