POSTGRESQL 关于2023-08-14 数据库自动启动文章中使用KILL 来进行配置RELOAD的问题解释...

开头还是介绍一下群,如果感兴趣Polardb ,mongodb ,MySQL ,Postgresql ,redis ,SQL SERVER ,ORACLE,Oceanbase 等有问题,有需求都可以加群群内有各大数据库行业大咖,CTO,可以解决你的问题。加群请加 liuaustin3微信号 ,在新加的朋友会分到3群(共1170人左右 1 + 2 + 3)

首先道歉,昨天关于POSTGRESQL 的文章中的部分内容个人觉得有误导的部分或者说没有解释清楚的地方。虽然相关的部分是官方的提供的相关的文件,特通过此文更新相关的内容。

在上一篇文章中,有这样一个部分

因为这个地方有不同的意见

1 实际上这块的部分代表了reload 的部分,而通常我们撰写这块的方式是

ExecReload=/usr/local/postgres/bin/pg_ctl reload -D ${PGDATA}

但是官方安装完毕后,这个部门给的命令是 kill -HUP $MAINPID ,熟悉这PG 这块的小伙伴,都明白,kill 在对于PG 来说是一个要了命的命令,所以本文最后会给出更新的部分,咱们不按官方的来。

但是问题又来了,为甚一个RELOAD的命令本身,在官方的命令里面,是通过 kill 来完成的,而不是我们常用的命令。

这里为避免歧义,特此解释:

"kill -hup" 是一个用于发送 SIGHUP 信号给进程的命令。SIGHUP 信号是一种发送给进程的 POSIX 信号,代表终端挂起信号(hangup signal)。

当一个进程收到 SIGHUP 信号时,通常会导致该进程重新加载配置文件、重新初始化或重新启动。这通常用于实现热重载配置或重新加载程序的功能。

所以说 kill -hup 并不是等同于 kill -9 XXX (两个没有可比性), 他是通过kill命令来给进程发送信号的。

go 复制代码
* 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 主进程号后,开始针对PG的配置文件,和 PG的 hba 文件和 ident 等部分信息的加载。

下面重写了相关的文件,昨天昨天文件的替换

go 复制代码
# 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=notify

User=postgres
Group=postgres


# Location of database directory
Environment=PGDATA=/pgdata/data/   #请根据实际情况修改你的PG数据库目录地址到这个位置
Environment=PGPORT=5432            #请根据实际情况修改此位置为你的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

#请根据实际的情况,来编辑下方的

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=0

TimeoutStopSec=1h

[Install]
WantedBy=multi-user.target

更详细的分析和解释请参加 德哥相关文字

https://developer.aliyun.com/article/60259

相关推荐
辉灰笔记17 小时前
MySQL8 意外关机/误移data目录导致服务启动失败 PID报错/权限报错 修复文档
linux·数据库·mysql·centos
麦聪聊数据18 小时前
电商大促数据库管控(下):数据需求小时级交付与全链路安全管控
数据库
喜欢的名字被抢了18 小时前
MySQL核心机制:事务、锁与存储引擎
数据库·sql·mysql·教程
JosieBook19 小时前
【数据库】时序数据库通过国测认证,TimechoAI开放体验:工业数据的“存”与“智”如何协同?
数据库·时序数据库
卓怡学长19 小时前
w263基于springboot + vue 健康饮食管理系统
java·数据库·vue.js·spring boot·spring·intellij-idea
阿演21 小时前
DataDjinn v0.2.11:SQL 编辑、AI 协作和表格操作继续打磨
数据库·人工智能·sql
智脑API平台1 天前
Codex 国内使用会封号吗?账号安全、中转站和合规边界说明
数据库·redis·缓存
l1t1 天前
duckdb 1.6dev新增的.manual命令
开发语言·数据库
辉灰笔记1 天前
第一篇:MySQL8.0生产备份实战|XtraBackup全自动全量+增量备份(钉钉告警+异地Binlog归档)
数据库·mysql·钉钉·运维开发
山峰哥1 天前
‌Explain实战:打开数据库执行计划的黑盒‌
大数据·服务器·数据库·sql·深度优先·宽度优先