【问题标题】:Unexpected behavior from changing owner in postgres在 postgres 中更改所有者的意外行为
【发布时间】:2021-01-16 00:33:19
【问题描述】:

我在 postgres 中有一个表 myschema 具有不同所有者的架构 - 所有者 'foo' 和所有者 'bar'

将数据库上的所有权限授予所有者“bar”,然后以用户“bar”重新登录后,我尝试使用以下命令将所有 bar 拥有的表的所有权更改为“foo”:

SELECT format(
  'ALTER TABLE %I.%I.%I OWNER TO %I;',
  table_catalog,
  table_schema,
  table_name,
  'foo'  
)
FROM information_schema.tables
WHERE table_schema = 'myschema'

然后返回:

 ALTER TABLE my_db.my_schema.my_tableA OWNER TO foo;
 ALTER TABLE my_db.my_schema.my_tableB OWNER TO foo;
 ALTER TABLE my_db.my_schema.my_tableC OWNER TO foo;

成功

然后,当我运行select * from pg_tables; 时,我看到表所有者都没有改变。这怎么可能?会发生什么?

【问题讨论】:

  • commit; 修改了吗?
  • COMMIT 应该出现在语句的末尾吗?
  • 在所有声明之后。
  • 我刚刚收到警告:没有正在进行的事务提交
  • 好的,那肯定是不一样的。

标签: sql postgresql ddl


【解决方案1】:

要将表的所有权从 bar 更改为 foo,用户必须是这两个角色的成员。所以如果bar应该能够做到,那一定是超级用户或者foo的成员:

GRANT foo TO bar;

我猜你的陈述导致了一个你不知何故没有看到并且没有做任何事情的错误。

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2020-06-11
    • 1970-01-01
    • 2021-10-12
    • 2016-07-20
    • 1970-01-01
    相关资源
    最近更新 更多