[RAILS] [PostgreSQL] could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I get the following error when trying to start on rails server

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

Try to log in to PostgreSQL

Same error occurs

$ psql posrgres
 ... (Omitted) ...
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

Try restarting PostgreSQL

brew services restart postgresql@11

Attempts to log in again but fails

Try different commands

Try deleting the data directory (** Note: The data will be lost **)
rm -rf /usr/local/var/postgres
Try reinstalling PostgreSQL
brew uninstall --force postgresql@11
brew install postgresql@11
I can log in to PostgreSQL, but when I run rails server, rails db: create, rails db: migrate, etc., I still get the error ↓
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Try to add a link with the following command
$sudo mkdir /var/pgsql_socket/
$sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket
Execute rails db: create → Error statement changed
dyld: lazy symbol binding failed: Symbol not found: _PQresultMemorySize
  Referenced from: /Users/dev/.rvm/gems/ruby-2.5.7/gems/pg-1.2.2/lib/pg_ext.bundle
  Expected in: /usr/lib/libpq.5.dylib

dyld: Symbol not found: _PQresultMemorySize
  Referenced from: /Users/dev/.rvm/gems/ruby-2.5.7/gems/pg-1.2.2/lib/pg_ext.bundle
  Expected in: /usr/lib/libpq.5.dylib

Try reinstalling the PostgreSQL gem

Comment out gem'pg' from the Gemfile and bundle update gem'pg' Uncomment and bundle install

Execute rails db: create → Success

rails db: migrate rails server now also passes

Reference article

** Solved the problem that DB could not be created with postgresql ** https://haayaaa.hatenablog.com/entry/2019/01/23/111745

** Causes and remedies when you cannot connect to postgresql installed with Homebrew ** https://blog.kyanny.me/entry/2015/01/16/024304

"/var/pgsql_socket/.s.PGSQL.5432"? https://ameblo.jp/soft3133/entry-11466406890.html

Recommended Posts

[PostgreSQL] could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
PG :: ConnectionBad: could not connect to server: No such file or directory
When I did rails new, I got an error saying PG :: ConnectionBad: could not connect to server: No such file or directory