我们在Centos7上安装了一个postgres数据库服务器(10.3),并创建了一个名为" db_name"的数据库。我们有数据库访问权限pg_hba.conf中的设置如下:
# "local" is for Unix domain socket connections only
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
当我有sudo访问权限时,我可以访问数据库" db_name"。
[root@localhost bin]# sudo -s
[root@localhost bin]# psql -U db_name db_user
psql (10.3)
Type "help" for help.
db_name=>
当我尝试以普通Linux用户身份访问数据库时,出现以下错误:
[linuxuser@localhost bin]# psql -U db_name db_user
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我们想要限制某些用户sudo访问权限的原因是我们的报表专家需要访问数据库" db_name",但我们不希望他们拥有sudo权限来执行某些操作其他
为了使其有效,我应该采取什么样的设置? 谢谢!
答案 0 :(得分:0)
在PostgreSQL中,您应该创建一个角色来访问数据库。
为此你必须这样做:
更改为postgres帐户(在安装postgresql期间创建)
shutdown.bat -S
创建新角色
$ sudo -i -u postgres
创建数据库
postgres@server createuser --interactive
Output
Enter name of role to add: DB_Name
Shall the new role be a superuser? (y/n) y
创建用户,更改为用户并访问数据库
postgres@server createdb DB_Name
参考文献:
答案 1 :(得分:0)
我找到了解决方案。 问题的原因是没有/var/run/postgresql/.s.PGSQL.5432文件存在。 默认情况下,unix_socket_directories是' / tmp'在postgresql.conf中设置。
出于某种原因,常规的linux用户不是在查看/tmp/.s.PGSQL.5432,而是查看/var/run/postgresql/.s.PGSQL.5432文件。
所以修复如下:
cd /var/run
mkdir postgresql
cd postgresql/
ln -s /tmp/.s.PGSQL.5432 .s.PGSQL.5432
以下命令也适用。
psql -h /tmp -U db_user db_name