为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Mac OS X上启动PostgreSQL服务器?

如何在Mac OS X上启动PostgreSQL服务器?

慕的地8271018 2020-02-03 13:48:34
最后更新:我忘记了运行initdb命令。</最终更新>通过运行此命令ps auxwww | grep postgres我看到postgres没有运行> ps auxwww | grep postgresremcat          1789   0.0  0.0  2434892    480 s000  R+   11:28PM   0:00.00 grep postgres这提出了一个问题:如何启动postgresql服务器?更新:>pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log startserver startingsh: /usr/local/var/postgres/server.log: No such file or directory更新2:触摸不成功,所以我改为这样做:> mkdir /usr/local/var/postgres> vi /usr/local/var/postgres/server.log> ls /usr/local/var/postgres/          server.log但是,当我尝试启动Rails服务器时,仍然看到以下内容:Is the server running on host "localhost" and acceptingTCP/IP connections on port 5432?更新3:> pg_ctl -D /usr/local/var/postgres statuspg_ctl: no server running更新4:我发现那里没有pg_hba.conf(只有pg_hba.conf.sample),所以我修改了示例并将其重命名(以删除.sample)。这里是内容: # 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.conffind: /dev/fd/3: Not a directoryfind: /dev/fd/4: Not a directory更新5:sudo pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log startPassword:pg_ctl: cannot be run as rootPlease 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.confegrep: /usr/local/var/postgres/postgresql.conf: No such file or directory不过,我确实这样做:>sudo find / -name "*postgresql.conf*"find: /dev/fd/3: Not a directoryfind: /dev/fd/4: Not a directory/usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample/usr/share/postgresql/postgresql.conf.sampl
查看完整描述

3 回答

?
一只名叫tom的猫

TA贡献1906条经验 获得超2个赞

该自制包管理器包括launchctl的Plist自动启动。有关更多信息,请运行brew info postgres。


手动启动:


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


手动停止:


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


自动启动:


“要启动现在启动postgresql并在登录时重新启动:”


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中是否有任何错误消息?


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


# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

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


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


#listen_addresses = 'localhost'     # what IP address(es) to listen on;

#port = 5432                # (change requires restart)

打扫干净


Postgres很可能是通过Homebrew,Fink,MacPorts或EnterpriseDB安装程序安装的。


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


brew && brew list|grep postgres

fink && fink list|grep postgres

port && port installed|grep postgres


查看完整回答
反对 回复 2020-02-03
?
慕容708150

TA贡献1831条经验 获得超4个赞

如果要手动启动和停止postgresql(通过homebrew安装),最简单的方法是:


brew services start postgresql


brew services stop postgresql


查看完整回答
反对 回复 2020-02-03
  • 3 回答
  • 0 关注
  • 1195 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信