環境:postgresql-10
$ bin/rails db:create をしたら下記のエラーがでました
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
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"?
Couldn't create 'scaffold_app1_development' database. Please check your configuration.
rails aborted!
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"?
/home/shunsuke/scaffold_app1/bin/rails:9:in <top (required)>'
'
/home/shunsuke/scaffold_app1/bin/spring:15:in
bin/rails:3:in load'
'
bin/rails:3:in
Tasks: TOP => db:create
(See full trace by running task with --trace)
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
参考にしたサイト
https://teratail.com/questions/47554
試したこと
ポート番号5432で受け付けていますか?とエラーで書いてあるので
$service postgresql start で再度サーバーを動かしておなじコマンドを打ってみても変化なし
解決方法
動いているPostgresqlの受け付けているポート番号を確認してみる
$sudo pg_lsclustersで確認したら
10 main 5433 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
と表示され5433で受け付けているのでconfig/database.ymlにポート番号を記述した↓
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
port: 5433 #ここにportを記述しました
そしてbin/rails db:createしたら
WARNING: could not flush dirty data: Function not implemented
Created database 'scaffold_app1_development'
WARNING: could not flush dirty data: Function not implemented
Created database 'scaffold_app1_test'
警告メッセージは出たものの何とか作ることができました!
bin/rails sで無事動いたのでとりあえず解決ということで...
おまけ?
関係ないと思い書いていないですがポート番号を追加したときに同時にした対策を書きます
何かのサイト?を見たときに書いてあった対策
下記のコマンドでpostgresql.confを開く
sudo vi /etc/postgresql/10/main/postgresql.conf
その中の#fsync=onのコメントを外しfsync=offします
その下にdata_sync_retry = trueを追加しました↓
fsync = off # flush data to disk for crash safety
data_sync_retry = true # (turning this off can cause
これは効果あったのかわからないですが一応...
これはなにしているのかよくわからない。。。