如何在 Mac OS X 上启动 PostgreSQL 服务器? [英] How can I start PostgreSQL server on Mac OS X?
问题描述
我忘记运行 initdb
命令.
通过运行这个命令
ps auxwww | grep postgres
我看到 postgres
没有运行
> ps auxwww | grep postgres
remcat 1789 0.0 0.0 2434892 480 s000 R+ 11:28PM 0:00.00 grep postgres
这就提出了一个问题:
如何启动 PostgreSQL 服务器?
How do I start the PostgreSQL server?
更新:
> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
sh: /usr/local/var/postgres/server.log: No such file or directory
更新 2:
touch 没有成功,所以我做了这个:
The touch was not successful, so I did this instead:
> mkdir /usr/local/var/postgres
> vi /usr/local/var/postgres/server.log
> ls /usr/local/var/postgres/
server.log
但是当我尝试启动 Ruby on Rails 服务器时,我仍然看到:
But when I try to start the Ruby on Rails server, I still see this:
服务器是否在主机localhost"上运行?并接受端口 5432 上的 TCP/IP 连接?
Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?
更新 3:
> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running
更新 4:
我发现没有任何 pg_hba.conf文件(只有文件pg_hba.conf.sample),所以我修改了示例并将其重命名(以去除 .sample).以下是内容:
I found that there wasn't any pg_hba.conf file (only file pg_hba.conf.sample), so I modified the sample and renamed it (to remover the .sample). Here are the contents:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
但我不明白这一点:
> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running
还有:
sudo find / -name postgresql.conf
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
更新 5:
sudo pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Password:
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
更新 6:
这看起来很奇怪:
> egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
egrep: /usr/local/var/postgres/postgresql.conf: No such file or directory
不过,我确实这样做了:
Though, I did do this:
>sudo find / -name "*postgresql.conf*"
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample
/usr/share/postgresql/postgresql.conf.sample
所以我这样做了:
egrep 'listen|port' /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample
#listen_addresses = 'localhost' # what IP address(es) to listen on;
#port = 5432 # (change requires restart)
# supported by the operating system:
# %r = remote host and port
所以我尝试了这个:
> cp /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf
> cp /usr/share/postgresql/postgresql.conf.sample /usr/share/postgresql/postgresql.conf
我仍然遇到同样的服务器正在运行吗?";留言.
I am still getting the same "Is the server running?" message.
推荐答案
如果您想手动启动和停止 PostgreSQL(通过 Homebrew),最简单的方法是:
If you want to manually start and stop PostgreSQL (installed via Homebrew), the easiest way is:
brew services start postgresql
和
brew services stop postgresql
如果您有特定版本,请确保为版本添加后缀.例如:
If you have a specific version, make sure to suffix the version. For example:
brew services start postgresql@10
这篇关于如何在 Mac OS X 上启动 PostgreSQL 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!