PostgreSQL7.0手冊(cè)-用戶手冊(cè)-20. 應(yīng)用 - pg_ctl
2019-09-08 23:33:31
供稿:網(wǎng)友
pg_ctl
名稱
pg_ctl -- 啟動(dòng),停止,和重起 postmaster
語(yǔ)法
pg_ctl [-w] [-D datadir][-p path] [-o "options"] start
pg_ctl [-w] [-D datadir] [-m [s[mart]|f[ast]|i[mmediate]]] stop
pg_ctl [-w] [-D datadir] [-m [s[mart]|f[ast]|i[mmediate]]
[-o "options"] restart
pg_ctl [-D datadir] status
輸入
-w
通過(guò)觀察 pid 文件(PGDATA/postmaster.pid)的創(chuàng)建,等待數(shù)據(jù)庫(kù)服務(wù)器的啟動(dòng).在 60 秒后超時(shí).
-D datadir
聲明這個(gè)數(shù)據(jù)庫(kù)安裝的數(shù)據(jù)庫(kù)位置.
-p path
聲明 postmaster 影象的位置.
-o "options"
聲明直接傳遞給 postmaster 的選項(xiàng).
通常這些參數(shù)用單或雙引號(hào)引起,以保證它們以一組的方式傳遞.
-m mode
聲明關(guān)閉模式.
smart, s
智能模式,等待所有客戶端退出.這是缺省.
f[ast], f
快速模式,向后端發(fā)送 SIGTERM,這意味著活躍的事務(wù)都回卷.
immediate, i
立即模式,向后端發(fā)送 SIGUSR1 并且讓它們退出.在這種模式,下一次啟動(dòng)將必須進(jìn)行數(shù)據(jù)庫(kù)恢復(fù)工作.
start
啟動(dòng) postmaster.
stop
關(guān)閉 postmaster.
restart
重新啟動(dòng) postmaster,執(zhí)行一次順序的 stop/start.
status
顯示 postmaster 的當(dāng)前狀態(tài).
輸出
pg_ctl: postmaster is state (pid: #)
Postmaster 狀態(tài).
如果存在一個(gè)錯(cuò)誤條件,將顯示出后端的錯(cuò)誤信息.
描述
pg_ctl 是一個(gè)用于啟動(dòng),停止和重起 postmaster 的工具.
用法
啟動(dòng) postmaster
要啟動(dòng) postmaster:
> pg_ctl start
如果使用了 -w,pg_ctl 等待數(shù)據(jù)庫(kù)服務(wù)器啟動(dòng)-通過(guò)觀察 pid 文件(PGDATA/postmaster.pid)的創(chuàng)建,最多等待 60 秒.
激活 postmaster 的參數(shù)從下面的資源里獲取:
postmaster 的路徑:在命令搜索路徑里查找.
數(shù)據(jù)庫(kù)目錄:PGDATA 環(huán)境變量.
其他參數(shù):PGDATA/postmaster.opts.default.
postmaster.opts.default 包含用于 postmaster 的參數(shù).缺省安裝時(shí),打開(kāi)了 -S 選項(xiàng).因此 pg_ctl start 隱含地是:
postmaster -S
請(qǐng)注意 postmaster.opts.default 是由 initdb 從 Postgres 的安裝目錄(lib/postmaster.opts.default.sample 是安裝 Postgres 時(shí)從 src/bin/pg_ctl/postmaster.opts.default.sample )里的?lib/postmaster.opts.default.sample 拷貝來(lái)的.
要覆蓋缺省的參數(shù),你可以使用 -D,-p 和 -o 選項(xiàng).
一個(gè)啟動(dòng) postmaster,并等到l postmaster 啟動(dòng)后才退出的例子是:
> pg_ctl -w start
要聲明 postmaster 二進(jìn)制路徑,試試:
> pg_ctl -p /usr/local/pgsq/bin/postmaster start
對(duì)一個(gè)使用端口5433,并且運(yùn)行在無(wú)磁盤(pán)同步的模式的 postmaster,使用:
> pg_ctl -o "-o -F -p 5433" start
停止 postmaster
> pg_ctl stop
停止 postmaster.使用 -m 開(kāi)關(guān)以允許我們控制后端是如何停止的.-w 等待 postmaster 停止.-m 聲明停止的模式.
重起 postmaster
這個(gè)功能幾乎等同于停止 postmaster 然后再次啟動(dòng)它-除了停止它前的參數(shù)還要使用以外.這是通過(guò)在 $PGDATA/postmaster.opts 文件里存儲(chǔ)這些參數(shù)實(shí)現(xiàn)的.-w,-D,-m,-fast,-immediate 也可以在重起模式使用,并且和上面有一樣的含義.
要用最簡(jiǎn)單的方法重起 postmaster:
> pg_ctl restart
要重起 postmaster,等它停止并重新啟動(dòng):
> pg_ctl -w restart
要在 5433 端口重起并且重起后關(guān)閉 fsync:
> pg_ctl -o "-o -F -p 5433" restart
postmaster 狀態(tài)
要從 postmaster 獲取狀態(tài)信息:
> pg_ctl status
下面是一些從 pg_ctl 里的例子:
pg_ctl: postmaster is running (pid: 13718)
options are:
/usr/local/src/pgsql/current/bin/postmaster
-p 5433
-D /usr/local/src/pgsql/current/data
-B 64
-b /usr/local/src/pgsql/current/bin/postgres
-N 32
-o '-F'