在我丢失了计算机上的所有数据后(必须将Apple商店删除的所有内容都删除),我使用Homebrew在我的Mac上安装了postgres,命令为brew install postgres
。然后我启动了服务器(确认服务器已启动)并尝试使用命令
createdb db_development
但是,我收到以下错误:
createdb: 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命令
initdb /usr/local/var/postgres
但是当我这样做时,我收到了这条消息
initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "braindead".
This user must also own the server process.
The database cluster will be initialized with locale "en_CA.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: 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".
那么,为什么postgres会在我收到此错误could not connect to database postgres: could not connect to server: No such file or directory
的同时确认服务器已启动,我该如何解决?
该项目的READ.me说
bundle install
createdb db_development
rake db:migrate
答案 0 :(得分:1)
它要么尝试连接到MacOS附带的postgres,要么未设置PG环境变量。
尝试:
createdb -h localhost db_development
答案 1 :(得分:0)
Postgres在postgresql.conf中有一个“unix_socket_directory”设置 请验证此设置是否存在以及目录本身是否存在,然后重新启动服务器。如果它不存在,请将其设置为/ var / run(或其他存在的目录),然后重新启动服务器。