programing

Postgres가 서버에 연결할 수 없습니다.

oldcodes 2023. 5. 14. 11:04
반응형

Postgres가 서버에 연결할 수 없습니다.

내가 한 후에brew update그리고.brew upgrade제 우편물에 문제가 생겼습니다.게시물을 제거하고 다시 설치하려고 했지만 제대로 작동하지 않았습니다.

이것이 오류 메시지입니다.(또한 제가 하려고 할 때 이 오류 메시지가 표시되었습니다.rake db:migrate)

$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

어떻게 해결해야 하나요?

Mac 버전:산사자.

홈브루 버전: 0.9.3

postgres 버전: psql(Postgre)SQL) 9.2.1

그리고 제가 한 일은 다음과 같습니다.

$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.2.1...
$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.1.4...
$ psql --version
bash: /usr/local/bin/psql: No such file or directory
$ brew install postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.1/postgresql-9.2.1.tar.bz2
Already downloaded: /Library/Caches/Homebrew/postgresql-9.2.1.tar.bz2
......
......
==> Summary
/usr/local/Cellar/postgresql/9.2.1: 2814 files, 38M, built in 2.7 minutes
$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "laigary".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
homebrew.mxcl.postgresql: Already loaded
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.14.1
1 gem installed
$ psql --version
psql (PostgreSQL) 9.2.1
$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

홈브루를 설치한 에, 할 때, 다설를시치후에한때, 사할용제가루홈.$ psql오류 메시지가 표시되지 않습니다.

하지만 나는 달립니다.rake db:migrate내 레일즈 앱에는 다음이 표시됩니다.

could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `initialize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `new'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `connect'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:107:in `rescue in create_database'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:51:in `create_database'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (3 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (2 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/local/bin/rake:32:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"riy_development", "pool"=>5, "username"=>nil, "password"=>nil}

마침내 해결책을 찾았습니다.

sudo mkdir /var/pgsql_socket/
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/

이 해결책은 조금 까다롭지만 효과가 있습니다.누구든 더 나은 해결책이 있기를 바랍니다.

갱신하다

이것은 저에게도 효과가 있습니다.

rm /usr/local/var/postgres/postmaster.pid

유사한 문제가 발생했습니다. pid 파일이 게시물 시작을 차단하고 있습니다.수정 방법:

$ rm /usr/local/var/postgres/postmaster.pid
$ brew services restart postgresql

그러면 모든 것이 잘 될 것입니다.


업데이트:

Apple M1(Big Sur) 사용자의 경우 대신 다음 작업을 수행합니다.

$ rm /opt/homebrew/var/postgres/postmaster.pid
$ brew services restart postgresql

갱신하다 (2022년 11월 15일):

Apple M1/M2(Ventura) 사용자의 경우 다음을 수행합니다.

$ bundle install (just to make sure pg is installed)
$ brew services restart postgresql

이 문제는 Brew가 Postgres 업그레이드를 수행하여 데이터 파일이 새 서버와 호환되지 않을 때 발생합니다.

저의 경우 9.3에서 9.4로 업그레이드할 때 발생했습니다.

OS X/홈브루:

달기보를 실행해 .postgres -D /usr/local/var/postgres포스트그레스가 시작되지 않을 경우 훨씬 더 자세한 출력을 제공합니다.또는 다음 위치에서 로그 파일을 엽니다./usr/local/var/log/postgres.log(/opt/homebrew/var/log/postgres.logMac M1)에서 "FATAL: 데이터베이스 파일이 서버와 호환되지 않음" 라인을 찾습니다.

경우에는 내경에는기, 리달우기를 합니다.rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8이전 데이터베이스를 제거한 다음 postgres db 스키마를 다시 초기화합니다. (데이터가 파괴됩니다.)

솔루션에 대해 https://github.com/Homebrew/homebrew/issues/35240 에 감사드립니다.철저한 재설치에 대한 전체 지침은 다음에서 확인할 수 있습니다.Homebrew Postgres를 완전히 제거하고 다시 설치하는 방법 - Test Double Blog(M1 Mac에 있는 경우에는 /opt/homebrew/var 경로를 /usr/local/var로 대체합니다)

후(with 데터베사한후재성생를용이(with 이스사))rake db:create이 다시 모든 것이 다시 정상적으로 작동했습니다.

