macOS で PostgreSQL が動かない様です。

```

    $ brew services list 
    Name       Status  User         Plist
    mysql      stopped 
    postgresql error user /Users/user/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    
```

因みに `psql -l` で PostgreSQL に接続できず、データベース一覧が取得できることを確認できません。

```

    $ psql -l
    psql: error: could not connect to server: 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"?
    
```

類似質問もない様ですし、ググってもそれらしいものが見当たりません。

ヒントを下さると幸いです。

**追加作業**

```

    $ brew services start postgresql 
    ==> Successfully started postgresql (label: homebrew.mxcl.postgresql) 
    
    $ brew services list 
    Name Status User Plist
    mysql stopped
    postgresql error XXXXXXX/Users/XXXXXXX/Library/LaunchAgents/homebrew.mxcl.postgresql.plist　
    
    postgres -D /usr/local/var/log/postgres.log 
    postgres: could not access the server configuration file "/usr/local/var/log/postgres.log/postgresql.conf": Not a directory 
    
    postgres -D /usr/local/var/postgres 
    postgres: could not access the server configuration file "/usr/local/var/postgres/postgresql.conf": No such file or directory 
    
```

```

    $ pg_ctl -l /usr/local/var/postgres/server.log start
    pg_ctl: no database directory specified and environment variable PGDATA unset Try "pg_ctl --help" for more information.
    
```

ログを確認

```

    $ less /usr/local/var/log/postgres.log
    
    it
    2021-02-10 08:05:11.179 JST [615] LOG:  listening on IPv6 address "::1", port 54
    32
    2021-02-10 08:05:11.179 JST [615] LOG:  listening on IPv4 address "127.0.0.1", port 5432
    2021-02-10 08:05:11.224 JST [615] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
    2021-02-10 08:05:11.921 JST [711] LOG:  database system was shut down at 2021-02-09 19:40:12 JST
    2021-02-10 08:05:12.030 JST [615] LOG:  database system is ready to accept connections
    2021-02-10 08:34:50.887 JST [615] LOG:  received smart shutdown request
    2021-02-10 08:34:50.966 JST [615] LOG:  background worker "logical replication launcher" (PID 718) exited with exit code 1
    2021-02-10 08:34:50.982 JST [713] LOG:  shutting down
    2021-02-10 08:34:51.031 JST [615] LOG:  database system is shut down
    2021-02-10 08:51:34.474 JST [1759] LOG:  starting PostgreSQL 12.3 on x86_64-apple-darwin19.4.0, compiled by Apple clang version 11.0.3 (clang-1103.0.32.59), 64-bit
    2021-02-10 08:51:34.476 JST [1759] LOG:  listening on IPv6 address "::1", port 5432
    2021-02-10 08:51:34.476 JST [1759] LOG:  listening on IPv4 address "127.0.0.1", port 5432
    :
    
```
CC BY-SA 4.0
2021-02-19T06:08:59.163
74128
2023-07-09T13:04:30.537
2021-04-08T08:21:02.057
3060
43894
question
postgresql
PostgreSQL が動かない: could not connect to server
取り敢えず `brew uninstall postgresql` を実行してみたが、次の様なエラーが出て試してみた。

```

    $ sudo chown -R "$USER":admin /usr/local
    
```

を入力後PWを入れる。

```

    $ brew uninstall postgresql
    Uninstalling /usr/local/Cellar/postgresql/12.3_4... (3,220 files, 37.8MB)
    postgresql  are still installed.
    To remove all versions, run:
    
```

`$ brew uninstall --force postgresql` ⭐️これを実行してすべてクリーンにする。

`$ brew install postgresql` で再インストールするが、エラーが出る。

```

    Error: 
      homebrew-core is a shallow clone.
    To `brew update`, first run:
    
    $ bundle install --path vendor/bundle
    $ rails db:migrate
    $ rails db:create
    
```

無事起動！

参考:

  * [How to fix homebrew permissions?](https://stackoverflow.com/questions/16432071/how-to-fix-homebrew-permissions)
  * [ActiveRecord::NoDatabaseErrorが出た時の対処法](https://rails-ambassador.herokuapp.com/debugs/NoDatabaseError)
CC BY-SA 4.0
2021-04-20T00:12:16.823
75391
2021-04-20T06:20:38.420
2021-04-20T06:20:38.420
3060
43894
74128
answer