Programing

PG :: ConnectionBad-서버에 연결할 수 없습니다 : 연결이 거부되었습니다

lottogame 2020. 4. 6. 07:57
반응형

PG :: ConnectionBad-서버에 연결할 수 없습니다 : 연결이 거부되었습니다


Rails 4.0 서버를 실행할 때마다이 결과가 나옵니다.

Started GET "/" for 127.0.0.1 at 2013-11-06 23:56:36 -0500

PG::ConnectionBad - could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
:
 activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `connect'
 activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:542:in `initialize'
 activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
 activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
 activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
 activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
 activerecord (4.0.0) lib/active_record/migration.rb:792:in `current_version'
 activerecord (4.0.0) lib/active_record/migration.rb:800:in `needs_migration?'
 activerecord (4.0.0) lib/active_record/migration.rb:379:in `check_pending!'
 activerecord (4.0.0) lib/active_record/migration.rb:366:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
 activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1613334440513032208__call__callbacks'
 activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
 actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
 better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
 better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
 better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
 railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
 railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
 activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
 activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
 activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
 railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
 quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
 actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
 rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
 rack (1.5.2) lib/rack/runtime.rb:17:in `call'
 activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
 rack (1.5.2) lib/rack/lock.rb:17:in `call'
 actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
 railties (4.0.0) lib/rails/engine.rb:511:in `call'
 railties (4.0.0) lib/rails/application.rb:97:in `call'
 rack (1.5.2) lib/rack/content_length.rb:14:in `call'
 thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process'
 thin (1.5.1) lib/thin/connection.rb:79:in `pre_process'
 thin (1.5.1) lib/thin/connection.rb:54:in `process'
 thin (1.5.1) lib/thin/connection.rb:39:in `receive_data'
 eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
 thin (1.5.1) lib/thin/backends/base.rb:63:in `start'
 thin (1.5.1) lib/thin/server.rb:159:in `start'
 rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
 rack (1.5.2) lib/rack/server.rb:264:in `start'
 railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
 railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
 railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
 bin/rails:4:in `<main>'

Mavericks OS X 10.9를 실행 중이므로 문제가 있는지 모르겠습니다. 나는 가능한 모든 것을 시도했지만 아무것도 효과가없는 것 같습니다. postgres와 pg gem을 여러 번 제거하고 설치했습니다.

이것은 내 database.yml 파일입니다

development:
  adapter: postgresql
  encoding: unicode
  database: metals-directory_development
  pool: 5
  username: 
  password: 
  template: template0
  host: localhost
  port: 5432

test: &test
  adapter: postgresql
  encoding: unicode
  database: metals-directory_test
  pool: 5
  username: 
  password: 
  template: template0
  host: localhost
  port: 5432

staging:
  adapter: postgresql
  encoding: unicode
  database: metals-directory_production
  pool: 5
  username:
  password:
  template: template0
  host: localhost

production:
  adapter: postgresql
  encoding: unicode
  database: metals-directory_production
  pool: 5
  username:
  password:
  template: template0
  host: localhost

cucumber:
  <<: *test

오래된 PID 파일 처럼 간단 할 수 있습니다 . 컴퓨터가 종료 프로세스를 완전히 완료하지 않아서 자동으로 실패 할 수 있습니다. 이는 postgresPID (프로세스 ID) 파일을 삭제하지 않았 음 을 의미 합니다.

postgres는 PID 파일을 사용하여 한 번에 하나의 서버 인스턴스 만 실행되도록합니다. 따라서 다시 시작 하면 서버의 다른 인스턴스가 시작되었음을 postgres알려주 PID 파일 이 이미 있기 때문에 실패합니다 (실행 중이 아니더라도 PID를 종료하고 삭제하지 못했습니다) .

  1. 이를 해결하려면 PID 파일을 제거 / 이름 바꾸기하십시오. postgres 데이터 디렉토리를 찾으십시오. homebrew를 사용하는 MAC /usr/local/var/postgres/에서는 다른 시스템 일 수도 있습니다 /usr/var/postgres/.
  2. 이것이 문제인지 확인하려면 로그 파일 ( server.log)을보십시오. 마지막 줄에는 다음이 표시됩니다.

치명적 : 잠금 파일 "postmaster.pid"가 이미 있습니다.
힌트 : 데이터 디렉토리 "/ usr / local / var / postgres"에서 다른 포스트 마스터 (PID 347)가 실행되고 있습니까?

  1. 그렇다면, rm postmaster.pid
  2. 서버를 다시 시작하십시오. launchctl (homebrew 포함)을 사용하는 Mac에서 다음 명령은 서버를 다시 시작합니다.

    launchctl unload homebrew.mxcl.postgresql.plist  
    launchctl load -w homebrew.mxcl.postgresql.plist
    

    또는 최신 버전의 Brew

    brew services restart postgresql
    

많은 검색 및 분석 후 우분투를 사용하는 경우 터미널 에서이 명령을 작성하고 Enter 키를 누르면 해결책을 찾았습니다.

sudo service postgresql restart

PostgreSQL이 다시 시작됩니다. 이것이 도움이 되길 바랍니다.


이 문제는 postgres가 제대로 종료되지 않은 경우에 발생합니다. 다음은 간단한 3 단계로이 문제를 해결 한 방법입니다.

1 단계 : postgres 디렉토리로 이동

Mac 사용자 는이 부분을 찾을 /usr/local/var/postgres수 있습니다 /usr/var/postgres/.

2 단계 :.pid 이 명령을 실행하여 파일을 제거하십시오 .

rm postmaster.pid

3 단계 : 서버 다시 시작

맥 사용자

brew services restart postgresql

리눅스 사용자

sudo service postgresql restart

마지막으로 앱을 다시 시작하면 좋습니다.


Chris Slade의 답변에 따라 문제를 해결했지만 서버를 다시 시작하려면 다음 명령을 사용해야했습니다.

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

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

내가 여기 에서 찾은 (바닥에 pjammer의 대답)


시스템 내에 postgresql이 설치되어 있습니까? 그렇지 않은 경우 Install postgresql을보십시오 . postgresql 을 시스템에 성공적으로 통합 한 후 시스템 터미널에 다음과 같이 입력 할 수 있습니다.

which psql
#=> /usr/bin/psql

그런 다음 postgresql에서 다음과 같이 사용자 및 데이터베이스를 작성해야합니다.

sudo su - postgres
psql

그러면 터미널 내에서 다음을 볼 수 있습니다

postgres=#

거기에 입력하십시오 :

CREATE USER yourname WITH PASSWORD 'passwordhere';
CREATE DATABASE metals-directory_production  WITH OWNER yourname;
GRANT ALL PRIVILEGES ON DATABASE metals-directory_production TO yourname;

이 작업을 수행 한 후을 수정해야합니다 database.yml. 아마도 다음과 같은 것이 필요할 것입니다.

development:
  adapter: postgresql
  encoding: unicode
  database: metals-directory_development
  pool: 5
  username: yourname
  password: passwordhere   ### password you have specified within psql
  host: localhost
  port: 5432               ### you can configure it in file postgresql.conf

또한 postgresql에 문제가 있다면 pg_hba.conf 를 확인하는 것이 좋습니다


Postgres에서 이러한 유형의 문제 를 해결하고 Postgres on Mac OSX에서 작업 하려면 지금까지 내가 찾은 BESTEASIEST 솔루션 일 것입니다.

http://postgresapp.com/

그냥 다운로드, 설치 및 행복 :)


  1. pg 제거 :

    gem uninstall pg
  2. postgres 제거 :

    brew uninstall postgres
  3. 많은 오래된 파일로 남아있을 수있는 postgres 폴더를 Nuke하십시오.

    rm -rf /usr/local/var/postgres
  4. 재부팅 (불필요 할 수 있음)

  5. pg 재설치 :

    brew install postgres
  6. Chris Slade의 답변에 대한 나의 의견은 어려운 방법으로 시작됩니다. 이제 양조 서비스를 사용하여 인생을 여러 가지 방법으로 단순화했습니다.

    brew install services
  7. 그리고 그것으로 pg를 시작하십시오 :

    brew services start postgresql
  8. 보석을 다시 설치하십시오 :

    gem install pg

그리고 bobsyouruncle.


파일 확인 postgresql.conf의 (에 ubuntu/etc/postgresql/XX/main/postgresql.conf 말한다 라인) 및보고 :

listen_addresses="localhost"

그것을 다음과 같이 변경하십시오 :

listen_addresses="*"

모든 IP를 수락하고 다음 줄을 확인하십시오.

port=5432

그리고 postgresql-9.2에서 기본적으로 5433 대신 5432를 사용 하는 postgres 서버 다시 시작 하는 것을 잊지 마십시오 .

행운을 빕니다!


@Magne에서 설명했듯이 PostgreSQL PG::ConnectionBad - could not connect to server: Connection refused주 / 부 버전 업그레이드 (예 : 9.5 -> 9.6또는 9 -> 10) 후에 오류가 발생할 수 있습니다 .

brew upgrade postgresqlPostgreSQL 버전 9.6 출시 후 실행 한 후이 오류가 발생했습니다 . 문제는 주 / 부 버전 업그레이드시 이전 날짜를 새 버전으로 마이그레이션하기 위해 추가 단계가 필요하다는 것입니다.

이것이 당신의 문제인지 확인하는 방법

homebrew와 함께 설치된 최신 BREW 공식 PostgreSQL 버전을 확인하여 이것이 문제인지 확인할 수 있습니다.

$ brew info postgresql

/usr/local/Cellar/postgresql/9.5.4_1 (3,147 files, 35M)
Poured from bottle on 2016-10-14 at 13:33:28
/usr/local/Cellar/postgresql/9.6.1 (3,242 files, 36.4M) *
Poured from bottle on 2017-02-06 at 12:41:00

... 그리고 현재 PG_VERSION과 비교

$ cat /usr/local/var/postgres/PG_VERSION
9.5

PG_VERSION이 최신 추출 공식보다 작고 차이가 주요 / 부 버전 변경 인 경우 이는 아마도 문제 일 수 있습니다.

수정 방법 (예 : 데이터 업그레이드 방법)

아래 지침은 9.5에서 9.6으로 업그레이드하기위한 것입니다. 자신의 업그레이드에 맞게 버전 번호를 변경하십시오.

단계 1. PostgreSQL이 꺼져 있는지 확인하십시오 :

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# or, with Homebrew...
$ brew services stop postgresql

2 단계. 새로운 원시 데이터베이스를 만듭니다.

$ initdb /usr/local/var/postgres9.6 -E utf8

3 단계 . 이전 및 새 이진 버전이 무엇인지 확인합니다.

$ ls /usr/local/Cellar/postgresql/
9.5.3   9.5.4   9.6.1

이 예제에서는 9.5.4 바이너리에서 9.6.1 바이너리로 업그레이드하고 있습니다.

단계 4. pg_upgrade 유틸리티를사용하여 현재 데이터를 새 데이터베이스로 마이그레이션하십시오.

$ pg_upgrade \
  -d /usr/local/var/postgres \
  -D /usr/local/var/postgres9.6 \
  -b /usr/local/Cellar/postgresql/9.5.4/bin/ \
  -B /usr/local/Cellar/postgresql/9.6.1/bin/ \
  -v
  • -d 플래그는 현재 데이터 디렉토리를 지정합니다
  • -D flag는 작성할 새 데이터 디렉토리를 지정합니다
  • -b 이전 바이너리를 지정합니다
  • -B 업그레이드 할 새로운 바이너리를 지정합니다

5 단계. 이전 데이터 디렉토리를 다른 곳으로 이동

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

6 단계. 새로 생성 된 데이터 디렉토리를 PostgreSQL이 예상하는 위치로 이동

$ mv /usr/local/var/postgres9.6 /usr/local/var/postgres

7 단계. PostgreSQL을 다시 시작하십시오.

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# or, if you're running a current version of Homebrew
$ brew services start postgresql

8 단계. Rails에 pg gem을 사용하는 경우 gem을 제거하고 다시 설치하여 다시 컴파일해야합니다 (pg gem을 사용하지 않는 경우이 단계 생략)

$ gem uninstall pg
$ gem install pg

단계 9. (선택 사항) 모든 것이 제대로 작동한다고 확신 한 후 다음 명령을 사용하여 디스크 공간을 다시 확보 할 수 있습니다.

brew cleanup postgresql

... 정말 용감하다고 생각되면 다음 명령으로 이전 PostgreSQL 데이터 디렉토리를 삭제할 수 있습니다

rm -rf /usr/local/var/postgres9.5/

(이 답변은 훌륭한 블로그 게시물 https://keita.blog/2016/01/09/homebrew-and-postgresql-9-5/기반으로 함 )


이것이 정말 도움이되었습니다.

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

참조 : http://alumni.lewagon.org/questions/60


위에서 제안했듯이 방금 Mac 에서 Postgres 앱 을 열고 열기를 클릭 Psql하고 psql창을 닫은 다음 터미널에서 레일 서버다시 시작 하면 더 이상 오류가 발생하지 않습니다.

코끼리를 믿으십시오 : http://postgresapp.com/


당신이 수행 한 후이 문제를 공격하는 경우 brew upgrade(f.ex 새로운 주요 버전으로 업그레이드 포스트 그레스를 9.3.09.4.0이상), 다음을 수행하십시오

https://github.com/Homebrew/homebrew/issues/35240 에서 @dmitrygusev의 수정

다음 공식 [Postgresql] 마이그레이션 가이드가 도움이되었습니다.

brew switch postgres 9.3.5    # presuming you already installed 9.4.1
pg_dumpall > outputfile
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres.old
brew switch postgres 9.4.1
initdb -D /usr/local/var/postgres
psql -d postgres -f outputfile

그게 다야. 가져 오기가 제대로되었는지 확인한 후 백업을 삭제하십시오.

rm outputfile
rm -Rf /usr/local/var/postgres.old

여기서 문제는 postgres의 주요 버전 업그레이드시 데이터베이스를 다시 작성 / 마이그레이션해야한다는 것입니다. 그리고 아마도 chown디렉토리 또는 수동으로 호출 initdb합니다.

참고 : 데이터 손실없이 PostgreSQL을 버전 9.5에서 버전 9.6으로 업그레이드하는 방법?


Homebrew를 사용하지 않는 경우 유용한 몇 가지 팁이 있습니다.

PG 서버를 수동으로 중지하는 방법 :

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

PG 서버를 수동으로 시작하는 방법 :

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


Osx Movaje에서 Mac을 업데이트 한 후에도 같은 문제가 발생했습니다.

이 솔루션을 찾았습니다.

먼저 터미널에서 다음 명령 행을 시도하십시오.

brew services restart postgresql

아무것도 바뀌지 않으면 :

ps aux | grep postgres

여전히 아무것도 바뀌지 않으면 :

ls -ls | grep post

마지막 수정 명령은 root에서 실행하여 postgres 잠금 파일을 제거했습니다.

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

그리고 :

brew services restart postgresql

berziiii에서 : https://github.com/ga-wdi-boston/capstone-project/issues/325

희망이 도움이 될 것입니다 :)

감사합니다 !!


당신의 포스트 그레스 파일이있을 수 있습니다 찾아 /usr/local/var/postgres/나에 /usr/var/postgres/후 삭제 postmaster.pid해당 폴더의 파일에 존재합니다.


넣어 host: localhost에서 database.yml파일이 명령을 실행합니다 :

rake db:create db:migrate  

분명히 @Chris Slade의 대답이었습니다.

유용한 경우 나머지 프로세스를 죽이는 작은 스크립트를 작성했습니다.

kill_postgres() {
  if [[ $* -eq "" ]]; then
    echo "Usage: 'kill_postgres <db_name>' to kill remaining instances (Eg. 'kill_postgres my_app_development')"
  else
    gksudo echo "Granted sudo"
    pids="$(ps xa | grep postgres | grep $* | awk '{print $1}' | xargs)"
    if [[ $pids -eq "" ]]; then
      echo "Nothing to kill"
    else
      for pid in "${pids[@]}"
      do
        echo "Killing ${pid}"
        sudo kill $pid
        echo "Killed ${pid}"
      done
      kill_postgres $*
    fi
  fi
}

프로덕션에서 동일한 문제가 발생했습니다 (모든 것이 제대로 작동했습니다). 제 경우에는 DB 서버가 앱과 동일한 시스템에 있지 않으므로 마지막으로 다음과 같이 작성하여 마이그레이션하면됩니다.

bundle exec rake db:migrate RAILS_ENV=production

그런 다음 서버를 다시 시작하면 모든 것이 작동했습니다.


나는 이것이 늦었지만 누군가를 도울 수 있음을 알고 있습니다. 나는 같은 문제를 겪고 있었다. postgres 9.1과 9.5의 두 가지 버전이 있음이 밝혀졌습니다. 9.1과 9.5를 제거하고 9.5를 다시 설치했는데 나에게 도움이되었습니다.


컴퓨터를 다시 시작한 후 Postgres 앱 실행을 잊었을 수 있습니다.


나는 같은 문제가 있었다. 에서 PostgreSQL로그 파일 의 마지막 줄을 확인합니다 /var/log/postgresql. /etc/postgresql/9.5/main/postgresql.conf 파일에 인식 할 수없는 구성 매개 변수가 있습니다 . 오류 줄을 주석 처리하면 postgresql.conf문제가 해결되었습니다.


내 문제는 내 application.yml 파일에있었습니다. 내 데이터베이스 url에 대한 heroku귀하의 확인 포트 5342.을 사용하지 않았다 heroku설정을 var DATABASE_URL. 해당 데이터베이스 application.yml정확히 일치하는지 확인하십시오 .


나는 같은 문제가 있었고,이 설명은 나를 위해 그것을 해결했다 : http://blog.55minutes.com/2013/09/postgresql-93-brew-upgrade/

핵심 단계는 내 /usr/local/var/postgres/server.log 의 꼬리 부분 을 살펴 보았습니다. 실제 문제가 무엇인지 알 수 있었으므로 PostgreSQL 업그레이드 프로세스를 완전히 완료하지 못했습니다.


방금이 명령을 실행하면 sudo service postgresql restart모든 것이 다시 작동했습니다.


Postgres 앱을 사용하는 Mac 사용자는 응용 프로그램을 열 수 있습니다 (스포트라이트 검색 Postgres 또는 메뉴 표시 줄에서 코끼리 아이콘 찾기). "Stale postmaster.pid file"메시지와 함께 빨간색 X가 표시 될 수 있습니다. 불행히도 스포트라이트 검색은이 파일의 위치를 ​​보여주지 않습니다. "서버 설정 ..."을 클릭하고 열리는 대화 상자에서 "표시"버튼을 클릭하여 데이터 디렉토리를 엽니 다. 하나의 폴더를 탐색하고 ( "var-10") postmaster.pid파일을 삭제 하십시오.

Postgres 앱으로 돌아가서 시작 버튼을 클릭하십시오. 빨간색 X가 "실행 중"메시지와 함께 녹색 확인 표시로 바뀌어야합니다. 이제 rails server터미널 에서처럼 Rails 명령을 성공적으로 실행할 수 있습니다 .

Postgres 앱 서버 설정-데이터 디렉토리 표시


나는 오늘 밤 에이 문제를 겪어 왔으며 잠시 동안 일해 온 레일 응용 프로그램에서 작업했습니다. 내 문제는 단순히 내 postgresql 서버가 실행되고 있지 않다는 사실에 달려 있습니다.

화면 상단으로 이동하여 (Mac에 있습니다) 작은 코끼리 아이콘을 클릭하고 '시작'을 클릭했습니다.

서버가 켜지지 않은 상태로 만듭니다.

바라건대 이것은 누군가에게 간단한 해결책을 제공하기를 바랍니다.


나는 rails 서버를 멈추고 실행 rake db:migrate하고 시작했다 rails s.


brew upgradepostgresql이 업데이트 된 후에이 오류가 발생했습니다 . 이 위대한 게시물에서 내 문제를 해결하는 방법을 정확하게 발견했습니다. postgres를 백업 및 실행하고 기존의 모든 데이터베이스로 마이그레이션 할 수도있었습니다. https://coderwall.com/p/ti4amw/how-to-launch-postgresql-after-upgrade


방금이 문제가 있었고 제안 된 해결책 중 어느 것도 나를 위해 일하지 않았습니다. 많은 인터넷 검색 후 해결책을 찾았습니다. 이것이 나를 위해 일한 것입니다.

먼저, 서버를 시작하기 위해이 명령을 실행해야했고 설정 파일의 위치를 ​​설정 한 것 같습니다.

pg_ctl -D /usr/local/var/postgres start && brew services start postgresql

그런 다음 postgres에 액세스하기 위해이 명령을 실행했습니다.

psql postgres

그리고 postgres 프롬프트에서 "\ du"를 입력하여 역할을 나열했습니다.

postgres=# \du

postgres 역할이 없어서이 명령으로 역할을 만들어야했습니다

CREATE ROLE POSTGRES WITH SUPERUSER CREATEDB CREATEUSER CREATEROLE REPLICATION BYPASSRLS ;

그것은 내 문제를 해결했고 이것이 다른 누군가를 돕기를 바랍니다.


postmaster.pid데이터가 손상 될 수 있으므로 파일 을 삭제할 필요가 없습니다 .

선택권? 단순히 kill프로세스 (를 사용하지 말고 kill -9일반적인 킬만하십시오).

그런 다음 postgres 서버를 다시 시작하면 좋습니다.

이를 달성하기위한 단계는 다음과 같습니다.

  1. postmaster.pid파일을 찾아서 엽니 다 (맥 시에라에 있음)

    vi ~/Library/Application\ Support/Postgres/var-10/postmaster.pid

  2. PID를 복사하십시오- postmaster.pid파일 의 첫 번째 줄에있는 숫자입니다

  3. kill PID예를 들어 PID가 381이면 프로세스를 종료하십시오 .kill 381
  4. Postres 다시 시작-brew를 사용하는 경우 수행하십시오 brew services start postgresql. 또는 postgresapp를 사용하는 경우 start버튼을 클릭하기 만하면됩니다.

Homebrew 패키지 관리자에는 자동으로 시작되는 launchctl plist가 포함되어 있습니다. 자세한 정보는 다음을 실행하십시오 brew info postgres.

수동으로 시작하십시오.

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

수동으로 중지하십시오.

pg_ctl -D /usr/local/var/postgres stop

자동 시작 :

"postgresql을 시작하고 로그인시 다시 시작하려면 :"

brew services start postgresql

참고 URL : https://stackoverflow.com/questions/19828385/pgconnectionbad-could-not-connect-to-server-connection-refused

반응형