PostgreSQL源码分析——pg_archivecleanup

pg_archivecleanup用于清理PostgreSQL WAL归档文件。指定归档目录,指定一个最老的日志段文件(在此之前的WAL日志都删掉), 用法如下:

postgres@slpc:~$ pg_archivecleanup --help
pg_archivecleanup removes older WAL files from PostgreSQL archives.Usage:pg_archivecleanup [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILEOptions:-d             generate debug output (verbose mode)-n             dry run, show the names of the files that would be removed-V, --version  output version information, then exit-x EXT         clean up files if they have this extension-?, --help     show this help, then exitFor use as archive_cleanup_command in postgresql.conf:archive_cleanup_command = 'pg_archivecleanup [OPTION]... ARCHIVELOCATION %r'
e.g.archive_cleanup_command = 'pg_archivecleanup /mnt/server/archiverdir %r'Or for use as a standalone archive cleaner:
e.g.pg_archivecleanup /mnt/server/archiverdir 000000010000000000000010.00000020.backup

可参考文档:http://www.postgres.cn/docs/14/pgarchivecleanup.html

源码分析

源码不多,在pg_archivecleanup.c中。

main(int argc, char **argv)
--> Initialize();	// 检查归档目录是否有效
--> SetWALFileNameForCleanup();		// 检查the oldest file we want to remain in archive是否有效
--> CleanupPriorWALFiles();  // 具体的清理归档日志

清理的代码实现如下:

static void CleanupPriorWALFiles(void)
{int			rc;DIR		   *xldir;struct dirent *xlde;char		walfile[MAXPGPATH];if ((xldir = opendir(archiveLocation)) != NULL){while (errno = 0, (xlde = readdir(xldir)) != NULL){strlcpy(walfile, xlde->d_name, MAXPGPATH);TrimExtension(walfile, additional_ext);// 比较的时候,忽略时间线,/** We ignore the timeline part of the XLOG segment identifiers in* deciding whether a segment is still needed.  This ensures that* we won't prematurely remove a segment from a parent timeline.* We could probably be a little more proactive about removing* segments of non-parent timelines, but that would be a whole lot* more complicated.** We use the alphanumeric sorting property of the filenames to* decide which ones are earlier than the exclusiveCleanupFileName* file. Note that this means files are not removed in the order* they were originally written, in case this worries you.*/if ((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) &&strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0){char		WALFilePath[MAXPGPATH * 2]; /* the file path* including archive *//** Use the original file name again now, including any* extension that might have been chopped off before testing* the sequence.*/snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s",archiveLocation, xlde->d_name);if (dryrun){/** Prints the name of the file to be removed and skips the* actual removal.  The regular printout is so that the* user can pipe the output into some other program.*/printf("%s\n", WALFilePath);pg_log_debug("file \"%s\" would be removed", WALFilePath);continue;}pg_log_debug("removing file \"%s\"", WALFilePath);rc = unlink(WALFilePath);if (rc != 0)pg_fatal("could not remove file \"%s\": %m",WALFilePath);}}if (errno)pg_fatal("could not read archive location \"%s\": %m",archiveLocation);if (closedir(xldir))pg_fatal("could not close archive location \"%s\": %m",archiveLocation);}elsepg_fatal("could not open archive location \"%s\": %m",archiveLocation);
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/30079.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HDU——2090.算菜价、2091.空心三角形、2093.考试排名

2090.算菜价 题目描述 Problem - 2090 Problem Description 妈妈每天都要出去买菜&#xff0c;但是回来后&#xff0c;兜里的钱也懒得数一数&#xff0c;到底花了多少钱真是一笔糊涂帐。现在好了&#xff0c;作为好儿子&#xff08;女儿&#xff09;的你可以给她用程序算一…

理解前端Cookie中的SameSite属性

SameSite属性是一个相对较新的Cookie属性&#xff0c;它可以帮助防止跨站请求伪造&#xff08;CSRF&#xff09;攻击。SameSite属性用于声明Cookie是否可以在跨站点情况下发送。 SameSite属性有三个可选值&#xff1a;Strict&#xff0c;Lax和None。 SameSiteStrict&#xff1…

Idea Git 解决Filename too long的问题

问题描述&#xff1a; 从远程厂库拉取代码以后&#xff0c;可能是被人的文件名字太长了&#xff0c;本地显示文件已经被删除。 原因&#xff1a; Windows系统下&#xff0c;在Git使用过程中&#xff0c;出现“filename too long”错误提示。直译成中文的意思就是&#xff1a;”…

Adobe XD是否收费?试试这几款超值的免费软件吧!

Adobe XD是一站式的 UX/UI 设计平台&#xff0c;设计师可以使用Adobe XD完成移动应用app界面设计、网页设计、原型设计等。Adobe XD也是一款结合原型和设计&#xff0c;提供工业性能的跨平台设计产品。而Adobebe。 XD跨平台的特点得到了很好的弥补 Sketch 没有 Windows 版本的缺…

网安人必备!开源网络安全工具TOP 10(附下载地址)

工欲善其事&#xff0c;必先利其器。对于广大的网络安全从业者&#xff0c;以及未来想要从事网络安全的人来说&#xff0c;选择并善用合适的网络安全工具&#xff0c;能有效提升工作效率。 开源网络安全工具之所以能够在众多安全解决方案中脱颖而出&#xff0c;不仅是因为它们…

C++ 68 之 类模版作函数的参数

#include <iostream> // #include <cstring> #include <string> using namespace std;template<class T1, class T2> // 可以设置默认的类型值&#xff0c;后面在使用的时候&#xff0c;就不用再指定类型了 class Students08{ public:T1 m_name;T2 m_a…

SysTools MailXaminer: 电子邮件取证调查中的链接分析和时间线分析

天津鸿萌科贸发展有限公司是 SysTools 系列软件的授权代理商。 SysTools MailXaminer 电子邮件取证软件提供全面强大的解决方案&#xff0c;通过简化的操作&#xff0c;从电子邮件客户端、网络邮箱服务器、磁盘镜像、Skype 通讯工具中解密并搜索证据。软件对调查工作的每一阶段…

c++参考std::string自己设计类hstring

目录 一、前言 二、设计需求 三、设计思想 1.功能一 1.功能二 四、设计过程 1.类hstring搭建 2. 实现有参构造函数 3. 实现副本构造函数 4.完整代码 五、结束语 一、前言 在c中有很多的库&#xff0c;但是在有些时候呢&#xff0c;我们一定要学会自己去设计库&#…

PHP框架之symfony框架

Symfony框架详解 Symfony是一个由SensioLabs公司开发并维护的PHP框架&#xff0c;旨在提高开发效率、代码复用性和应用的可维护性。自2005年发布以来&#xff0c;Symfony已成为众多开发者的首选框架之一&#xff0c;尤其在构建复杂的Web应用程序方面表现出色。 主要特点 高效…

文件扫描工具都有哪些?职场大佬都在用的文本提取工具大盘点~

回想起刚毕业初入职场那阵子&#xff0c;领导让帮忙把纸质文件扫描提取为文本时&#xff0c;还只会傻乎乎地一点点操作&#xff0c;属实是费劲得很&#xff01; 好在后面受朋友安利&#xff0c;找到了4个能够快速实现文件扫描文字提取的方法&#xff0c;这才让我的办公效率蹭蹭…

关于自学\跳槽\转行做网络安全行业的一些建议

很好&#xff0c;如果你是被题目吸引过来的&#xff0c;那请看完再走&#xff0c;还是有的~ 为什么写这篇文章 如何自学入行&#xff1f;如何小白跳槽&#xff0c;年纪大了如何转行等类似问题 &#xff0c;发现很多人都有这样的困惑。下面的文字其实是我以前的一个回答&#…

当site-packages的类型为.so,Python解释器不会提示或列出该模块可用的函数和类的原因及解决方法

原因&#xff1a; 当你在Python中导入一个.so文件&#xff08;或者任何扩展模块&#xff09;时&#xff0c;如果它不提供任何Python级别的接口或文档&#xff0c;Python解释器通常不会提示或列出可用的函数和类。这是因为扩展模块可能是用C语言编写的&#xff0c;并且它们通常…

MyBatis-For input string: “oqm“ 异常

前言 具体的异常信息如下&#xff1a; Error attempting to get column open_id from result set. Cause: java.lang.NumberFormatException: For input string: "oqmJX5ZPU1KOv-YDt30GNAN-Zefk" 乍一看下其实就是无法把open_id字符串类型转为数字类型进行赋值&…

Elasticsearch RestclientApi基础用法

Elasticsearch RestclientApi基础用法 索引 初始化 添加依赖 <dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId> </dependency>创建链接 package com.hmall.i…

synchronized原理

当线程释放锁&#xff0c;JMM会把线程对应的本地的内存中的共享变量刷新到内存中 当线程获取锁&#xff0c;JMM会帮其他线程中对应的本地的内存中的共享变量设置未无效&#xff0c;从而监视器保护的临界区的代码必须从内存中读取共享变量。&#xff08;临界区为锁之间的代码&am…

3D模型可视化引擎HOOPS Communicator与Visualize的统一化文件加载解决方案

在当今数字化时代&#xff0c;3D可视化技术已成为工程设计、建筑规划和游戏开发等多个领域的核心技术。Tech Soft 3D公司凭借其创新的HOOPS Communicator和HOOPS Visualize两款开发包&#xff0c;分别针对Web端和桌面端提供了强大的3D可视化解决方案。然而&#xff0c;由于两者…

第三集《唯识与净土》

和尚尼慈悲&#xff01;诸位法师、诸位居士&#xff0c;阿弥陀佛&#xff01; 请大家打开讲义第六面&#xff0c;三、业果强弱。 我们身为一个有情众生&#xff0c;在我们的生命当中&#xff0c;我们曾经出现过很多痛苦的果报&#xff0c;当然也出现过很多安乐的果报&#xff0…

c语言回顾-结构体(2)

前言 前面讲了结构体的概念&#xff0c;定义&#xff0c;赋值&#xff0c;访问等知识&#xff0c;本节内容小编将讲解结构体的内存大小的计算以及通过结构体实现位段&#xff0c;话不多说&#xff0c;直接上干货&#xff01;&#xff01;&#xff01; 1.结构体内存对齐 说到计…

物联网技术-第3章物联网感知技术-3.2定位技术

目录 1.1位置信息和位置服务 1.1.1位置信息 1.1.2位置服务 1.2主流定位系统 1.2.1卫星定位系统&#xff08;Satellite Positioning Systems&#xff09; 1.2.2移动通信蜂窝基站定位&#xff08;Cellular Triangulation or Advanced Forward Link Trilateration&#xff09…

大学物理绪论组收集和分析

目录 ​编辑 随机误差的估计 算术平均值的标准偏差 不确定度&#xff08;Uncertainty&#xff09;是测量学中的一个重要概念&#xff0c;用于表示测量结果的可靠程度。它反映了测量值可能偏离真值&#xff08;即被测量的客观真实值&#xff09;的程度。 A类不确定度的计算方…