我已经安装和卸载了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现在似乎工作正常,但知道如何修复此错误会很高兴
答案 0 :(得分:1)
我对你的命令有点混淆
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
因为命令pg_ctl -D /usr/local/var/postgres start
用于启动数据库守护程序,而命令brew services start postgresql
执行相同的操作。
这意味着您尝试启动数据库两次,当然第二个无法启动。
你能尝试只运行一个命令吗?