当前位置: 首页 > news >正文

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

7c9db544e85e6d67156b2602973de604.png

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

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

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

d81833a97a405969275cdf27bb99242a.png

13580199c3b75f6cab503c481325deb4.png

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

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

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

3f21587c2216634f5b0126f658d2541c.png

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

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

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

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

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

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

0a36bfa5cdea2a9b060c6851471ef109.png

* 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 等部分信息的加载。

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

# 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/   #请根据实际情况修改你的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=0TimeoutStopSec=1h[Install]
WantedBy=multi-user.target

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

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

e4d815f178b7b6ce8e3d0c1f02b05803.png

http://www.lryc.cn/news/126951.html

相关文章:

  • vue 使用插件高德地图--vue-amap
  • 减速比如何计算
  • HarmonyOS/OpenHarmony应用开发-ArkTSAPI组件总体分类与说明(下)
  • 势函数和鞅的停时定理
  • 途乐证券-炒股开户流程是怎样的?
  • Eclipse如何设置快捷键
  • 刷享全球美好 中信银行信用卡推出跨境消费系列活动
  • LeetCode算法心得——限制条件下元素之间的最小绝对差(TreeSet)
  • MySQL表的基础操作(crud)
  • vue中的activated和deactivated
  • unity 发布报错 The type or namespace name `UnityEditor‘ could not be found.
  • 在ubuntu中将dict.txt导入到数据库sqlite3
  • nginx 代理postgresql
  • 小程序 CSS-in-JS 和原子化的另一种选择
  • flutter项目 环境搭建
  • PG-DBA培训12:PostgreSQL物理备份与恢复实战
  • 饿了么大数据开发凉经
  • 前端安全:XSS 与 CSRF 安全防御
  • 应用层读取wfp防火墙阻断记录
  • web基础和tomcat的安装,部署jpress应用
  • idea git命令使用
  • 软件测试技术之单元测试—工程师 Style 的测试方法
  • C#学习....
  • C语言暑假刷题冲刺篇——day2
  • springcloud3 hystrix实现服务降级的案例配置2
  • 第 3 章 稀疏数组和队列(1)
  • 7-10 奇偶分家
  • 使用词向量以数学方式查找具有相似含义的单词
  • opencv实现以图搜图
  • 爬虫工作中代理失效了怎么处理?