命令简介
pg_ctl 启动、关闭、重启 postgres
pg_ctl start [-w] [-s] [-D datadir] [-l filename] [-o options] [-p path] pg_ctl stop [-W] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] pg_ctl restart [-w] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-o options] pg_ctl reload [-s] [-D datadir] pg_ctl status [-D datadir] pg_ctl kill [signal_name] [process_id] pg_ctl register [-N servicename] [-U username] [-P password] [-D datadir] [-w] [-o options] pg_ctl unregister [-N servicename]
具体说明见参考资料。
实操记录
# 查找 pg_ctl [root@localhost ~]# whereis pg_ctl pg_ctl: /usr/bin/pg_ctl /usr/share/man/man1/pg_ctl.1.gz # 启动 postgres [root@localhost ~]# su postgres bash-4.2$ /usr/bin/pg_ctl -D /var/lib/pgsql/data start could not change directory to "/root" pg_ctl: another server might be running; trying to start server anyway server starting bash-4.2$ FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 30063) running in data directory "/var/lib/pgsql/data"?
出现如下错误 could not change directory to "/root",因为在 postgres 中不能自动切换路径,解决方法
bash-4.2$ cd /usr/bin bash-4.2$ pwd /usr/bin bash-4.2$ ./pg_ctl -D /var/lib/pgsql/data start server starting
可能出现如下错误 pg_ctl: PID file "/var/lib/pgsql/data/postmaster.pid" does not exist,可以查看启动日志
我操作时是因为磁盘满了,无法创建新的文件 postmaster.pid,清除缓存腾出一点空间即可。