PostgreSQL 서버 Mac OS X의 상태를 확인하는 방법
내 Postgresql 서버가 실행 중인지 여부를 어떻게 알 수 있습니까?
이 메시지가 나타납니다.
[~/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/postgres -D /Library/PostgreSQL/8.3/data
서버를 시작하려면 다음과 같이 실행하십시오.
/Library/PostgreSQL/8.3/bin/pg_ctl start -D /Library/PostgreSQL/8.3/data -l postgres.log
다음 명령을 실행하여 포스트그레스가 실행 중인지 확인할 수 있습니다.
$ pg_ctl status
PGDATA
환경 변수도 설정하고 싶을 것 입니다.
~/.bashrc
postgres에 대한 내 파일에 있는 내용은 다음과 같습니다 .
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
이제 시도해 보면 다음과 같은 결과를 얻을 수 있습니다.
$ show-pg-status
pg_ctl: server is running (PID: 11030)
/usr/local/Cellar/postgresql/9.2.4/bin/postgres
아마도 postgres를 초기화하지 않았을 것입니다.
HomeBrew를 사용하여 설치 한 경우 다른 항목을 사용할 수있게되기 전에 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
Once you have run that, it should say something like:
Success. You can now start the database server using:
postgres -D /usr/local/var/postgres or pg_ctl -D /usr/local/var/postgres -l logfile start
If you are still having issues, check your firewall. If you use a good one like HandsOff! and it was configured to block traffic, then your page will not see the database.
As of PostgreSQL 9.3, you can use the command pg_isready
to determine the connection status of a PostgreSQL server.
From the docs:
pg_isready returns 0 to the shell if the server is accepting connections normally, 1 if the server is rejecting connections (for example during startup), 2 if there was no response to the connection attempt, and 3 if no attempt was made (for example due to invalid parameters).
It depends on where your postgresql server is installed. You use the pg_ctl to manually start the server like below.
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
The pg_ctl status
command suggested in other answers checks that the postmaster process exists and if so reports that it's running. That doesn't necessarily mean it is ready to accept connections or execute queries.
It is better to use another method like using psql
to run a simple query and checking the exit code, e.g. psql -c 'SELECT 1'
, or use pg_isready
to check the connection status.
참고URL : https://stackoverflow.com/questions/7975414/how-to-check-status-of-postgresql-server-mac-os-x
'IT story' 카테고리의 다른 글
여러 함수 호출 onClick ReactJS (0) | 2020.09.11 |
---|---|
출력 디렉토리로 복사는 폴더 구조를 복사하지만 파일 만 복사하려고합니다. (0) | 2020.09.11 |
다른 div 아래의 css3 그림자, Z- 색인이 작동하지 않음 (0) | 2020.09.11 |
MySQL의 기존 필드에 문자열을 어떻게 추가 할 수 있습니까? (0) | 2020.09.11 |
ASP.NET MVC 모델 대 ViewModel (0) | 2020.09.11 |