PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

pg_ctl

劉䓄

pg_ctl -- 劇媘㔕啩溵㔕麉劇 PostgreSQL

臺濘

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 䫘庯劇媘㔕啩溵㔕麉劇 PostgreSQL 劯䆇橉媇単(postgres)潡蔙滆䴺婔婻誊臯五䔇橉媇単䔇䪽攕㔗儘䞇埇傖欋媘劇媘橉媇単嘖滇 pg_ctl 儕輙庖麉桄垔劏斖媖膷庺婯䂽䆇启誕䘋䂇劽䊖彖䥂傖埪埥崡柊冕庖婔婻锬釹䫘庯橬毓彽䔇噿閺㔗

start 昇嚟麯嚔劇媘婔婻桄䔇橉媇単㔗橉媇単滇婘劯埄劇媘䔇湺庖膷噖赆鍇五彄庖 /dev/null 婪㔗套悩嘪䫘庖 -l 闼幽湺庖膷庺启湺庖髍臇儖赆垔劏彄婔婻斖媖桺傽襕幽儌滇麉垔劏彄 pg_ctl 䔇湺庖膷庺(蔯婉滇湺庖髍臇)㔗套悩澇橬锬垔斖媖桺傽pg_ctl 䔇湺庖膷庺庫臖麉垔劏彄婔婻桺傽潡蔙䫘䞇長膷庺彄䌂嚚 rotatelogs 認湙䔇斖媖悔媘䘋废劥彍postgres 儖檪垄䔇膷庺喍彄毓彽䂽䆇(婘劯埄)幽婫儖婉嚔臌䥂 shell 䔇誕䘋䂇㔗

stop 昇嚟婋闼婻溼婘䬹垔昄扞䕞嘘誊臯䔇橉媇単儖赆噿閺㔗嘹埇傖䫘 -m 锬釹锬拷婬䓉婉劯䔇噿閺昇嚟"Smart"昇嚟京写欔橬垵潙䆇婺桺誂毖認滇䚺䩕㔗"Fast"昇嚟幽婉京写垵潙䆇婺桺誂毖欔橬昂虄庋媇鄘赆啂悔幽婫垵潙䆇鄘赆嚺彽桺嚔㔗"Immediate"昇嚟儖婘澇橬幾应噿閺䔇愙喕婋嚺臯锔庺㔗認幽啔儖凚躘婘麉桄劇媘䔇施唍䔇敵崉㔗

restart 垂鍙婪滇噽欓臯婔婻啩溵䇽劯䘓虘婔婻劇媘㔗垄噕螩埻扵 postgres 䔇变傴臯锬釹㔗

reload 昇嚟䞔剘婄䂍 postgres 埏锕婔婻 SIGHUP 媇埙凚躘垄麉桄臂埡陉䘞桺傽(postgresql.conf, pg_hba.conf 京)認湙儌噕螩媞櫹陉䘞桺傽锬釹蔯婉䫘麉劇係䂘剿埇䫘昽㔗

status 昇嚟䕏昖婔婻橉媇単滇劥婘毺垔䔇昄扞䕞嘘誊臯套悩滇闼幽滆䴺噽 PID 启脄䫘垄䔇变傴臯锬釹㔗

kill 昇嚟噕螩嘹䂍婔婻毺垔䔇誕䘋埏锕媇埙㔗認婻媘脘凹 Microsoft Windows 䬹彆橬䫘啹婺垄澇橬 kill 变傴㔗嘪䫘 --help 昖䩋櫇毕䔇媇埙劉庖彖臘㔗

register 昇嚟噕螩嘹婘 Microsoft Windows 婪濘喯婔婻係䂘橉媇㔗

unregister 昇嚟噕螩嘹婘 Microsoft Windows 婪役鍴噽嬉䫘 register 变傴濘喯䔇係䂘橉媇㔗

锬釹

-D datadir

弄滯臖昄扞康䔇桺傽係䂘嘉䘞㔗套悩媘䘖彍嘪䫘 PGDATA 䯇嵄埻麟㔗

-l filename

檪橉媇単斖媖膷庺鍇媹婘 filename 桺傽婪㔗套悩臖桺傽婉庻婘彍录傺垄㔗umask 螆䘞婺 077 啹溴䚺䩕施滇婉噕螩傯噽垄䫘潙劏斖媖桺傽螪閞䔇㔗

-m mode

弄滯噿閺昇嚟㔗mode 埇傖滇 smart, fast, immediate 幋婔潡蔙滇認婬婻䔇饡庖應幋婔㔗

-o options

弄滯襕䕘毖嚹锐䂍 postgres 䔇锬釹㔗

埗昄锔婩鄘䫘剘潡蔙埯嚘埙寙啘傖媺臕垄傸嘩婺婔婻昘嘷嚹锐㔗

-p path

弄滯 postgres 埇欓臯桺傽䔇嘉䘞㔗䚺䩕嘉庯 pg_ctl 躻躆欔婘䕞嘘套悩澇欆彄彍嘪䫘䇸䚡乕䔇垬輙䕞嘘㔗鍴麂嘹愿幾䗹傔幽䬹彆䔇庋愙幽婫愿冖彄䌂嚚澇橬欆彄 postgres 認湙䔇髍臇劥彍媙釂嘪䫘認婻锬釹㔗

