如何在Mac OS X上启动PostgreSQL服务器? [英] How can I start PostgreSQL server on Mac OS X?

查看:146
本文介绍了如何在Mac OS X上启动PostgreSQL服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忘记了运行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:

触摸失败,所以我改为这样做:

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.

推荐答案

Homebrew 程序包管理器包括launchctl plists来启动自动地.有关更多信息,请运行brew info postgres.

The Homebrew package manager includes launchctl plists to start automatically. For more information, run brew info postgres.

pg_ctl -D /usr/local/var/postgres start

pg_ctl -D /usr/local/var/postgres stop

要立即启动postgresql并在登录时重新启动:"

"To have launchd start postgresql now and restart at login:"

brew services start postgresql

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start的结果是什么?

pg_ctl -D /usr/local/var/postgres status的结果是什么?

server.log中是否有任何错误消息?

Are there any error messages in the server.log?

确保在pg_hba.conf中启用了tcp localhost连接:

Make sure tcp localhost connections are enabled in pg_hba.conf:

# IPv4 local connections:
host    all    all    127.0.0.1/32    trust

检查postgresql.conf中的listen_addresses和端口:

Check the listen_addresses and port in postgresql.conf:

egrep 'listen|port' /usr/local/var/postgres/postgresql.conf

#listen_addresses = 'localhost'        # What IP address(es) to listen on;
#port = 5432                # (change requires restart)


清理

PostgreSQL很可能是通过 Homebrew MacPorts

PostgreSQL was most likely installed via Homebrew, Fink, MacPorts or the EnterpriseDB installer.

检查以下命令的输出,以确定安装了哪个软件包管理器:

Check the output of the following commands to determine which package manager it was installed with:

brew && brew list|grep postgres
fink && fink list|grep postgres
port && port installed|grep postgres

这篇关于如何在Mac OS X上启动PostgreSQL服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