如何限制来自多个用户的postgresql中的数据库

如何限制来自多个用户的postgresql中的数据库

问题描述:

我在公开可见的服务器中创建了PostgreSQL数据库。如何限制来自多个用户的postgresql中的数据库

有几个用户,但我只希望他们中的2-3个可以访问系统中的数据库。所有应该能够读取和写入数据。

那么如何限制其他用户呢?可能吗?

默认情况下,连接到数据库的权限授予public角色。

因此,您需要做的第一件事就是撤消这个。为此,请以超级用户身份登录到该数据库(通常为postgres),例如

psql -U postgres new_database 

然后在SQL提示符下运行:

revoke connect on database new_database from public; 

然后,你需要的权限授予每个用户:

grant connect on database new_database to user_1; 
grant connect on database new_database to user_2; 

替换new_database与您创建的数据库的名称。

您还可以通过pg_hba.conf来控制对服务器的访问,但这有点复杂。详情请参阅手册:http://www.postgresql.org/docs/current/static/client-authentication.html