出现错误:“Unix 域套接字上的连接“/var/run/postgresql/.s.PGSQL.5432”?” 尝试在 centos 上使用 postgresql 创建用户时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8962563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:34:15  来源:igfitidea点击:

getting error: "connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?" when trying to create a user with postgresql on centos

postgresqlcentos

提问by kamal

complete error:

完全错误:

Creating 'pcore' PostgreSQL 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"?

Connecting to PostgreSQL as 'pcore'... 
 ** Error occurred during execution: FATAL:  Ident authentication failed for user "pcore"

postgresql:

PostgreSQL:

psql -U postgres template1
psql (8.4.9)
Type "help" for help.

template1=# \l
                                  List of databases
   Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
(3 rows)

linux:

linux:

lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.7 (Final)
Release:    5.7
Codename:   Final

also:

还:

ps -ef | grep post

user   25055 25032  0 11:13 pts/1    00:00:00 grep post
postgres 32104     1  0 Jan20 ?        00:00:00 /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data

There is no user pcore in /etc/passwd Could this be the problem, that postgresql expects one to one matching between linux users and postgresql users ?

/etc/passwd 中没有用户 pcore 这可能是问题,postgresql 期望 linux 用户和 postgresql 用户之间一对一匹配吗?

I am trying to create a user when this error occurs:

发生此错误时,我正在尝试创建用户:

# Database imports
import pgdb as psql

# This will create the 'pcore' user using `su` to run the
# command as the postgres system user
def createPsqlPcoreUser(new_pass):
    print "Creating 'pcore' PostgreSQL user...",
    sys.stdout.flush()
    cmd_list = ['su', '-', 'postgres', '-c','psql --host=%s -c '\
        '"CREATE USER pcore WITH PASSWORD \'%s\' CREATEDB"' % \
        (PSQL_SOCKET_PATH, new_pass)]
    p1 = subprocess.Popen(cmd_list,
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    p1.wait()
    print p1.communicate()[0]

Additionally:

此外:

 sudo -u postgres createuser pcore -P
Enter password for new role: 
Enter it again: 
Shall the new role be a superuser? (y/n) y
createuser: could not connect to database postgres: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[root@localhost pcore]# service postgresql status
postmaster (pid 28901 28900 28899 28898 28896 28894) is running...
[root@localhost pcore]# ps -ef | grep post
postgres 28894     1  0 00:21 ?        00:00:00 /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data
postgres 28896 28894  0 00:21 ?        00:00:00 postgres: logger process                          
postgres 28898 28894  0 00:21 ?        00:00:00 postgres: writer process                          
postgres 28899 28894  0 00:21 ?        00:00:00 postgres: wal writer process                      
postgres 28900 28894  0 00:21 ?        00:00:00 postgres: autovacuum launcher process             
postgres 28901 28894  0 00:21 ?        00:00:00 postgres: stats collector process   

回答by Chris Travers

Fascinating error. It looks like your user is able to connect to sockets properly but the postgres user is not. I find this very odd. My guess is that there is something wrong with the profile of the postgres user.

迷人的错误。看起来您的用户能够正确连接到套接字,但 postgres 用户不能。我觉得这很奇怪。我的猜测是 postgres 用户的配置文件有问题。

where I would recommend starting is with a printenv as both your normal user and the postgres user and compare them. Particularly look at PGPORT and PGHOST variables as these can determine socket location. This is the first place to start.

我建议首先使用 printenv 作为您的普通用户和 postgres 用户并比较它们。特别注意 PGPORT 和 PGHOST 变量,因为它们可以确定套接字位置。这是第一个开始的地方。

Secondly you can check the postgresql.conf for the socket directory and set PGHOST to the absolute directory path. That would likely fix your problem, but something is messed up on the user account level on your system.

其次,您可以检查套接字目录的 postgresql.conf 并将 PGHOST 设置为绝对目录路径。这可能会解决您的问题,但是您系统上的用户帐户级别出现问题。