마지막으로, 댓글의 링크는 당신의 데이터를 보존하는 이 가능한 솔루션을 가리키지만, 저는 그것을 시도하지 않았습니다: Postgre를 업그레이드하는 방법.데이터 손실 없이 버전 9.6에서 버전 10.1로 SQL - 스택 오버플로

여기서 저에게 맞는 솔루션을 찾았습니다.

https://dba.stackexchange.com/questions/75214/psql-could-not-connect-to-server-no-such-file-or-directory

기본적으로 다음 명령을 실행하여 서버를 수동으로 시작합니다.

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

brew와 함께 postgres를 설치하고 제거하는 것이 효과가 없다면, postgresql 설치의 로그를 보거나 다음과 같이 하십시오.

postgres -D /usr/local/var/postgres

다음과 같은 종류의 출력이 표시되는 경우

LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.6.1.

그런 다음 다음을 시도합니다.

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

그런 다음 서버를 시작합니다.

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

원천

데이터베이스 업그레이드가 가능합니다.

brew postgresql-upgrade-database

을 차단하고 pid Postgres가 pid Postgres가 시작됩니다.launchctl데몬이 데이터베이스 데몬을 로드하려고 시도하다가 실패하면 plist 파일을 언로드해야 합니다.

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

그런 다음 pid 파일을 제거합니다.

$ rm /usr/local/var/postgres/postmaster.pid

그런 다음 다시 로드합니다.launchctl

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

이나 Postgres.app을 사용하는 나 이 를 읽을 수 .host: localhost데이터베이스에 있습니다.ymlhttp://postgresapp.com/documentation#toc_3

brew services start postgres 

날 위해 일했다!

이 문제는 postmaster.pid 파일을 남겨둔 충돌 프로세스 때문일 수도 있습니다.이 작업을 수행하고 작업을 수행합니다.

$ brew services stop postgresql
$ rm /usr/local/var/postgres/postmaster.pid # adjust path accordingly to your install
$ brew services start postgresql

문제는 포트 5432에서 이미 실행 중인 서비스가 있고 이 포트를 통해 psql 소켓 연결을 설정할 수 없기 때문입니다.

소켓 파일을 제거했습니다.

rm -rf /tmp/.s.PGSQL.5432/

그리고 나서 나는 포스트그레스 서비스를 다시 초기화했습니다.

postgres -D /usr/local/var/postgres

이것은 저에게 효과가 있었습니다.

소켓 파일이 있는지 확인합니다.

$ ls -l /tmp/.s.PGSQL.5432
srwxrwxrwx  1 you  wheel  0 Nov 16 09:22 /tmp/.s.PGSQL.5432

그렇지 않으면 postgresql.conf에서 unix_socket_directory 변경 내용을 확인합니다.

$ grep unix_socket /usr/local/var/postgres/postgresql.conf
#unix_socket_directory = ''     # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation

이것을 피하는 가장 어리석은 방법은 하는 것입니다.

brew reinstall postgresql

이렇게 하면 사용자 권한 등이 모두 그대로 유지되고 모든 항목이 새 항목으로 재설정됩니다.항상 작동합니다!

저의 경우, Mac OS 업데이트로 인해 문제가 발생했습니다.Postgre 업그레이드 중SQL이 문제를 해결했습니다.

# upgrade database version solved the trouble
$ brew postgresql-upgrade-database

그러나 이 오류는 매우 일반적이며 여러 가지 가능한 이유가 있습니다. 위의 솔루션에 전적으로 의존해서는 안 됩니다.

MacOS BigSur의 경우 홈브루 포스트그:

  • rm /opt/homebrew/var/postgres/postmaster.pid
  • brew services restart postgresql

제겐 효과가 있었어요 어떤 파일도 제거할 필요가 없었어요

brew postgresql-upgrade-database

이것이 실제로 여러분이 해야 할 일입니다.

대신 /usr/local/var/postgres/postmaster를 확인해야 합니다.뚱딴지

그런 다음 파일의 첫 번째 줄을 보십시오. 이것은 잘못된 PID입니다.

달려.

ps aux | grep <PID>

예:

ps aux | grep 12345

그럼 하시오

kill <PID>

예를들면

