PostgreSQL服務器啓動及關閉方法
PostgreSQL採用C/S(客戶機/服務器)模式結構。應用層通過INET或者Unix Socket利用既定的協議與數據庫服務器進行通信。下面yjbys小編爲大家蒐集相關的PostgreSQL服務器啓動及關閉方法!
1. 啓動數據庫服務器(posgres用戶):
[postgres@localhost bin]$ postgres -D /opt/postgresql/data/ > /opt/postgresql/log/pg_ 2>&1 &
[1] 4508
當然如果設置了環境變量
PGDATA=/opt/postgresql/data
export PGDATA
後,可使用pg_ctl工具進行啓動:
[postgres@localhost log]$ pg_ctl start -l /opt/postgresql/log/pg_
pg_ctl: another server might be running; trying to start server anyway
pg_ctl: could not start server
Examine the log output.
[postgres@localhost log]$
因爲之前已經啓動,所以打印“another server might be running”。此時,查看日誌,有如下信息:
[postgres@localhost log]$ cat pg_
FATAL: lock file "" already exists
HINT: Is another postmaster (PID 4491) running in data directory "/opt/postgresql/data"?
[postgres@localhost log]$
當然,最簡的啓動方式是:
[postgres@localhost ~]$ pg_ctl start
server starting
[postgres@localhost ~]$ LOG: database system was shut down at 2011-07-09 13:58:00 CST
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
如果要在操作系統啓動時就啓動PG,可以在/etc/rc.d/l 文件中加以下語句:
/opt/postgresql/bin/pg_ctl start -l /opt/postgresql/log/pg_ -D /opt/postgresql/data
2.關閉服務器
最簡單方法:
[postgres@localhost ~]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
與Oracle相同,在關閉時也可採用不同的'模式,簡介如下:
SIGTERM
不再允許新的連接,但是允許所有活躍的會話正常完成他們的工作,只有在所有會話都結束任務後才關閉。這是智能關閉。
SIGINT
不再允許新的連接,向所有活躍服務器發送 SIGTERM(讓它們立刻退出),然後等待所有子進程退出並關閉數據庫。這是快速關閉。
SIGQUIT
令 postgres 向所有子進程發送 SIGQUIT 並且立即退出(所有子進程也會立即退出),而不會妥善地關閉數據庫系統。這是立即關閉。這樣做會導致下次啓動時的恢復(通過重放 WAL 日誌)。我們推薦只在緊急的時候使用這個方法。
SIGKILL
此選項儘量不要使用,這樣會阻止服務器清理共享內存和信號燈資源,那樣的話你只能在啓動服務器之前自己手工做這件事。另外,SIGKILL 直接把 postgres 殺掉,而不會等它把信號中繼給它的子進程,因此我們還需要手工殺掉每個獨立子進程。
使用方法舉例:
[postgres@localhost ~]$ pg_ctl stop -o SIGTERM
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
waiting for server to shut : shutting down
LOG: database system is shut down
done
server stopped
[postgres@localhost ~]$
最快速關閉方法:kill postgres 進程
[postgres@localhost ~]$ kill -INT `head -1 /opt/postgresql/data/`
[postgres@localhost ~]$ LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
附:postgre啓動後的進程,如下:
[postgres@localhost ~]$ ps -ef|grep post
root 4609 4543 0 13:57 pts/2 00:00:00 su - postgres
postgres 4610 4609 0 13:57 pts/2 00:00:00 -bash
postgres 4724 1 0 14:08 pts/2 00:00:00 /opt/postgresql/bin/postgres
postgres 4726 4724 0 14:08 ? 00:00:00 postgres: writer process
postgres 4727 4724 0 14:08 ? 00:00:00 postgres: wal writer process
postgres 4728 4724 0 14:08 ? 00:00:00 postgres: autovacuum launcher process
postgres 4729 4724 0 14:08 ? 00:00:00 postgres: stats collector process
postgres 4752 4610 0 14:11 pts/2 00:00:00 ps -ef
postgres 4753 4610 0 14:11 pts/2 00:00:00 grep post
[postgres@localhost ~]$
相關文章
-
MySQL安裝時出現current root password的解決方法
總結出以下解決方法:1.清除MYSQL的`安裝目錄,默認是C:Program Files2.清除MYSQL數據存放目錄,一般在C:Documents and SettingsAll owsApplication Data目錄下(需要注意的時Application Data這個文件夾默認是隱藏的,要通過 -
MS SQL Server Management Studio Express安裝圖文具體步驟
Microsoft sql server Management Studio Express (SSMSE) 是一種免費、易用的圖形管理工具,用於管理 SQL Server 2005 Express Edition 和具有高級服務的 SQL Server 2005 Express Edition。SSMSE 還可以管理任何版本 -
Zend studio for eclipse中使php可以調用mysql相關函數的設置方
Zend studio for eclipse中使php可以調用mysql相關函數的設置方法教程如果直接調用mysql_connect會出現:Fatal error: Call to undefined function mysql_connect() 的錯誤解決辦法,找到zend studio 所在的`位置我的zen -
WebSphere MQ Solution Designer認證考試
IBM根據其產品分類設置了相應的專業認證項目,那麼IBM認證是什麼呢?IBM認證的優勢又怎樣的呢?下面是小編整理的關於WebSphere MQ Solution Designer認證考試,希望大家認真閱讀! 打開隊列本部分討論打開不同隊列類型的 -
The Risks of Plastic Surgery高中英語作文及翻譯
Today, Korean TV series is very popular in China, people are attractive by the beautiful girls and handsome boys, they want to be one of a is famous by the plastic surgery, it is said that most Korean -
快速入睡的方法The Ways to Get Sleep Quickly高中英語作文
謎面得天子氣而興波瀾謎語類型打一篇目謎底王風,揚之水 -
SQL Server 服務由於登錄失敗而無法啓動怎麼辦
SQL Server 服務由於登錄失敗而無法啓動症狀在重新啓動 SQL Server、SQL Executive 或 SQL Server Agent 時,可能無法啓動該服務,並顯示以下錯誤信息:Error 1069:The service did not start due to a logon failure.或者 -
用Photoshop如何繪製Google Currents圖標
使用Photoshop如何繪製 Google Currents 的圖標?下面是詳細介紹,歡迎閱讀,更多內容請關注應屆畢業生網!這題用 AI、Sketch 等矢量繪圖工具來做,可能比 Photoshop 合適。以下過程使用 Sketch 繪製,其他軟件可觸類旁通。一 -
大學生面臨許多壓力The Pressures on Collese Students英語作文
many college students say that they are facing so many pressures in their lives that they are on the go from moing till night. what, then, are the pressures on college students?there are generally thr -
Windows系統服務器技術SQLServer輔導資料
知識就是力量,下面是小編整理的關於存儲過程的一些簡單的理論和實際應用的知識,歡迎閱讀!首先,我們需要了解的是什麼是存儲過程,以及它的格式。定義:將常用的或很複雜的工作,預先用SQL語句寫好並用一個指定的'名稱存儲起來