授予对 PostgreSQL 中未来表的权限?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22684255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:22:31  来源:igfitidea点击:

Grant privileges on future tables in PostgreSQL?

sqldatabasepostgresql

提问by Andrey Chernih

I am running PostgreSQL 9.3.1. I have testdatabase and backupuser which is used to backup the database. I have no problems with granting privileges to all current tables, but I have to grant privileges each time the new table is added to schema.

我正在运行 PostgreSQL 9.3.1。我有用于备份数据库的test数据库和backup用户。我对所有当前表授予权限没有问题,但是每次将新表添加到架构时我都必须授予权限。

createdb test

psql test
test=# create table foo();
CREATE TABLE
test=# grant all on all tables in schema public to backup;
GRANT
test=# create table bar();
CREATE TABLE

psql -U backup test
test=> select * from foo;
test=> select * from bar;
ERROR:  permission denied for relation bar

Is it possible to grant access to tables which will be created in future without making user owner of the table?

是否可以在不让用户拥有表的情况下授予对将来创建的表的访问权限?

采纳答案by Andrey Chernih

It looks like the solution is to alter default privileges for backupuser:

看起来解决方案是更改backup用户的默认权限:

alter default privileges in schema public grant all on tables to backup;
alter default privileges in schema public grant all on sequences to backup;