我有一个本地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
我可以在命令行上连接到服务器:
$ 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
我正在尝试使用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"?
值得注意的是,它试图使用不存在的套接字文件.s.PGSQL.5432 ,而实际的套接字文件名是.s.PGSQL.5433 ,文件名几乎完全相同。
为什么使用错误的文件名,我该如何使用正确的文件名?
看起来你的PostgreSQL服务器已经被configuration为监听端口5433,而不是默认的5432.你的Postgres客户端应用程序默认是默认的,因此找不到套接字。 在运行应用程序之前,尝试将PGPORT环境variables设置为5433。 例如:
PGPORT=5433 ./osm2pgsql/osm2pgsql -m -d gis -U rory ../data.osm.bz2
对于我来说,解决这个错误的方法是在命令中添加-H localhost(即使直觉上,我不应该)
即:
osm2pgsql -H localhost -s -d foo switzerland-latest.osm.pbf
注意:我使用默认的postgres 5432端口