向bgwriter 发送 SIGQUIT 的实验

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介:

bgwriter.c 的代码中有如下部分:

    pqsignal(SIGQUIT, bg_quickdie);        /* hard crash time */

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

还有:

复制代码
/*
 * bg_quickdie() occurs when signalled SIGQUIT by the postmaster.
 *
 * Some backend has bought the farm,
 * so we need to stop what we're doing and exit.
 */
static void
bg_quickdie(SIGNAL_ARGS)
{
    PG_SETMASK(&BlockSig);

    /*
     * We DO NOT want to run proc_exit() callbacks -- we're here because
     * shared memory may be corrupted, so we don't want to try to clean up our
     * transaction.  Just nail the windows shut and get out of town.  Now that
     * there's an atexit callback to prevent third-party code from breaking
     * things by calling exit() directly, we have to reset the callbacks
     * explicitly to make this work as intended.
     */
    on_exit_reset();

    /*
     * Note we do exit(2) not exit(0).    This is to force the postmaster into a
     * system reset cycle if some idiot DBA sends a manual SIGQUIT to a random
     * backend.  This is necessary precisely because we don't clean up our
     * shared memory state.  (The "dead man switch" mechanism in pmsignal.c
     * should ensure the postmaster sees this as a crash, too, but no harm in
     * being doubly sure.)
     */
    exit(2);
}
复制代码

我是这样实验的:

首先个给 bgwriter.c 的 pg_quickdie,加入一小段代码,变成:

复制代码
/*
 * bg_quickdie() occurs when signalled SIGQUIT by the postmaster.
 *
 * Some backend has bought the farm,
 * so we need to stop what we're doing and exit.
 */
static void
bg_quickdie(SIGNAL_ARGS)
{
fprintf(stderr,"bg_quickdie happend.\n"); PG_SETMASK(
&BlockSig); /* * We DO NOT want to run proc_exit() callbacks -- we're here because * shared memory may be corrupted, so we don't want to try to clean up our * transaction. Just nail the windows shut and get out of town. Now that * there's an atexit callback to prevent third-party code from breaking * things by calling exit() directly, we have to reset the callbacks * explicitly to make this work as intended. */ on_exit_reset(); /* * Note we do exit(2) not exit(0). This is to force the postmaster into a * system reset cycle if some idiot DBA sends a manual SIGQUIT to a random * backend. This is necessary precisely because we don't clean up our * shared memory state. (The "dead man switch" mechanism in pmsignal.c * should ensure the postmaster sees this as a crash, too, but no harm in * being doubly sure.) */ exit(2); }
复制代码

然后,我启动 postgreSQL ,并查看进程状态:

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data
LOG:  database system was shut down at 2012-10-31 10:25:11 CST
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
复制代码
[root@localhost postgresql-9.2.0]# ps -ef|grep post
root      2928  2897  0 10:34 pts/1    00:00:00 su - postgres
postgres  2929  2928  0 10:34 pts/1    00:00:00 -bash
postgres  2967  2929  0 10:34 pts/1    00:00:00 ./postgres -D /usr/local/pgsql/data
postgres  2969  2967  0 10:34 ?        00:00:00 postgres: checkpointer process     
postgres  2970  2967  0 10:34 ?        00:00:00 postgres: writer process           
postgres  2971  2967  0 10:34 ?        00:00:00 postgres: wal writer process       
postgres  2972  2967  0 10:34 ?        00:00:00 postgres: autovacuum launcher process   
postgres  2973  2967  0 10:34 ?        00:00:00 postgres: stats collector process   
root      3000  2977  0 10:35 pts/2    00:00:00 grep post
[root@localhost postgresql-9.2.0]# 
复制代码

然后,向 bgwriter 发送 SIGQUIT 信号:

[root@localhost postgresql-9.2.0]# kill -s SIGQUIT 2970

这个时候,我们会从pts/1 中看到什么?

