[ruby-on-rails] Postgres가 서버에 연결할 수 없습니다

업데이트 및 양조 업그레이드를 수행 한 후 postgres에 문제가 발생했습니다. postgres를 제거하고 다시 설치하려고했지만 작동하지 않았습니다.

이것은 오류 메시지입니다. (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"?

어떻게 해결할 수 있습니까?

맥 버전 : 산 사자.

사제 버전 : 0.9.3

postgres 버전 : psql (PostgreSQL) 9.2.1

그리고 이것이 내가 한 일입니다.

12:30 ~/D/works$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.2.1...
12:31 ~/D/works$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.1.4...
12:31 ~/D/works$ psql --version
bash: /usr/local/bin/psql: No such file or directory
12:33 ~/D/works$ 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
12:37 ~/D/works$ 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".
12:39 ~/D/works$ mkdir -p ~/Library/LaunchAgents
12:39 ~/D/works$   cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
12:39 ~/D/works$   launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
homebrew.mxcl.postgresql: Already loaded
12:39 ~/D/works$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
12:39 ~/D/works$ 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
12:42 ~/D/works$ psql --version
psql (PostgreSQL) 9.2.1
12:42 ~/D/works$ 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"?

이제 howbrew를 다시 설치 한 후을 사용할 때 $ 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 파일이 postgres의 시작을 차단하고있었습니다. 그것을 해결하기 위해:

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

그리고 모든 것이 잘됩니다.


답변

이것은 때때로 postgres 업그레이드에서 문제가 될 수 있습니다.

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

보다 http://www.postgresql.org/docs/9.4/static/upgrading.html을 하십시오

OS X / 홈 브루 :

달리기 postgres -D /usr/local/var/postgres – 포스트 그레스가 시작되지 않으면 그것은 당신에게 훨씬 더 자세한 출력을 제공 할 것입니다.

내 경우에는 rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8 이전 데이터베이스가 제거되고 postgres db 스키마가 다시 초기화되었습니다.

해당 솔루션에 대한 https://github.com/Homebrew/homebrew/issues/35240 에게 감사합니다 .

로 데이터베이스를 재생성 한 후 rake db:create모든 것이 잘 작동했습니다.


답변

나를 위해 일한 해결책을 찾았습니다.

/dba/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

출처


답변

Yosemite에서 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: localhostdatabase.yml에 필요할 수 있습니다. http://postgresapp.com/documentation#toc_3


답변

데이터베이스 업그레이드가 저에게 효과적입니다


brew postgresql-upgrade-database