gpt4 book ai didi

postgresql - Postgres 撤销用户的数据库访问权限

转载 作者:行者123 更新时间:2023-11-29 12:32:22 25 4
gpt4 key购买 nike

当我尝试过

REVOKE ALL PRIVILEGES ON DATABASE postgres from admin; 

但之后用户 admin 仍然可以通过 pgadmin 远程连接到 postgres

如何完全撤销用户对数据库的访问权限?

/root$ psql -U postgres
psql (9.2.24)
Type "help" for help.

postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
admin | No inheritance | {}
postgres | Superuser, Create role, Create DB, Replication | {}

postgres=# REVOKE ALL PRIVILEGES ON DATABASE postgres from admin;
REVOKE
postgres=# SELECT * FROM pg_stat_activity;
datid | datname | pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start |
query_start | state_change | waiting | state | query
-------+----------+--------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+
-------------------------------+-------------------------------+---------+--------+---------------------------------
12924 | postgres | 121487 | 10 | postgres | psql | | | -1 | 2018-03-10 20:20:42.458031+08 | 2018-03-10 20:21:27.367078+08 |
2018-03-10 20:21:27.367078+08 | 2018-03-10 20:21:27.367082+08 | f | active | SELECT * FROM pg_stat_activity;
(1 row)

postgres=# \q
/root$ psql -U admin postgres
psql (9.2.24)
Type "help" for help.

postgres=>

enter image description here

最佳答案

你可能还需要做一个

REVOKE CONNECT ON DATABASE postgres FROM PUBLIC; 

每个角色都是 PUBLIC 的隐式成员。

关于postgresql - Postgres 撤销用户的数据库访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49206699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com