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

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

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

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

Ruby on Rails

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

Q&A

0回答

597閲覧

PG::ConnectionBad postgresqlに接続できない

BadXO

総合スコア6

PostgreSQL

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

Ruby on Rails

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

0グッド

0クリップ

投稿2019/11/16 03:57

編集2019/11/16 04:05

postgresqlに接続できなくなりました。
dockerでrailsの環境構築をしています。
今までは普通に動いていたのですが、bundle install を行ったのちに、サーバーを停止させて
docker-compose up で再度サーバーを起動させてブラウザにて表示しようとしたら以下のエラーが出ました。

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: Cannot assign requested address Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

色々と調べて以下のコマンドをターミナルで入力して起動確認したら起動しておらず

$ps aux | grep postgres 88316 1.5 0.0 4278296 848 s001 S+ 12:50PM 0:00.01 grep postgres

tail コマンドで postgres が起動された時に作られるファイルの存在を確認しました
postgresqlを起動した時に作成される.pidファイル?が存在していないので起動していないと考えました。

$tail /usr/local/var/postgres/server.log tail: /usr/local/var/postgres/server.log: No such file or directory

関係ありそうなファイルを貼っておきます

Docekrfile

1FROM ruby:2.5 2RUN apt-get update -qq && apt-get install -y nodejs postgresql-client 3RUN mkdir /myapp 4WORKDIR /myapp 5COPY Gemfile /myapp/Gemfile 6COPY Gemfile.lock /myapp/Gemfile.lock 7RUN bundle install 8COPY . /myapp 9 10# Add a script to be executed every time the container starts. 11COPY entrypoint.sh /usr/bin/ 12RUN chmod +x /usr/bin/entrypoint.sh 13ENTRYPOINT ["entrypoint.sh"] 14EXPOSE 3000 15 16# Start the main process. 17CMD ["rails", "server", "-b", "0.0.0.0"] 18

docker-compose.yml

version: '3' services: db: image: postgres ports: - '5432:5432' volumes: - postgresql-data:/var/lib/postgresql/data web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp ports: - "3000:3000" depends_on: - db volumes: postgresql-data: driver: local

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.5.7' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.3' 8# Use postgresql as the database for Active Record 9gem 'pg', '>= 0.18', '< 2.0' 10# Use Puma as the app server 11gem 'puma', '~> 3.11' 12# Use SCSS for stylesheets 13gem 'sass-rails', '~> 5.0' 14# Use Uglifier as compressor for JavaScript assets 15gem 'uglifier', '>= 1.3.0' 16# See https://github.com/rails/execjs#readme for more supported runtimes 17# gem 'mini_racer', platforms: :ruby 18 19# Use CoffeeScript for .coffee assets and views 20gem 'coffee-rails', '~> 4.2' 21# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22gem 'turbolinks', '~> 5' 23# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24gem 'jbuilder', '~> 2.5' 25# Use Redis adapter to run Action Cable in production 26# gem 'redis', '~> 4.0' 27# Use ActiveModel has_secure_password 28# gem 'bcrypt', '~> 3.1.7' 29 30# Use ActiveStorage variant 31# gem 'mini_magick', '~> 4.8' 32 33# Use Capistrano for deployment 34# gem 'capistrano-rails', group: :development 35 36# Reduces boot times through caching; required in config/boot.rb 37gem 'bootsnap', '>= 1.1.0', require: false 38 39group :development, :test do 40 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42end 43 44group :development do 45 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51end 52 53group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59end 60 61# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 62gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 63gem 'bootstrap-sass' 64

Gemfile.lock

Gemfile.lock

