【问题标题】:Postgres Database Local Installation / RunningPostgres 数据库本地安装/运行
【发布时间】:2013-06-28 22:54:39
【问题描述】:

尝试在 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

有人用山狮成功地做到了这一点吗?如果是这样,我错过了什么?感谢您对这个问题的帮助!

【问题讨论】:

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


    【解决方案1】:

    这条消息:

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

    表示您的 PostgreSQL 服务器不使用 /var/pgsql_socket 作为其 Unix 域套接字目录,这是服务器和客户端之间的集合点。这很常见,因为只有 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,这是自制版本,而不是最初的/usr/bin/psql,这是Apple 版本。

    【讨论】:

    • 感谢您的想法@Daniel。我使用自制软件安装了 PostGREs,并遵循了instructions here。您对如何解决此问题有任何想法,以便我可以在 django 项目中使用我的 PostGREs 数据库吗?感谢您的想法!
    • 谢谢@Daniel。我按照链接帖子中的说明将usr/local/bin 放在usr/bin 上方,但是当我尝试which createdb 时,它输出/usr/bin/createdb,而不是您上面列出的内容。我错过了正确链接路径的东西吗?感谢您的想法!
    • @NickB:你的意思是编辑/etc/paths?您是否在新终端中开始了新会话?
    • 谢谢@Daniel。是的,我按照您链接的帖子中接受的答案中的建议编辑了/etc/paths。我还开始了一个新的终端会话,which createdb 现在返回/usr/local/bin/createdb.. 关于如何解决这个问题的任何想法?感谢您的想法!
    • @NickB:现在回到问题的开头,你可以重试createdb geo,希望它不会连接到postgresql。
    猜你喜欢
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    相关资源
    最近更新 更多