kill 12345

아직 실행 중이라고 가정합니다.

https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists

승인된 답변을 듣지 마십시오. 나쁘고 데이터를 손상시킬 수 있습니다!!!

postresql 또는 데이터베이스를 변경하는 중입니다.yml 구성 설정, $PATH 변경 또는 심볼 링크 생성은 모두 저에게 불필요했습니다.내가 해야 할 일은gem uninstall pg그리고 나서.bundle(또는)gem install pg).

문제는 pggem이 홈브루 포스트그레스 이전에 설치되었기 때문에 MacOS와 함께 제공되는 포스트그레스 버전에서 설정을 선택하고 있다는 것입니다.이를 다시 설치하고(따라서 네이티브 확장을 다시 빌드) 문제를 해결했습니다.

데이터베이스가 업그레이드되지 않고 호환되지 않기 때문에 9.3.4에서 9.5로 업그레이드했을 때 이러한 상황이 발생했습니다.

다음과 같이 pg_upgrade를 사용했습니다.

우편물 중지

$ brew services stop postgresql

데이터베이스 업그레이드:

$ pg_upgrade \
   -d /usr/local/var/postgres \
   -D /usr/local/var/postgres9.5 \
   -b /usr/local/Cellar/postgresql/9.3.4/bin/ \
   -B /usr/local/Cellar/postgresql/9.5.0/bin/ \
   -v

이전 데이터베이스 보관:

 $ mv /usr/local/var/postgres /usr/local/var/postgres9.3.save
 $ mv /usr/local/var/postgres9.5 /usr/local/var/postgres

postgres 다시 시작:

 $ brew services start postgresql

업데이트된 보석(레일/액티브 레코드용):

 $ gem uninstall pg
 $ gem uninstall activerecord-postgresql-adapter
 $ bundle install

저는 같은 문제에 직면했습니다.psql (PostgreSQL) 9.6.11.

내게 효과가 있었던 것은-

postmaster를 합니다.pid 거제 --rm /usr/local/var/postgresql@9.6/postmaster.pid

postgres -- postgres 다작시시 --brew services restart postgresql@9.6

이것도 작동하지 않으면 실행합니다.sudo chmod 700 /usr/local/var/postgresql@9.6

Psql 옵션

-h 호스트 이름 --host=hostname

서버가 실행 중인 컴퓨터의 호스트 이름을 지정합니다.값이 슬래시로 시작하면 이 값이 유닉스 도메인 소켓의 디렉터리로 사용됩니다.

$ grep "port\|unix_socket" /etc/postgresql/9.1/main/postgresql.conf
port = 5433                                         # (change requires restart)
unix_socket_directory = '/var/run/postgresql'       # (change requires resta

$ netstat -nalp | grep postgres
unix  2      [ ACC ]     STREAM     LISTENING     106753   4349/postgres       /tmp/.s.PGSQL.5432
unix  2      [ ACC ]     STREAM     LISTENING     10377 1031/postgres       /var/run/postgresql/.s.PGSQL.5433

-host 옵션과 함께 psql 실행

$ psql -p 5433 -h /var/run/postgresql

소프트 링크를 만들 필요가 없음

홈브루를 사용하여 포스트그레스를 설치한 경우 다음을 실행하여 이 문제를 해결할 수 있습니다.

brew link postgres

이것은 저에게 효과가 있었습니다(이전 답변 혼합).

$ rm /usr/local/var/postgres/postmaster.pid

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

출처: https://coderwall.com/p/zf-fww/postgres-on-osx-with-homebrew-not-running-after-osx-crash

그래서 나는 이것을 그 후에 밟았습니다.rails db:create: 10.macOS Catalina 10.15에서 3에서 환경 설정.

제가 가장 먼저 확인한 것은 저를 여기까지 오게 한 흐름이었습니다.모든 것이 순조롭게 진행되고 제 마음에서 벗어날 수 있는 오류가 없음을 확인한 후, 저는 여기서 가장 인기 있는 해결책을 시도했지만, 어떤 것도 효과가 없는 것 같았습니다.

지금까지 제가 본 유일한 오류는

$ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

그래서 저는 무슨 일이 일어나고 있는지에 대한 좀 더 구체적인 정보가 필요했습니다.그런 이유로 저는 다음 위치에 있는 postgres 로그 파일을 보기로 결정했습니다.

