Postgres 应用程序尝试使用不正确的套接字文件

Ama*_*rus 5 postgresql socket

我有一个本地 postgres 服务器正在运行(在 ubuntu linux 上)。它通过套接字文件侦听:

$ ls -la /var/run/postgresql/
total 8
drwxrwsrwx  2 postgres postgres  100 2011-04-15 19:06 .
drwxr-xr-x 26 root     root     1100 2011-04-15 19:12 ..
-rw-------  1 postgres postgres    5 2011-04-15 19:06 8.4-main.pid
srwxrwxrwx  1 postgres postgres    0 2011-04-15 19:06 .s.PGSQL.5433
-rw-------  1 postgres postgres   34 2011-04-15 19:06 .s.PGSQL.5433.lock
Run Code Online (Sandbox Code Playgroud)

我可以在命令行上正常连接到服务器:

$ psql -d gis -U rory
psql (8.4.7)
Type "help" for help.

gis=# \q
$ psql -d gis
psql (8.4.7)
Type "help" for help.

 gis=# \q
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用osm2pgsql,这是OpenStreetMap 项目中的一个应用程序,它将数据导入到 pgsql 数据库中。

但是我得到的错误是:

$ ./osm2pgsql/osm2pgsql -m -d gis -U rory ../data.osm.bz2 
osm2pgsql SVN version 0.70.5

Connection to database failed: 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"?
Run Code Online (Sandbox Code Playgroud)

值得注意的是,它试图使用.s.PGSQL.5432不存在的套接字文件,而实际的套接字文件名是.s.PGSQL.5433,文件名几乎完全相同。

为什么它使用错误的文件名,我如何使它使用正确的文件名?

Ste*_*day 8

看起来您的 PostgreSQL 服务器已配置为侦听端口 5433,而不是默认的 5432。您的 Postgres 客户端应用程序采用默认设置,因此找不到套接字。PGPORT在运行应用程序之前尝试将环境变量设置为 5433。例如:

PGPORT=5433 ./osm2pgsql/osm2pgsql -m -d gis -U rory ../data.osm.bz2
Run Code Online (Sandbox Code Playgroud)