Postgres数据库本地安装/运行

时间:2013-07-01 18:11:19

标签: postgresql command-line installation osx-mountain-lion postgis

尝试在OSX Mountain Lion上设置Postgres / PostGIS以与Django一起使用。但是,有些事情是错误的,我不知道如何解决它。

$ createdb geo
createdb: 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 "/var/pgsql_socket/.s.PGSQL.5432"?

$ postgres -D /usr/local/var/postgres
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 221) running in data directory "/usr/local/var/postgres"?

$ pg_ctl -D /usr/local/var/postgres -l logfile start
pg_ctl: another server might be running; trying to start server anyway
server starting

然后我发现this gist说了如何在狮子身上修好它。但它对我不起作用:

$ kill -9 221
$ pg_ctl -D /usr/local/var/postgres stop
waiting for server to shut down.... done
server stopped

$ pg_ctl -D /usr/local/var/postgres start
pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 1436) running in data directory "/usr/local/var/postgres"?

另一次尝试:

$ cd /usr/local/var/postgres
$ mv postmaster.pid postmaster.backup
$ pg_ctl -D /usr/local/var/postgres start
server starting

$ LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for "localhost"
FATAL:  could not create any TCP/IP sockets

有没有人成功地用山狮做过这件事?如果是这样,我错过了什么?感谢您对此问题的帮助!

1 个答案:

答案 0 :(得分:1)

此消息:

  

createdb:无法连接到数据库postgres:无法连接到   server:没有这样的文件或目录       服务器是在本地运行还是接受       Unix域套接字“/var/pgsql_socket/.s.PGSQL.5432”上的连接?

表示您的PostgreSQL服务器不使用/var/pgsql_socket作为其Unix域套接字目录,即服务器和客户端之间的 rendez-vous point 。这很常见,因为只有Apple与OSX服务器一起发布的PostgreSQL才使用该路径。顺便说一句,这就是Apple发布的createdb命令尝试按Apple配置连接到服务器的原因。

从那时起,有许多不同的解决方案可以解决这个问题,但更明显的是使用PostgreSQL安装附带的createdb命令而不是预安装的命令。你的系统。

如果您需要进一步的帮助,您应该指定如何安装PostgreSQL,因为有很多不同的软件包提供它,并且它们都使用不同的路径来避免相互挤压。

Homebrew更新

如果使用brew,我建议在superuser.com上应用答案: How should I set the PATH variable on my Mac so the Hombrew-installed tools are found?

据推测,你所指的Postgres + Postgis教程的作者很久以前就改变了它的PATH,忘了在文中提到它。

完成后,命令which createdb应返回/usr/local/bin/psql,这是自制版本,而不是Apple版本的初始/usr/bin/psql