質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

6411閲覧

postgresqlが繋がらなくなりました.PG::ConnectionBad: could not connect to server: Connection refused

mikan1110

総合スコア15

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

1グッド

0クリップ

投稿2016/06/20 07:54

編集2016/06/20 08:58

昨日までは何事もなくこのアプリケーションにアクセスできていましたが、急にエラーが出るようになりました。
すでに自分でも検索しながら4hほど奮闘しているのですが改善の兆しが見えません。参考にしたURL->
http://stackoverflow.com/questions/19828385/pgconnectionbad-could-not-connect-to-server-connection-refused

そして検索しながら気になる点が2点見つかりました。

  1. postmaster.pidを消す -> しかしpostmaster.pidが見つかりません..
  2. 自分だけディレクトリの場所がおかしい気がする..
  3. server.logを確認したいが方法がわかりません..
$ bundle exec rails db:create WARNING: Nokogiri was built against LibXML version 2.9.4, but has dynamically loaded 2.9.2 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? Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "username"=>"user", "password"=>"****", "host"=>"localhost", "port"=>5432, "database"=>sample_development"} rails aborted! 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? /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `initialize' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `new' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `connect' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:765:in `checkout_new_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:744:in `try_to_checkout_new_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:705:in `acquire_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:501:in `checkout' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:877:in `retrieve_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_handling.rb:128:in `retrieve_connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_handling.rb:91:in `connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/postgresql_database_tasks.rb:6:in `connection' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:109:in `create' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:129:in `block in create_current' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:292:in `block in each_current_configuration' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:291:in `each' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:291:in `each_current_configuration' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:128:in `create_current' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/railties/databases.rake:27:in `block (2 levels) in <top (required)>' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.rc1/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.rc1/lib/rails/commands/rake_proxy.rb:10:in `run_rake_task' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.rc1/lib/rails/commands/commands_tasks.rb:51:in `run_command!' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.rc1/lib/rails/commands.rb:18:in `<top (required)>' /Users/ponta/sample/bin/rails:9:in `require' /Users/ponta/sample/bin/rails:9:in `<top (required)>' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load' /Users/ponta/.rvm/gems/ruby-2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>' /Users/ponta/sample/bin/spring:13:in `require' /Users/ponta/sample/bin/spring:13:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace)
default: &default adapter: postgresql encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: user password: '******' host: localhost port: 5432 development: <<: *default database: sample_development test: <<: *default database:sample_test production: <<: *default database: sample_production username: sample password: <%= ENV[SAMPLE_DATABASE_PASSWORD'] %>
$ which psql /usr/local/bin/psql
$ which postgres /usr/local/bin/postgres
$ 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"?
/usr/local/var/postgres/server.log postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": No such file or directory =>postgresql.logを手動で作成しました。 作成した後のログ => LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf" FATAL: data directory "/usr/local/var/postgres" has wrong ownership HINT: The server must be started by the user that owns the data directory.
$ initdb /usr/local/var/postgres -E utf8 The files belonging to this database system will be owned by user "ponta". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. 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".

拙い質問となってしまい申し訳ありません、わかる方いましたらお手数ですが教えてくださいませ。

退会済みユーザー👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

/usr/local/var/postgresを消去し、
$ initdb /usr/local/var/postgres -E utf8
$ rake db:createで治りました!

投稿2016/06/20 09:04

mikan1110

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問