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 刚安装完,出的问题,求大牛帮忙
从 brew info postgres
摘抄的:
If this is your first install, create a database with:
initdb /usr/local/var/postgres -E utf8
and create user
createuser postgres createdb -U postgres postgres
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
You can add aliases
alias pg.start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start' alias pg.stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
#1 楼 @luikore 额,还是提示这个错误。。 iMac:19wu-master lxq$ createuser postgres Shall the new role be a superuser? (y/n) y createuser: could not connect to database postgres: 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"?
initdb /usr/local/var/postgres -E utf8
初始化数据库
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
启动 postgresql server
然后再psql
就能打开了,没有问题啊,也是 brew 安装的。
今天遇到了同样的问题,在 rails 5 中用 rails db:create
时出现这个问题,但直接运行 psql
是正常的。后来在 stackoverflow 上看到了解决办法,环境变量的问题,一行解决:export PGHOST=localhost