Postgresql postgres服务器已启动,但无法连接到服务器

Postgresql postgres服务器已启动,但无法连接到服务器,postgresql,sinatra,Postgresql,Sinatra,在我丢失了电脑上的所有数据后(不得不让苹果商店擦除所有数据),我用自制的brew install postgres命令在Mac上安装了postgres。然后,我启动了服务器(确认服务器已启动),并尝试使用命令为使用postgres的Sinatra项目创建数据库 createdb db_development 但是,我得到了以下错误: createdb: could not connect to database postgres: could not connect to server

在我丢失了电脑上的所有数据后(不得不让苹果商店擦除所有数据),我用自制的
brew install postgres
命令在Mac上安装了postgres。然后,我启动了服务器(确认服务器已启动),并尝试使用命令为使用postgres的Sinatra项目创建数据库

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会在我收到此错误的同时确认服务器已启动?postgres:无法连接到数据库postgres:无法连接到服务器:没有这样的文件或目录,我如何修复此错误

该项目的READ.me说

bundle install
createdb db_development
rake db:migrate

它要么尝试连接到MacOS附带的postgres,要么未设置PG环境变量。 尝试:
createdb-h localhost db_开发

这些是为博士后准备的。在Mac上使用Postgresql也是一种非常方便的方法

Postgres在Postgresql.conf中有一个“unix\u socket\u目录”设置 请验证此设置是否存在以及目录本身是否存在,然后重新启动服务器。如果不存在,请将其设置为/var/run(或其他存在的目录)并重新启动服务器