设为首页 收藏本站
查看: 1113|回复: 0

[经验分享] PostgreSQL服务器启动和关闭方法介绍

[复制链接]

尚未签到

发表于 2016-11-20 10:47:55 | 显示全部楼层 |阅读模式
  1. 启动数据库服务器(posgres用户):
[postgres@localhost bin]$ postgres -D /opt/postgresql/data/ > /opt/postgresql/log/pg_server.log 2>&1 &[1] 4508  
当然如果设置了环境变量
PGDATA=/opt/postgresql/dataexport PGDATA  后,可使用pg_ctl工具进行启动:
[postgres@localhost log]$ pg_ctl start -l /opt/postgresql/log/pg_server.logpg_ctl: another server might be running; trying to start server anywaypg_ctl: could not start serverExamine the log output.[postgres@localhost log]$  
因为之前已经启动,所以打印“another server might be running”。此时,查看日志,有如下信息:
[postgres@localhost log]$ cat pg_server.logFATAL:  lock file "postmaster.pid" already existsHINT:  Is another postmaster (PID 4491) running in data directory "/opt/postgresql/data"?[postgres@localhost log]$  当然,最简的启动方式是:
[postgres@localhost ~]$ pg_ctl startserver starting[postgres@localhost ~]$ LOG:  database system was shut down at 2011-07-09 13:58:00 CSTLOG:  autovacuum launcher startedLOG:  database system is ready to accept connections  
如果要在操作系统启动时就启动PG,可以在/etc/rc.d/rc.local 文件中加以下语句:
/opt/postgresql/bin/pg_ctl start -l /opt/postgresql/log/pg_server.log -D /opt/postgresql/data  
2.关闭服务器
  最简单方法:
[postgres@localhost ~]$ pg_ctl stopwaiting for server to shut down.... doneserver stopped  与oracle相同,在关闭时也可采用不同的模式,简介如下:
SIGTERM 不再允许新的连接,但是允许所有活跃的会话正常完成他们的工作,只有在所有会话都结束任务后才关闭。这是智能关闭。SIGINT 不再允许新的连接,向所有活跃服务器发送 SIGTERM(让它们立刻退出),然后等待所有子进程退出并关闭数据库。这是快速关闭。SIGQUIT 令 postgres 向所有子进程发送 SIGQUIT 并且立即退出(所有子进程也会立即退出),而不会妥善地关闭数据库系统。这是立即关闭。这样做会导致下次启动时的恢复(通过重放 WAL 日志)。我们推荐只在紧急的时候使用这个方法。SIGKILL 此选项尽量不要使用,这样会阻止服务器清理共享内存和信号灯资源,那样的话你只能在启动服务器之前自己手工做这件事。另外,SIGKILL 直接把 postgres 杀掉,而不会等它把信号中继给它的子进程,因此我们还需要手工杀掉每个独立子进程。  使用方法举例:
[postgres@localhost ~]$ pg_ctl stop -o SIGTERMLOG:  received smart shutdown requestLOG:  autovacuum launcher shutting downwaiting for server to shut down....LOG:  shutting downLOG:  database system is shut downdoneserver stopped[postgres@localhost ~]$  
最快速关闭方法:kill postgres 进程
[postgres@localhost ~]$ kill -INT `head -1 /opt/postgresql/data/postmaster.pid`[postgres@localhost ~]$ LOG:  received fast shutdown requestLOG:  aborting any active transactionsLOG:  autovacuum launcher shutting downLOG:  shutting downLOG:  database system is shut down  
附:postgre启动后的进程,如下:
[postgres@localhost ~]$  ps -ef|grep postroot      4609  4543  0 13:57 pts/2    00:00:00 su - postgrespostgres  4610  4609  0 13:57 pts/2    00:00:00 -bashpostgres  4724     1  0 14:08 pts/2    00:00:00 /opt/postgresql/bin/postgrespostgres  4726  4724  0 14:08 ?        00:00:00 postgres: writer processpostgres  4727  4724  0 14:08 ?        00:00:00 postgres: wal writer processpostgres  4728  4724  0 14:08 ?        00:00:00 postgres: autovacuum launcher processpostgres  4729  4724  0 14:08 ?        00:00:00 postgres: stats collector processpostgres  4752  4610  0 14:11 pts/2    00:00:00 ps -efpostgres  4753  4610  0 14:11 pts/2    00:00:00 grep post[postgres@localhost ~]$  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-302833-1-1.html 上篇帖子: PostgreSQL psycopg2:IndexError: tuple index out of range 下篇帖子: 系统蓝屏后 PostgreSQL 无法启动的解决
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表