/usr/local/var/log/postgres.log

그래서 로그를 연 후에 나는 이 오류를 보았습니다.

LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin19.3.0, compiled by Apple clang version 11.0.0 (clang-1100.0.33.17), 64-bit LOG: could not translate host name "localhost", service "5432" to address: nodename nor servname provided, or not known WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets LOG: database system is shut down

그래서 이것은 좀 더 설명적이고 구체적입니다.문제는 그 포스트그레에 관한 것입니다.SQL은 로컬 호스트 서버를 "확인"하고 확인할 수 없습니다.

그래서 다음으로 제가 한 일은 /etc/hosts 파일의 기본 내용을 다음과 같이 확인하는 것이었습니다.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1          localhost 

위의 내용을 제 것과 비교해 본 결과, 제 것에서 이 선이 다르다는 것을 확인하고 코멘트(!)를 달았습니다.

#::1             localhost

그래서 저는 줄 앞에 있는 # 기호를 제거하고 파일을 저장하고 다시 실행했습니다.

rails db:create 

데이터베이스가 성공적으로 시작되었습니다.

MacOS M1 몬테레이용 솔루션

rm /opt/homebrew/var/postgres/postmaster.pid
brew services restart postgresql

MacOS Sierra에서도 이 문제를 발견했으며 위에서 설명한 대로 pg_ctl을 실행했을 때 다음 오류가 발생했습니다.pg_ctl: no database directory specified and environment variable PGDATA unset그래서 우리는 여기서 우리의 문제를 해결한 단계를 따랐습니다. 즉, 다음과 같습니다.

mkdir ~/.postgres

initdb ~/.postgres

pg_ctl -D ~/.postgres start

코드에서 Postgres의 사용자 이름을 잘못 사용하여 동일한 문제가 발생했습니다.우편물에 로그인했습니다.psql -d postgres를 입력합니다.\du역할 이름을 가져와서 Postgres의 사용자 이름을 수정합니다.

따라서 이 문제가 발생할 경우 올바른 Postgres 사용자 이름, 암호, 호스트 이름 및 데이터베이스를 사용하고 있는지 확인해야 합니다.

이것이 누구에게나 도움이 되기를 바랍니다.

psql을 종료하지 않고 시스템을 종료하면 postgres가 일부 파일을 제거하지 않았을 것입니다.

usr/local/var/postgres 위치에서 postmaster.pid 파일을 찾지 못했습니다.

그래서 저는 다음과 같이 했습니다.

brew 서비스 시작 postgresql

위의 명령을 사용하여 postgres를 시작할 수 있습니다.

다른 프로세스에서 DB에 액세스하는 동안 DB를 복원/드롭/생성하려고 하다가 이 문제가 발생했습니다.MacOSX/홈브루 픽스:

  1. 다른 모든 액세스 프로세스 닫기rails server,rails console,guard기타...
  2. 에서 찾은 명령을 사용하여 로드/다운로드brew info postgres
  3. 이전에서 복원/삭제/생성 실행

FWIW 이런 일이 오늘 저에게 일어났지만, 무슨 일이 일어났는지는 당시 Ubuntu 업데이트를 실행하고 있었고, Postgres를 업데이트하고 있었을 가능성이 높습니다.일단 업데이트가 완료되면, 저는 문제없이 연결할 수 있었습니다.

완전성을 위해 Rails 콘솔에서 데이터베이스에서 레코드를 검색하려고 했습니다.

development (main):0 > a = MyModel.find 73694
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

psql이 실행되지 않는 것 같습니다.연결하기 전에 실행해야 합니다.Mac OS용 Postgres.app만 사용하여 이 작업을 수행할 수 있습니다. (이 앱 다운로드 및 설치 http://postgresapp.com ) 앱을 열면 Postgre가 있습니다.SQL 서버가 준비되고 새 연결을 기다리고 있습니다.앱을 닫으면 서버가 종료됩니다. 정보는 http://www.postgresql.org/download/macosx/ 에서도 확인할 수 있습니다.이것이 당신에게 도움이 되기를 바랍니다.

언급URL : https://stackoverflow.com/questions/13410686/postgres-could-not-connect-to-server

반응형