Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
934 views
in Technique[技术] by (71.8m points)

macos - 如何在Mac OS X上启动PostgreSQL服务器?(How to start PostgreSQL server on Mac OS X?)

FINAL UPDATE:

(最终更新:)

I had forgotten to run the initdb command.

(我忘了运行initdb命令。)

< /FINAL UPDATE>

(</ FINAL UPDATE>)

by running this command

(通过运行此命令)

ps auxwww | grep postgres

I see that postgres is not running

(我看到postgres没有运行)

> ps auxwww | grep postgres
remcat          1789   0.0  0.0  2434892    480 s000  R+   11:28PM   0:00.00 grep postgres

this raises the question: How do I start the postgresql server?

(这引出了一个问题:如何启动postgresql服务器?)

update:

(更新:)

>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

update 2:

(更新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

But when I try to start rails server, I still see this:

(但是当我尝试启动rails服务器时,我仍然看到:)

Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?

update 3:

(更新3:)

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

update 4:

(更新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).

(我发现没有pg_hba.conf(只有pg_hba.conf.sample)所以我修改了样本并将其重命名(以移除.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:

(更新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:

(更新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.

(信息。)

  ask by community wiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Homebrew package manager includes launchctl plists to start automatically.

(Homebrew包管理器包含自动启动的launchctl plists。)

For more information run brew info postgres .

(有关更多信息,请运行brew info postgres 。)

Start manually:

(手动启动:)

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

Stop manually:

(手动停止:)

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

Start automatically:

(自动启动:)

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

(“要立即启动postgresql并在登录时重新启动:”)

brew services start postgresql


What is the result of pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start ?

(pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start什么?)

What is the result of pg_ctl -D /usr/local/var/postgres status ?

(pg_ctl -D /usr/local/var/postgres status什么?)

Are there any error messages in the server.log?

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

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

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

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

Check the listen_addresses and port in postgresql.conf:

(检查postgresql.conf中的listen_addresses和port:)

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

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

Cleaning up

(打扫干净)

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

(Postgres最有可能通过HomebrewFinkMacPortsEnterpriseDB安装程序安装。)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...