我已经安装和卸载了Postgres很多次,这就是我所在的地方:
当我运行psql postgres
时,出现此错误:
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
当我运行此命令时:
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
我收到此错误:
waiting for server to start....2018-01-21 17:02:39.204 PST [10947] LOG: listening on IPv6 address "::1", port 5432
2018-01-21 17:02:39.205 PST [10947] LOG: listening on IPv6 address "fe80::1%lo0", port 5432
2018-01-21 17:02:39.205 PST [10947] LOG: listening on IPv4 address "127.0.0.1", port 5432
2018-01-21 17:02:39.205 PST [10947] LOG: could not bind Unix address "/tmp/.s.PGSQL.5432": Address already in use
2018-01-21 17:02:39.205 PST [10947] HINT: Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.
2018-01-21 17:02:39.205 PST [10947] WARNING: could not create Unix-domain socket in directory "/tmp"
2018-01-21 17:02:39.205 PST [10947] FATAL: could not create any Unix-domain sockets
2018-01-21 17:02:39.205 PST [10947] LOG: database system is shut down
我的/tmp
目录没有.s.PGSQL.5432
文件,并且我的sudo lsof -i tcp:5432
不显示任何内容,表示该端口上未运行任何内容
..
更新(解决方法)
我下载了 Postgress.app,将我想使用的端口更改为 5435,Postgres 现在似乎工作正常,但知道如何解决此错误会很好
我对你的命令有点困惑
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
因为命令pg_ctl -D /usr/local/var/postgres start
用于启动数据库守护程序,而命令brew services start postgresql
执行相同的操作。
这意味着您尝试启动数据库两次,当然第二次无法启动。
您可以尝试仅运行一个命令吗?