当我尝试运行服务器时:
postgres@ubuntu:~$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets postgres@ubuntu:~$
Run Code Online (Sandbox Code Playgroud)
然后我将用户改为自己:
postgres@ubuntu:~$ su - michael
michael@ubuntu:~$ sudo netstat -tulpn | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 959/postgres
Run Code Online (Sandbox Code Playgroud)
好吧,postgres似乎正在听端口,这似乎是问题所在.
让我们将pack更改为postgres并尝试终止此过程:
postgres@ubuntu:~$ kill `cat /usr/local/pgsql/data/postmaster.pid`
Run Code Online (Sandbox Code Playgroud)
反应是:
cat: /usr/local/pgsql/data/postmaster.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
Run Code Online (Sandbox Code Playgroud)
你能推荐我怎么办吗?
首先,运行Postgres pid:
ps -ef | grep postmaster | awk '{print $2}'
Run Code Online (Sandbox Code Playgroud)
然后杀了它
kill <the_pid_you_just_got>
Run Code Online (Sandbox Code Playgroud)
但是,除非你正在尝试做一些非常特别的在Postgres(多个实例......),你应该使用停止须藤/etc/init.d/postgresql的停止(或sudo /etc/init.d/postgres停止)并启动它使用sudo /etc/init.d/postgresql start
Postgres作为服务运行,因此它有一个服务控制文件/脚本,负责正确启动和停止它.使用这些控制文件位于里面的/etc/init.d,但我必须承认,它已成为一个有点乱,这些天,随着越来越多的服务管理系统(INIT,暴发户,systemd ...)