复制代码
bg_quickdie happend.
LOG:  background writer process (PID 2970) exited with exit code 2
LOG:  terminating any other active server processes
WARNING:  terminating connection because of crash of another server process
DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

HINT:  In a moment you should be able to reconnect to the database and repeat your command.
LOG:  all server processes terminated; reinitializing
LOG:  database system was interrupted; last known up at 2012-10-31 10:34:47 CST
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  record with zero length at 0/192D458
LOG:  redo is not required
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
复制代码

也就是说,bgwriter 捕获了SIGQUIT 的信号,而Postmaster/postgres 重新启动了各个子进程!

再看 ps 来验证一下:

复制代码
[root@localhost postgresql-9.2.0]# ps -ef|grep post
root      2928  2897  0 10:34 pts/1    00:00:00 su - postgres
postgres  2929  2928  0 10:34 pts/1    00:00:00 -bash
postgres  2967  2929  0 10:34 pts/1    00:00:00 ./postgres -D /usr/local/pgsql/data
postgres  3002  2967  0 10:35 ?        00:00:00 postgres: checkpointer process     
postgres  3003  2967  0 10:35 ?        00:00:00 postgres: writer process           
postgres  3004  2967  0 10:35 ?        00:00:00 postgres: wal writer process       
postgres  3005  2967  0 10:35 ?        00:00:00 postgres: autovacuum launcher process   
postgres  3006  2967  0 10:35 ?        00:00:00 postgres: stats collector process   
root      3010  2977  0 10:36 pts/2    00:00:00 grep post
[root@localhost postgresql-9.2.0]# 
复制代码
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
存储 OLAP OLTP
漫谈OceanBase 列式存储
列式存储主要的目的有两个: 大部分OLAP查询只需要读取部分列而不是全部列数据,列式存储可以避免读取无用数据; 将同一列的数据在物理上存放在一起,能够极大地提高数据压缩率。 OLAP和OLTP OLAP,也叫联机分析处理(Online Analytical Processing)系统,有的时候也叫DSS决策支持系统,就是我们说的数据仓库。
6567 0
|
2月前
|
存储 缓存 固态存储
固态硬盘为什么会出现故障?
近年来,固态硬盘(SSD)因速度快广受用户青睐,但使用中也出现故障频发的问题,如开机异常、数据丢失、系统卡顿等。本文解析SSD故障原因,包括寿命限制、主控设计缺陷、电压波动、固件问题等,并提供数据抢救方法与延长SSD寿命的实用技巧,助你避免数据丢失风险。
|
人工智能
【MCP教程系列】阿里云百炼xChatPPT,5分钟轻松搞定PPT
通过阿里云百炼平台结合ChatPPT,只需简单四步即可快速生成专业PPT。
2393 0
|
3月前
|
监控 Linux C#
《C#与.NET Core跨平台开发的融合架构与实践逻辑》
本文深入解析了利用C#与.NET Core开发跨平台桌面应用的核心逻辑,探讨如何突破操作系统壁垒实现文件管理、图像处理和系统监控等功能的统一体验。阐述了.NET Core对不同系统底层差异的抽象与适配,包括文件系统规则的转化、图形硬件调用的平衡、系统内核信息的解读,以及C#语言特性在跨平台开发中的互补作用。强调跨平台开发需培养“系统无关”的抽象思维,通过技术融合实现功能逻辑与用户体验的跨平台一致性,重塑桌面应用的开发边界。
|
存储 分布式计算 算法
基于 Log 的通用增量 Checkpoint
本文将从 Checkpoint 的性能优化历程出发,介绍 ChangelogStateBackend 的基本机制、应用场景和未来规划,同时介绍最新版本在 State 上的一些优化工作。
7654 2
基于 Log 的通用增量 Checkpoint
|
7天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
6天前
|
存储 人工智能 Java
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话
本文讲解 Prompt 基本概念与 10 个优化技巧,结合学术分析 AI 应用的需求分析、设计方案,介绍 Spring AI 中 ChatClient 及 Advisors 的使用。
318 130
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话