PG修改表owner提示must be member of role “pg13“

PG修改表owner提示must be member of role “pg13”

背景:有一个表test6在pg13这个schema下,但是目前的owner是pg13_1。想把这个表的owner修改成pg13。然而在修改表的owner时候,提示must be member of role “pg13”

pg13test1=> \c pg13test1 pg13_1
You are now connected to database "pg13test1" as user "pg13_1".
pg13test1=> alter table pg13.test5 owner to pg13;
ERROR:  must be member of role "pg13"
pg13test1=> select * from pg_tables where tablename='test5';
 schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity 
------------+-----------+------------+------------+------------+----------+-------------+-------------
 pg13       | test5     | pg13_1     |            | f          | f        | f           | f
(1 row)

解决方案:

把原来的owner加上pg13的role。

grant pg13 to pg13_1;

以下是详细操作步骤:

pg13test1=> \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 pg13      |                                                            | {}
 pg13_1    |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 pg13test1=> \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 pg13      |                                                            | {}
 pg13_1    |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

pg13test1=> \c pg13test1 pg13
You are now connected to database "pg13test1" as user "pg13".
pg13test1=> grant pg13 to pg13_1;
GRANT ROLE
pg13test1=> \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 pg13      |                                                            | {}
 pg13_1    |                                                            | {pg13}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

pg13test1=> \c pg13test1 pg13_1
You are now connected to database "pg13test1" as user "pg13_1".
pg13test1=> alter table pg13.test5 owner to pg13;
ALTER TABLE
pg13test1=> select * from pg_tables where tablename='test5';
 schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity 
------------+-----------+------------+------------+------------+----------+-------------+-------------
 pg13       | test5     | pg13       |            | f          | f        | f           | f
(1 row)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值