1. 启动数据库服务器(posgres用户):
- [postgres@localhostbin]$postgres-D/opt/postgresql/data/>/opt/postgresql/log/pg_server.log2>&1&
- [1]4508
当然如果设置了环境变量
- PGDATA=/opt/postgresql/data
- exportPGDATA
后,可使用pg_ctl工具进行启动:
- [postgres@localhostlog]$pg_ctlstart-l/opt/postgresql/log/pg_server.log
- pg_ctl:anotherservermightberunning;tryingtostartserveranyway
- pg_ctl:couldnotstartserver
- Examinethelogoutput.
- [postgres@localhostlog]$
因为之前已经启动,所以打印“another server might be running”。此时,查看日志,有如下信息:
- [postgres@localhostlog]$catpg_server.log
- FATAL:lockfile"postmaster.pid"alreadyexists
- HINT:Isanotherpostmaster(PID4491)runningindatadirectory"/opt/postgresql/data"?
- [postgres@localhostlog]$
当然,最简的启动方式是:
- [postgres@localhost~]$pg_ctlstart
- serverstarting
- [postgres@localhost~]$LOG:databasesystemwasshutdownat2011-07-0913:58:00CST
- LOG:autovacuumlauncherstarted
- LOG:databasesystemisreadytoacceptconnections
如果要在操作系统启动时就启动PG,可以在/etc/rc.d/rc.local文件中加以下语句:
- /opt/postgresql/bin/pg_ctlstart-l/opt/postgresql/log/pg_server.log-D/opt/postgresql/data
2.关闭服务器
最简单方法:
- [postgres@localhost~]$pg_ctlstop
- waitingforservertoshutdown....done
- serverstopped
与Oracle相同,在关闭时也可采用不同的模式,简介如下:
- SIGTERM
- 不再允许新的连接,但是允许所有活跃的会话正常完成他们的工作,只有在所有会话都结束任务后才关闭。这是智能关闭。
- SIGINT
- 不再允许新的连接,向所有活跃服务器发送SIGTERM(让它们立刻退出),然后等待所有子进程退出并关闭数据库。这是快速关闭。
- SIGQUIT
- 令postgres向所有子进程发送SIGQUIT并且立即退出(所有子进程也会立即退出),而不会妥善地关闭数据库系统。这是立即关闭。这样做会导致下次启动时的恢复(通过重放WAL日志)。我们推荐只在紧急的时候使用这个方法。
- SIGKILL
- 此选项尽量不要使用,这样会阻止服务器清理共享内存和信号灯资源,那样的话你只能在启动服务器之前自己手工做这件事。另外,SIGKILL直接把postgres杀掉,而不会等它把信号中继给它的子进程,因此我们还需要手工杀掉每个独立子进程。
使用方法举例:
- [postgres@localhost~]$pg_ctlstop-oSIGTERM
- LOG:receivedsmartshutdownrequest
- LOG:autovacuumlaunchershuttingdown
- waitingforservertoshutdown....LOG:shuttingdown
- LOG:databasesystemisshutdown
- done
- serverstopped
- [postgres@localhost~]$
最快速关闭方法:killpostgres进程
- [postgres@localhost~]$kill-INT`head-1/opt/postgresql/data/postmaster.pid`
- [postgres@localhost~]$LOG:receivedfastshutdownrequest
- LOG:abortinganyactivetransactions
- LOG:autovacuumlaunchershuttingdown
- LOG:shuttingdown
- LOG:databasesystemisshutdown
附:postgre启动后的进程,如下:
- [postgres@localhost~]$ps-ef|greppost
- root46094543013:57pts/200:00:00su-postgres
- postgres46104609013:57pts/200:00:00-bash
- postgres47241014:08pts/200:00:00/opt/postgresql/bin/postgres
- postgres47264724014:08?00:00:00postgres:writerprocess
- postgres47274724014:08?00:00:00postgres:walwriterprocess
- postgres47284724014:08?00:00:00postgres:autovacuumlauncherprocess
- postgres47294724014:08?00:00:00postgres:statscollectorprocess
- postgres47524610014:11pts/200:00:00ps-ef
- postgres47534610014:11pts/200:00:00greppost
- [postgres@localhost~]$
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|