wordpress社團(tuán)網(wǎng)站今日頭條最新
開頭還是介紹一下群,如果感興趣Polardb ,mongodb ,MySQL?,Postgresql ,redis ,SQL SERVER ,ORACLE,Oceanbase 等有問題,有需求都可以加群群內(nèi)有各大數(shù)據(jù)庫行業(yè)大咖,CTO,可以解決你的問題。加群請加 liuaustin3微信號 ,在新加的朋友會分到3群(共1170人左右 1 + 2 + 3)
首先道歉,昨天關(guān)于POSTGRESQL 的文章中的部分內(nèi)容個(gè)人覺得有誤導(dǎo)的部分或者說沒有解釋清楚的地方。雖然相關(guān)的部分是官方的提供的相關(guān)的文件,特通過此文更新相關(guān)的內(nèi)容。
在上一篇文章中,有這樣一個(gè)部分
因?yàn)檫@個(gè)地方有不同的意見
1??實(shí)際上這塊的部分代表了reload 的部分,而通常我們撰寫這塊的方式是
ExecReload=/usr/local/postgres/bin/pg_ctl reload -D ${PGDATA}
但是官方安裝完畢后,這個(gè)部門給的命令是 kill -HUP $MAINPID ,熟悉這PG 這塊的小伙伴,都明白,kill 在對于PG 來說是一個(gè)要了命的命令,所以本文最后會給出更新的部分,咱們不按官方的來。
但是問題又來了,為甚一個(gè)RELOAD的命令本身,在官方的命令里面,是通過 kill 來完成的,而不是我們常用的命令。
這里為避免歧義,特此解釋:
"kill -hup" 是一個(gè)用于發(fā)送 SIGHUP 信號給進(jìn)程的命令。SIGHUP 信號是一種發(fā)送給進(jìn)程的 POSIX 信號,代表終端掛起信號(hangup signal)。
當(dāng)一個(gè)進(jìn)程收到 SIGHUP 信號時(shí),通常會導(dǎo)致該進(jìn)程重新加載配置文件、重新初始化或重新啟動。這通常用于實(shí)現(xiàn)熱重載配置或重新加載程序的功能。
所以說 kill -hup 并不是等同于 kill -9 XXX (兩個(gè)沒有可比性), 他是通過kill命令來給進(jìn)程發(fā)送信號的。
*?Re-read?config?files,?and?tell?children?to?do?same.*/
static?void
process_pm_reload_request(void)
{pending_pm_reload_request?=?false;ereport(DEBUG2,(errmsg_internal("postmaster?received?reload?request?signal")));if?(Shutdown?<=?SmartShutdown){ereport(LOG,(errmsg("received?SIGHUP,?reloading?configuration?files")));ProcessConfigFile(PGC_SIGHUP);SignalChildren(SIGHUP);if?(StartupPID?!=?0)signal_child(StartupPID,?SIGHUP);if?(BgWriterPID?!=?0)signal_child(BgWriterPID,?SIGHUP);if?(CheckpointerPID?!=?0)signal_child(CheckpointerPID,?SIGHUP);if?(WalWriterPID?!=?0)signal_child(WalWriterPID,?SIGHUP);if?(WalReceiverPID?!=?0)signal_child(WalReceiverPID,?SIGHUP);if?(AutoVacPID?!=?0)signal_child(AutoVacPID,?SIGHUP);if?(PgArchPID?!=?0)signal_child(PgArchPID,?SIGHUP);if?(SysLoggerPID?!=?0)signal_child(SysLoggerPID,?SIGHUP);/*?Reload?authentication?config?files?too?*/if?(!load_hba())ereport(LOG,/*?translator:?%s?is?a?configuration?file?*/(errmsg("%s?was?not?reloaded",?HbaFileName)));if?(!load_ident())ereport(LOG,(errmsg("%s?was?not?reloaded",?IdentFileName)));
代碼中,在接受到kill -hup 主進(jìn)程號后,開始針對PG的配置文件,和 PG的 hba 文件和 ident 等部分信息的加載。
下面重寫了相關(guān)的文件,昨天昨天文件的替換
#?It's?not?recommended?to?modify?this?file?in-place,?because?it?will?be
#?overwritten?during?package?upgrades.??It?is?recommended?to?use?systemd
#?"dropin"?feature;??i.e.?create?file?with?suffix?.conf?under
#?/etc/systemd/system/postgresql-14.service.d?directory?overriding?the
#?unit's?defaults.?You?can?also?use?"systemctl?edit?postgresql-14"
#?Look?at?systemd.unit(5)?manual?page?for?more?info.#?Note:?changing?PGDATA?will?typically?require?adjusting?SELinux
#?configuration?as?well.#?Note:?do?not?use?a?PGDATA?pathname?containing?spaces,?or?you?will
#?break?postgresql-14-setup.
[Unit]
Description=PostgreSQL?14?database?server
Documentation=https://www.postgresql.org/docs/14/static/
After=syslog.target
After=network-online.target[Service]
Type=notifyUser=postgres
Group=postgres#?Location?of?database?directory
Environment=PGDATA=/pgdata/data/???#請根據(jù)實(shí)際情況修改你的PG數(shù)據(jù)庫目錄地址到這個(gè)位置
Environment=PGPORT=5432????????????#請根據(jù)實(shí)際情況修改此位置為你的PG的端口號#?StandardOutput=syslog#?Disable?OOM?kill?on?the?postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0#請根據(jù)實(shí)際的情況,來編輯下方的ExecStart=/usr/local/postgres/bin/postmaster?-D?${PGDATA}
ExecStop=/usr/local/postgres/bin/pg_ctl?stop?-D?${PGDATA}?-m?fast
ExecReload=/usr/local/postgres/bin/pg_ctl?reload?-D?${PGDATA}
ExecStatus=/usr/local/postgres/bin/pg_ctl?status?-D?${PGDATA}#ExecReload=/bin/kill?-HUP?$MAINPID
#KillMode=mixed
#KillSignal=SIGINT#?Do?not?set?any?timeout?value,?so?that?systemd?will?not?kill?postmaster
#?during?crash?recovery.
TimeoutSec=0#?0?is?the?same?as?infinity,?but?"infinity"?needs?systemd?229
TimeoutStartSec=0TimeoutStopSec=1h[Install]
WantedBy=multi-user.target
更詳細(xì)的分析和解釋請參加? 德哥相關(guān)文字
https://developer.aliyun.com/article/60259