在PostgreSQL中创建管理员用户
我正在尝试在PostgreSQL中创建一个管理员角色/用户,该角色/用户应满足以下要求:在PostgreSQL中创建管理员用户,postgresql,database-administration,database-permissions,Postgresql,Database Administration,Database Permissions,我正在尝试在PostgreSQL中创建一个管理员角色/用户,该角色/用户应满足以下要求: 应该能够为特定数据库进行备份(而不是 (其他) 应该能够创建可以访问 特定数据库(而不是其他数据库) 应该能够在特定数据库而不是其他数据库中创建/删除表 不能创建其他数据库 这就是我到目前为止所做的: create role dba with nosuperuser createdb createrole nologin replication bypassrls; grant usage on schem
create role dba with nosuperuser createdb createrole nologin replication bypassrls;
grant usage on schema public to dba;
alter default privileges in schema public grant all on tables to dba;
alter default privileges in schema public grant all on sequences to dba;
grant connect on database myDatabase to dba;
grant usage on schema public to dba;
grant select on all tables in schema public to dba;
grant select on all sequences in schema public to dba;
grant all privileges on all tables in schema public to dba;
create user dba_user login inherit encrypted password 'password' in role dba;
请建议如何修改上述代码以满足要求。要实现这一点,请执行以下修改:
- 将数据库及其所有架构和对象的所有权转移给新用户
- 给用户
CREATEROLE
- 确保从公共数据库中撤消所有数据库上的连接。向新用户授予有关数据库的
权限CONNECT
- 不要授予新用户对其中其他数据库或对象的任何权限
重新分配所有权
会很好,但不能局限于模式。一个好的解决方案可能是psql
的\gexec
。