1GEM 2 remote: https://rubygems.org/ 3 specs: 4 actioncable (5.2.3) 5 actionpack (= 5.2.3) 6 nio4r (~> 2.0) 7 websocket-driver (>= 0.6.1) 8 actionmailer (5.2.3) 9 actionpack (= 5.2.3) 10 actionview (= 5.2.3) 11 activejob (= 5.2.3) 12 mail (~> 2.5, >= 2.5.4) 13 rails-dom-testing (~> 2.0) 14 actionpack (5.2.3) 15 actionview (= 5.2.3) 16 activesupport (= 5.2.3) 17 rack (~> 2.0) 18 rack-test (>= 0.6.3) 19 rails-dom-testing (~> 2.0) 20 rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 actionview (5.2.3) 22 activesupport (= 5.2.3) 23 builder (~> 3.1) 24 erubi (~> 1.4) 25 rails-dom-testing (~> 2.0) 26 rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 activejob (5.2.3) 28 activesupport (= 5.2.3) 29 globalid (>= 0.3.6) 30 activemodel (5.2.3) 31 activesupport (= 5.2.3) 32 activerecord (5.2.3) 33 activemodel (= 5.2.3) 34 activesupport (= 5.2.3) 35 arel (>= 9.0) 36 activestorage (5.2.3) 37 actionpack (= 5.2.3) 38 activerecord (= 5.2.3) 39 marcel (~> 0.3.1) 40 activesupport (5.2.3) 41 concurrent-ruby (~> 1.0, >= 1.0.2) 42 i18n (>= 0.7, < 2) 43 minitest (~> 5.1) 44 tzinfo (~> 1.1) 45 addressable (2.7.0) 46 public_suffix (>= 2.0.2, < 5.0) 47 archive-zip (0.12.0) 48 io-like (~> 0.3.0) 49 arel (9.0.0) 50 autoprefixer-rails (9.7.1) 51 execjs 52 bindex (0.8.1) 53 bootsnap (1.4.5) 54 msgpack (~> 1.0) 55 bootstrap-sass (3.4.1) 56 autoprefixer-rails (>= 5.2.1) 57 sassc (>= 2.0.0) 58 builder (3.2.3) 59 byebug (11.0.1) 60 capybara (3.29.0) 61 addressable 62 mini_mime (>= 0.1.3) 63 nokogiri (~> 1.8) 64 rack (>= 1.6.0) 65 rack-test (>= 0.6.3) 66 regexp_parser (~> 1.5) 67 xpath (~> 3.2) 68 childprocess (3.0.0) 69 chromedriver-helper (2.1.1) 70 archive-zip (~> 0.10) 71 nokogiri (~> 1.8) 72 coffee-rails (4.2.2) 73 coffee-script (>= 2.2.0) 74 railties (>= 4.0.0) 75 coffee-script (2.4.1) 76 coffee-script-source 77 execjs 78 coffee-script-source (1.12.2) 79 concurrent-ruby (1.1.5) 80 crass (1.0.5) 81 erubi (1.9.0) 82 execjs (2.7.0) 83 ffi (1.11.2) 84 globalid (0.4.2) 85 activesupport (>= 4.2.0) 86 i18n (1.7.0) 87 concurrent-ruby (~> 1.0) 88 io-like (0.3.0) 89 jbuilder (2.9.1) 90 activesupport (>= 4.2.0) 91 listen (3.1.5) 92 rb-fsevent (~> 0.9, >= 0.9.4) 93 rb-inotify (~> 0.9, >= 0.9.7) 94 ruby_dep (~> 1.2) 95 loofah (2.3.1) 96 crass (~> 1.0.2) 97 nokogiri (>= 1.5.9) 98 mail (2.7.1) 99 mini_mime (>= 0.1.1) 100 marcel (0.3.3) 101 mimemagic (~> 0.3.2) 102 method_source (0.9.2) 103 mimemagic (0.3.3) 104 mini_mime (1.0.2) 105 mini_portile2 (2.4.0) 106 minitest (5.13.0) 107 msgpack (1.3.1) 108 nio4r (2.5.2) 109 nokogiri (1.10.5) 110 mini_portile2 (~> 2.4.0) 111 pg (1.1.4) 112 public_suffix (4.0.1) 113 puma (3.12.1) 114 rack (2.0.7) 115 rack-test (1.1.0) 116 rack (>= 1.0, < 3) 117 rails (5.2.3) 118 actioncable (= 5.2.3) 119 actionmailer (= 5.2.3) 120 actionpack (= 5.2.3) 121 actionview (= 5.2.3) 122 activejob (= 5.2.3) 123 activemodel (= 5.2.3) 124 activerecord (= 5.2.3) 125 activestorage (= 5.2.3) 126 activesupport (= 5.2.3) 127 bundler (>= 1.3.0) 128 railties (= 5.2.3) 129 sprockets-rails (>= 2.0.0) 130 rails-dom-testing (2.0.3) 131 activesupport (>= 4.2.0) 132 nokogiri (>= 1.6) 133 rails-html-sanitizer (1.3.0) 134 loofah (~> 2.3) 135 railties (5.2.3) 136 actionpack (= 5.2.3) 137 activesupport (= 5.2.3) 138 method_source 139 rake (>= 0.8.7) 140 thor (>= 0.19.0, < 2.0) 141 rake (13.0.1) 142 rb-fsevent (0.10.3) 143 rb-inotify (0.10.0) 144 ffi (~> 1.0) 145 regexp_parser (1.6.0) 146 ruby_dep (1.5.0) 147 rubyzip (2.0.0) 148 sass (3.7.4) 149 sass-listen (~> 4.0.0) 150 sass-listen (4.0.0) 151 rb-fsevent (~> 0.9, >= 0.9.4) 152 rb-inotify (~> 0.9, >= 0.9.7) 153 sass-rails (5.1.0) 154 railties (>= 5.2.0) 155 sass (~> 3.1) 156 sprockets (>= 2.8, < 4.0) 157 sprockets-rails (>= 2.0, < 4.0) 158 tilt (>= 1.1, < 3) 159 sassc (2.2.1) 160 ffi (~> 1.9) 161 selenium-webdriver (3.142.6) 162 childprocess (>= 0.5, < 4.0) 163 rubyzip (>= 1.2.2) 164 spring (2.1.0) 165 spring-watcher-listen (2.0.1) 166 listen (>= 2.7, < 4.0) 167 spring (>= 1.2, < 3.0) 168 sprockets (3.7.2) 169 concurrent-ruby (~> 1.0) 170 rack (> 1, < 3) 171 sprockets-rails (3.2.1) 172 actionpack (>= 4.0) 173 activesupport (>= 4.0) 174 sprockets (>= 3.0.0) 175 thor (0.20.3) 176 thread_safe (0.3.6) 177 tilt (2.0.10) 178 turbolinks (5.2.1) 179 turbolinks-source (~> 5.2) 180 turbolinks-source (5.2.0) 181 tzinfo (1.2.5) 182 thread_safe (~> 0.1) 183 uglifier (4.2.0) 184 execjs (>= 0.3.0, < 3) 185 web-console (3.7.0) 186 actionview (>= 5.0) 187 activemodel (>= 5.0) 188 bindex (>= 0.4.0) 189 railties (>= 5.0) 190 websocket-driver (0.7.1) 191 websocket-extensions (>= 0.1.0) 192 websocket-extensions (0.1.4) 193 xpath (3.2.0) 194 nokogiri (~> 1.8) 195 196PLATFORMS 197 ruby 198 199DEPENDENCIES 200 bootsnap (>= 1.1.0) 201 bootstrap-sass 202 byebug 203 capybara (>= 2.15) 204 chromedriver-helper 205 coffee-rails (~> 4.2) 206 jbuilder (~> 2.5) 207 listen (>= 3.0.5, < 3.2) 208 pg (>= 0.18, < 2.0) 209 puma (~> 3.11) 210 rails (~> 5.2.3) 211 sass-rails (~> 5.0) 212 selenium-webdriver 213 spring 214 spring-watcher-listen (~> 2.0.0) 215 turbolinks (~> 5) 216 tzinfo-data 217 uglifier (>= 1.3.0) 218 web-console (>= 3.3.0) 219 220RUBY VERSION 221 ruby 2.5.7p206 222 223BUNDLED WITH 224 1.17.3 225

どのような問題でどうすれば解決できるのでしょうか?
曖昧な質問ですが回答頂けるとありがたいです。
よろしくお願い致します。

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問