Macos 如何检查PostgreSQL server Mac OS X的状态

Macos 如何检查PostgreSQL server Mac OS X的状态,macos,postgresql,Macos,Postgresql,如何判断我的Postgresql server是否正在运行 我收到了这样的信息: [~/dev/working/sw] sudo bundle exec rake db:migrate rake aborted! could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 543

如何判断我的Postgresql server是否正在运行

我收到了这样的信息:

[~/dev/working/sw] sudo bundle exec rake db:migrate 
rake aborted!
could not connect to server: Connection refused
    Is the server running on host "localhost" and accepting
    TCP/IP connections on port 5432?
更新:

> which postgres
/usr/local/bin/postgres
> pg_ctl -D /usr/local/bin/postgres -l /usr/local/bin/postgres/server.log start
pg_ctl: could not open PID file "/usr/local/bin/postgres/postmaster.pid": Not a directory
更新2:

>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

检查正在运行的进程的最简单方法:

ps auxwww | grep postgres
并查找类似以下内容的命令(您的版本可能不是8.3):

要启动服务器,请执行以下操作:

/Library/PostgreSQL/8.3/bin/pg_ctl start -D /Library/PostgreSQL/8.3/data -l postgres.log
$ show-pg-status
pg_ctl: server is running (PID: 11030)
/usr/local/Cellar/postgresql/9.2.4/bin/postgres

这取决于postgresql server的安装位置。您可以使用pg_ctl手动启动服务器,如下所示

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

你可能没有参加postgres

如果使用自制软件安装,则必须先运行init,然后才能使用其他软件

要查看说明,请运行
brew info postgres

# Create/Upgrade a Database
If this is your first install, create a database with:
     initdb /usr/local/var/postgres -E utf8

To have launchd start postgresql at login:
   ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 
Then to load postgresql now:     
   launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 
Or, if you don't want/need launchctl, you can just run:
    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
一旦你运行了它,它应该说:

成功。现在可以使用以下命令启动数据库服务器:

postgres -D /usr/local/var/postgres or
pg_ctl -D /usr/local/var/postgres -l logfile start

如果仍然存在问题,请检查防火墙。如果你用一个好的方法,比如握手!并且它被配置为阻止流量,那么您的页面将看不到数据库。

您可以运行以下命令来确定postgress是否正在运行:

$ pg_ctl status
您还需要设置
PGDATA
环境变量

以下是我在postgres的
~/.bashrc
文件中的内容:

export PGDATA='/usr/local/var/postgres'
export PGHOST=localhost
alias start-pg='pg_ctl -l $PGDATA/server.log start'
alias stop-pg='pg_ctl stop -m fast'
alias show-pg-status='pg_ctl status'
alias restart-pg='pg_ctl reload'
要使其生效,请记住按如下方式提供:

$ . ~/.bashrc
现在,尝试一下,您应该会得到如下结果:

/Library/PostgreSQL/8.3/bin/pg_ctl start -D /Library/PostgreSQL/8.3/data -l postgres.log
$ show-pg-status
pg_ctl: server is running (PID: 11030)
/usr/local/Cellar/postgresql/9.2.4/bin/postgres

其他答案中建议的
pg_ctl status
命令检查postmaster进程是否存在,如果存在,则报告它正在运行。这并不一定意味着它已经准备好接受连接或执行查询


最好使用另一种方法,如使用
psql
来运行简单的查询并检查退出代码,例如
psql-c'SELECT 1'
,或使用
pgu isready

从PostgreSQL 9.3开始,您可以使用命令
pg\u isready
来确定PostgreSQL服务器的连接状态

从:

如果服务器正常接受连接,pg_isready将返回0到shell;如果服务器拒绝连接(例如在启动过程中);如果没有响应连接尝试,pg_isready将返回1;如果没有尝试(例如由于无效参数),pg_isready将返回3


您可以使用brew启动/停止pgsql。我的~/.bashrc文件中有以下快捷方式


好的,如果我找不到类似的东西,如何启动服务器?
pgrep postgres
也可以。或
ps auxwww | grep[p]ostgres
以防止
grep
被拾取。Boo,hiss关于
ps | grep
舞弊建议<代码>pgrep勉强可以接受<代码>pg_ctl状态非常好
ps auxwww | grep postgres
将匹配
grep postgres
,和
less/var/log/postgres/whatever
。应该注意,数据库集群目录
/Library/PostgreSQL/8.3/data
由用户通过
initdb
命令任意创建。这是您在路径中用bin替换var的@Ramy。嗯……好的。我想我需要检查我的安装位置。请查看最新更新。您是如何安装postgres的?安装postgres后是否运行了initdb?您还应该注意Mac OS/X上的postgres的多个版本。如果您通过自制程序安装了postgres,那么当路径设置不正确时,您可能会出现上述错误-我只是不小心篡改了路径,所有内容都是使用系统安装的postgres开始的,但效果不太好在我根据您的错误消息调整使用brew安装的路径之前,我打赌SamGoody建议运行initdb命令将解决您的“连接被拒绝”问题。修复后,请尝试我的建议以获取您的postgres db服务器状态。
psql-c“选择1”-d{dbname}>/dev/null | | postgres-d/usr/local/var/postgres>postgres.log 2>&1&
,如果您想一次性检查并启动postgres(对于自动化脚本来说很方便).如何检查9.3之前版本的psql?关于
如何检查状态
不启动/停止pgsql的问题!你可以试试。。。brew服务列表| grep postgres