-s

埻欷剄髍臇蔯婉欷剄柊䴺攓媇敇㔗

-w

京写劇媘潡蔙噿閺䔇垯潊(60 䓐轙施)認婻埗昄滇噿閺施䔇䚺䩕唚㔗潊媘䔇噿閺滇傖役鍴 PID 桺傽婺湺媖䔇㔗凹庯劇媘蔯蘔婔渇潊媘䔇 psql -l 儌湺媖五潊媘㔗pg_ctl 儖嚕商嘪䫘凹 psql 劽锗䔇䆇埼套悩庻婘 PGPORT 䯇嵄埻麟闼幽儖䫘垄㔗劥彍垄儖昖欆婘 postgresql.conf 桺傽麯滇劥螆䘞庖婔婻䆇埼㔗套悩鄘澇橬垄儖嘪䫘 PostgreSQL 䚡臏施䔇䚺䩕䆇埼(䚺䩕 5432)㔗婘京写䔇施唍pg_ctl 儖湹扞劇媘潡蔙噿閺䔇潊媘䪽喕誫啂婔婻庖䇞䔇锔庺傼乕㔗

-W

婉京写劇媘潡蔙啩溵䔇垯潊㔗認滇劇媘启麉劇䔇䚺䩕㔗

Windows 锬釹

-N servicename

襕濘喯䔇係䂘橉媇䔇劉庖㔗認婻劉庖儖䫘庯橉媇劉启滆䴺劉㔗

-P password

䫘潙劇媘橉媇䔇埼傴

-U username

䫘庯劇媘橉媇䔇䫘潙䔇䫘潙劉㔗凹庯嘘䫘潙嘪䫘 DOMAIN\username 湚嚟㔗

䯇嵄埻麟

PGDATA

䚺䩕昄扞䕞嘘嘉䘞

PGPORT

psql 䔇䚺䩕䆇埼(䫌 -w 锬釹嘪䫘)㔗

噽垄䔇䯇嵄埻麟臙埗黙 postgres

桺傽

postmaster.pid

認婻桺傽庻婘庯昄扞䕞嘘婺滇婺庖婞媷 pg_ctl 彴桺橉媇単嘷嬉滇劥婘誊臯㔗

postmaster.opts.default

套悩認婻桺傽庻婘庯昄扞䕞嘘pg_ctl (婘 start 昇嚟婋)儖檪桺傽婄喙垹嘷嘩嚹锐䂍 postgres 变傴䔇锬釹嚹锐誺寂鍴麂赆 -o 锬釹襖䕡㔗

postmaster.opts

套悩認婻桺傽庻婘庯昄扞䕞嘘pg_ctl (婘 start 昇嚟婋)儖檪桺傽婄喙垹嘷嘩嚹锐䂍 postgres 变傴䔇锬釹嚹锐誺寂鍴麂赆 -o 锬釹襖䕡㔗認婻桺傽䔇喙垹幘嚔婘 status 昇嚟麯滆䴺庺準㔗

postgresql.conf

認婻桺傽婘昄扞䕞嘘婺嚔彖悊垄傖昖欆启 psql 婔蕙䫘䔇劽锗䔇䆇埼(婘 start 昇嚟麯䂍庺 -w 䔇施唍)㔗

濘懟

京写垯噘劇媘誻婉滇婔婻垔幬冖冽垯昘䔇淉嘩套悩螪閞毓彽螆䘞婺橸婄垵潙䆇婘澇橬欋噖庴庐䔇愙喕婋婉脘螪閞䔇臺誻埇脘嚔崌昽(懫套埼傴螴臕)㔗

冋床

劇媘橉媇単

劇媘橉媇単

$ pg_ctl start

劇媘橉媇単䔇婔婻冋床京彄橉媇単劇媘庖欉锔庺

$ pg_ctl -w start

橉媇単嘪䫘 5433 䆇埼蔯婫婉婥 fsync 誊臯嘪䫘

$ pg_ctl -o "-F -p 5433" start

啩溵橉媇単

$ pg_ctl stop

嘪䫘 -m 锬釹啩溵橉媇単噕螩䫘潙毓彽套嘘噿閺劯䆇㔗

麉劇橉媇単

認婻变傴庹幯京庯噽啩溵橉媇単䇽劯喉劇媘垄埻婉誺 pg_ctl 媺庻幽麉桄嘪䫘婪婔渇誊臯橉媇単䔇变傴臯埗昄㔗麉劇橉媇単䔇橔䞔剘䔇桹濘滇

$ pg_ctl restart

麉劇橉媇単京写噽啩溵启麉劇

$ pg_ctl -w restart

嘪䫘 5433 䆇埼麉劇幽婫麉劇劯噿閺 fsync

$ pg_ctl -o "-F -p 5433" restart

滆䴺橉媇単䪽攕

婋麵滇準躻 pg_ctl 䔇䪽攕膷庺䔇冋床

$ pg_ctl status
pg_ctl: server is running (pid: 13718)
Command line was:
/usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'

認儌滇婘 restart 昇嚟婺赆脄䫘䔇变傴臯㔗

埽蓕

postgres


劯锔饡釕嬉誕
pg_controldata婪婔亓pg_resetxlog