无法构建 PostgreSQL 环境。致命:数据库 "t" 不存在

Unable to build the PostgreSQL environment. FATAL: database "t" does not exist

我从 brew 安装了 postgres。 我收到一个错误,我试图删除 postmaster.id 该文件似乎丢失了。

rm -f data/postmaster.pid 没有效果。

我试过了

$brew install postgres
$psql --version                                                                                                        
psql (PostgreSQL) 14.1

$postgres --version                                                                                                    
postgres (PostgreSQL) 14.1
$psql

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:  database "t" does not exist
$postgres -D /usr/local/var/postgres                                                                                  

2022-01-28 14:27:14.406 JST [94892] LOG:  starting PostgreSQL 14.1 on aarch64-apple-darwin21.1.0, compiled by Apple clang version 13.0.0 (clang-1300.0.29.3), 64-bit
2022-01-28 14:27:14.408 JST [94892] LOG:  could not bind IPv6 address "::1": Address already in use
2022-01-28 14:27:14.408 JST [94892] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-01-28 14:27:14.408 JST [94892] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2022-01-28 14:27:14.408 JST [94892] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-01-28 14:27:14.408 JST [94892] WARNING:  could not create listen socket for "localhost"
2022-01-28 14:27:14.408 JST [94892] FATAL:  could not create any TCP/IP sockets
2022-01-28 14:27:14.409 JST [94892] LOG:  database system is shut down
$rm /usr/local/var/postgres/postmaster.pid                                                                            

rm: /usr/local/var/postgres/postmaster.pid: No such file or directory    
$sudo lsof -i:5432                 
                                                                                    
COMMAND    PID USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
postgres 94724    t    7u  IPv6 0xe42d991dab624b7      0t0  TCP localhost:postgresql (LISTEN)
postgres 94724    t    8u  IPv4 0xe42d991d7856c0f      0t0  TCP localhost:postgresql (LISTEN)

我不知道你为什么坚持要通过删除 PID 文件来破坏你的 PostgreSQL 服务器。我希望你停止这样做。

该错误消息表示您正在尝试连接到数据库 t,但该数据库不存在。由于您没有明确指定数据库,原因可能是:

  • 您是操作系统用户 t,因此默认连接到数据库 t

  • 环境变量PGDATABASE设置为t

  • 环境变量PGUSER设置为t,连接默认与用户名同数据库名

无论如何,解决方案是选择一个现有的数据库并使用

psql -d dbname