postgresql 如何启动 Postgres 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14948406/
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-09-11 00:02:49  来源:igfitidea点击:

How to start Postgres server?

postgresqlosx-liondjango-postgresql

提问by harristrader

Ive actually had this problem for a while but I've finally decided to take it on. Postgres was initially installed using Brew.

我实际上已经遇到这个问题一段时间了,但我最终决定接受它。Postgres 最初是使用 Brew 安装的。

After my upgrade to OSX 10.8.2 to receive a

在我升级到 OSX 10.8.2 后收到一个

psql: 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"?

error when I typed the

我输入时出错

$ psql

command.

命令。

I see the following processes:

我看到以下过程:

$ ps auxw | grep post
Tulsa           59222   0.0  0.2  2483256  14808   ??  Ss   Thu03PM   0:02.61 /System/Library/PrivateFrameworks/DiskImages.framework/Resources/diskimages-helper -uuid 470DA5CC-1602-4D69-855F-F365A6512F90 -post-exec 4
Tulsa           57940   0.0  0.2  2498852  13648   ??  Ss   Wed10PM   0:00.61 /System/Library/PrivateFrameworks/DiskImages.framework/Resources/diskimages-helper -uuid FAFAAAB4-0F67-42C8-864E-EF8C31A42EE3 -post-exec 4
root            24447   0.0  0.1  2476468  10080   ??  Ss    8Feb13   0:03.40 /System/Library/PrivateFrameworks/DiskImages.framework/Resources/diskimages-helper -uuid CC768720-12C2-436C-9020-548C275A6B0C -post-exec 4
Tulsa           74224   0.0  0.0  2432768    596 s002  R+    7:24PM   0:00.00 grep post


$ which psql
/usr/local/bin/psql

$ pg_ctl start 
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information. 

回答by Andrew Lazarus

You haven't started the Postgres server. Some of the dmg packages for Postgres set it to run as a service on startup. But not however you did the install.

您还没有启动 Postgres 服务器。Postgres 的一些 dmg 包将其设置为在启动时作为服务运行。但不是你安装的。

You need to init a data directory, start postgres, and then go from there.

您需要初始化一个数据目录,启动 postgres,然后从那里开始。

initdb /some/directory # just do this ONCE
pg_ctl -D /some/directory start # many other options, e.g. logging, available here
psql postgres

You can set an environment variable for the data directory and you won't need the -Dflag later. You can look that up later.

你可以为数据目录设置一个环境变量,-D以后你就不需要这个标志了。你可以稍后查一下。