1.起こったこと
久しぶりに postgresql を使おうとした下記のエラーが起こった。
1 | psql: error: could not connect to server: No such file or director |
正直1年ぶりに使うためどういう経緯でこうなったのかは見当がつきませんでしたが、postgresql を使いたかったためこのエラーの解決に努めました。
2.試したこと
postgresql の再起動
1 2 3 4 | brew services restart postgresql ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql) ==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql) |
起動自体は問題なくできるらしい。
3.解決方法
postgresql の再インストール
1 2 3 4 5 6 7 8 9 10 11 | brew install postgresql ==> Error: homebrew-core is a shallow clone. To `brew update`, first run: git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow This restriction has been made on GitHub's request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you automatically to avoid repeatedly performing an expensive unshallow operation in CI systems (which should instead be fixed to not use shallow clones). Sorry for the inconvenience! |
homebrew に関するエラーが出たのでまずはそちらを対処した。
と言っても、指示されたコマンドを打ち込んだだけ。
1 2 3 4 5 6 7 8 9 | <strong>git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow </strong> ==>remote: Enumerating objects: 861095, done. remote: Counting objects: 100% (861048/861048), done. remote: Compressing objects: 100% (280872/280872), done. remote: Total 851405 (delta 580330), reused 838590 (delta 567644), pack-reused 0 Receiving objects: 100% (851405/851405), 332.88 MiB | 9.11 MiB/s, done. Resolving deltas: 100% (580330/580330), completed with 7989 local objects. From https://github.com/Homebrew/homebrew-core 435c28688d3..34b76a8807c master -> origin/master |
その後、
1 | brew install postgresql |
で再インストールすることができた。
1 2 3 4 | psql ==>psql: error: 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"? |
でも問題のエラーは終わらなかった。
クラスタの作成
再インストールしたのでクラスタをつくなければいけないのでは?と考え、クラスタを作った。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | initdb /usr/local/var/postgres ==>The files belonging to this database system will be owned by user "ユーザ名". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". The default database encoding has accordingly been set to "UTF8". 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: error: 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". |
「/usr/local/var/postgres は既に存在する、もしくは空じゃない」
といわれたので、再インストール前に作った usr/local/var/postgres をとりあえず削除….は怖いので usr/local/var/postgres_1 としてとりあえず名前を変えて保管。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | initdb /usr/local/var/postgres ==> The files belonging to this database system will be owned by user "Pillow545". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". The default database encoding has accordingly been set to "UTF8". 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. creating directory /usr/local/var/postgres ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Tokyo creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: pg_ctl -D /usr/local/var/postgres -l logfile start |
warning が少し気になるけどうまくいったぽいので、再接続
1 2 3 | brew services restart postgresql ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql) ==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql) |
接続もうまくいったので psql を使ってみる。
1 2 | psql -l ==> データベース一覧 |
うまくいったみたい。
よきよき。
|
ABOUT ME