programing

Postgre 상태 확인 방법SQL 서버 Mac OS X

lovejava 2023. 5. 29. 09:05

Postgre 상태 확인 방법SQL 서버 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환경 변수입니다.

제가 가지고 있는 것은 이것입니다.~/.bashrcpostgres 파일:

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

포스트그레 기준SQL 9.3, 다음 명령을 사용할 수 있습니다.pg_isreadyPostgre의 연결 상태 확인SQL 서버.

문서에서:

pg_isready는 서버가 정상적으로 연결을 수락하는 경우 0을 셸로 반환하고, 서버가 연결을 거부하는 경우 1을 반환하며, 연결 시도에 응답하지 않는 경우 2를 반환하고, 잘못된 매개 변수로 인해 시도하지 않은 경우 3을 반환합니다.

당신은 아마도 게시물을 시작하지 않았을 것입니다.

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

이를 실행하면 다음과 같은 메시지가 표시됩니다.

성공.이제 다음을 사용하여 데이터베이스 서버를 시작할 수 있습니다.

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

여전히 문제가 있는 경우 방화벽을 확인합니다.HandsOff!와 같은 좋은 것을 사용하고 트래픽을 차단하도록 구성된 경우 페이지에 데이터베이스가 표시되지 않습니다.

postgresql 서버가 설치된 위치에 따라 다릅니다.아래와 같이 pg_ctl을 사용하여 서버를 수동으로 시작합니다.

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

brew를 사용하여 pgsql을 시작/중지할 수 있습니다.~/.bashrc 파일의 바로 가기를 추적했습니다.

alias start-pg='brew services start postgresql'
alias stop-pg='brew services stop postgresql'
alias restart-pg='brew services restart postgresql'

pg_ctl status다른 답변에 제안된 명령은 포스트마스터 프로세스가 존재하는지 확인하고, 존재하는 경우 포스트마스터 프로세스가 실행 중임을 보고합니다.그렇다고 해서 연결을 수락하거나 쿼리를 실행할 준비가 된 것은 아닙니다.

를 사용하는 것과 같은 다른 방법을 사용하는 것이 좋습니다.psql간단한 쿼리를 실행하고 종료 코드를 확인합니다.psql -c 'SELECT 1'또는 사용pg_isready 연결 상태를 확인합니다.

언급URL : https://stackoverflow.com/questions/7975414/how-to-check-status-of-postgresql-server-mac-os-x