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

  • 回答 (2)
  • 关注 (0)
  • 查看 (889)

我忘记了运行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服务器?

更新:

>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:

触摸不成功,所以我做了这个,而不是:

> 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 accepting
TCP/IP connections on port 5432?

更新3:

> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running

更新4:

I found that there WAS NO pg_hba.conf (only 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
but I don't understand this:
> 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

also:

sudo find / -name postgresql.conf
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

update 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.

update 6:

this seems odd:
> 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

so I did this:
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
so I tried this:
> 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 
still getting the same "Is the server running?" message.
社会人就是社会人就是修改于
黄易音乐战组程序员回答于

如果你想手动启动和停止postgresql(通过自制软件安装),最简单的方法是:

brew services start postgresql

brew services stop postgresql
HKC

红客学院 · 创始人 (已认证)

道可道 非常道 名可名 非常名回答于

Homebrew包管理器包括launchctl plists自动启动。网络上有许多的信息

运行,了解更多

rew info postgres

手动启动:

pg_ctl - d /usr/local/var/postgres开始

手动停止:

pg_ctl - d /usr/local/var/postgres停止

自动启动:

“要让launchd立即启动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)

扫码关注云+社区

领取腾讯云代金券