用户始终可以连接到数据库 [POSTGRES]

User can always connect to the database [POSTGRES]

我连接了用户 "Postgres" 并创建了一个用户:

postgres=# CREATE DATABASE db_example ;
postgres=# CREATE USER user WITH PASSWORD 'user123';
postgres=# REVOKE CONNECT ON DATABASE db_example FROM user;
REVOKE
postgres=# \q

稍后,我尝试与用户 "user" 连接至 "db_example":

root@debian:/home/debian# psql -d db_example -U user -h localhost

psql (9.4.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

db_example=>

为什么我可以连接到用户 "user" 到 "db_example"?

感谢您的帮助,祝您愉快。

这是因为 PUBLIC(即每个人)默认拥有该权限。

要删除它,运行

REVOKE CONNECT ON DATABASE db_example FROM PUBLIC;

运行 \l+ 查看当前在数据库上设置的权限。 空设置表示默认值:所有者可以执行所有操作,并且 PUBLIC 可以连接。