最佳答案
我忘了运行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
但是当我尝试启动Ruby on Rails服务器时,我仍然看到:
服务器是否在主机上运行“localhost”并接受端口5432上的TCP/IP连接?
更新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 startserver starting> pg_ctl -D /usr/local/var/postgres statuspg_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.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
我仍然收到相同的“服务器正在运行吗?”消息。