PostgreSQL timeline

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

关于timeline,有如下的说法

http://www.postgresql.org/docs/current/static/continuous-archiving.html

复制代码
24.3.5. Timelines

The ability to restore the database to a previous point in time creates some complexities that are akin to science-fiction stories about time travel and parallel universes. For example, in the original history of the database, suppose you dropped a critical table at 5:15PM on Tuesday evening, but didn't realize your mistake until Wednesday noon. Unfazed, you get out your backup, restore to the point-in-time 5:14PM Tuesday evening, and are up and running. In this history of the database universe, you never dropped the table. But suppose you later realize this wasn't such a great idea, and would like to return to sometime Wednesday morning in the original history. You won't be able to if, while your database was up-and-running, it overwrote some of the WAL segment files that led up to the time you now wish you could get back to. Thus, to avoid this, you need to distinguish the series of WAL records generated after you've done a point-in-time recovery from those that were generated in the original database history.

To deal with this problem, PostgreSQL has a notion of timelines. Whenever an archive recovery completes, a new timeline is created to identify the series of WAL records generated after that recovery. The timeline ID number is part of WAL segment file names so a new timeline does not overwrite the WAL data generated by previous timelines. It is in fact possible to archive many different timelines. While that might seem like a useless feature, it's often a lifesaver. Consider the situation where you aren't quite sure what point-in-time to recover to, and so have to do several point-in-time recoveries by trial and error until you find the best place to branch off from the old history. Without timelines this process would soon generate an unmanageable mess. With timelines, you can recover to any prior state, including states in timeline branches that you abandoned earlier.

Every time a new timeline is created, PostgreSQL creates a "timeline history" file that shows which timeline it branched off from and when. These history files are necessary to allow the system to pick the right WAL segment files when recovering from an archive that contains multiple timelines. Therefore, they are archived into the WAL archive area just like WAL segment files. The history files are just small text files, so it's cheap and appropriate to keep them around indefinitely (unlike the segment files which are large). You can, if you like, add comments to a history file to record your own notes about how and why this particular timeline was created. Such comments will be especially valuable when you have a thicket of different timelines as a result of experimentation.

The default behavior of recovery is to recover along the same timeline that was current when the base backup was taken. If you wish to recover into some child timeline (that is, you want to return to some state that was itself generated after a recovery attempt), you need to specify the target timeline ID in recovery.conf. You cannot recover into timelines that branched off earlier than the base backup.
复制代码

经过我的实验,发现是这样的,一旦开始第一次的restore,那么就产生了一个交叉点,于是"平行宇宙"诞生了。但是还有一个问题:

参见下图:

如果我当初在A点与B点之间插入数据,又在B点和C点之间插入数据。

然后,在B点所在的时间点处Restore,那么,Timeline2就产生了。

我可以接着在B点和D点至今插入数据,又在D点和E点之间插入数据。

可以说A到B是 timeline2, B到D到E是timeline1。

到达了D点或E点后,我是无法再次Restore到 B点和C点之间了。

这是因为:

B点到C点已经成为不存在了。

(虽然所有的archive wal log我都有,但是某些数据是保留在online wal log中,这部分的数据变化,经过timeline2的处理后,其实是永远失去了)








本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3238700.html,如需转载请自行联系原作者


相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
JavaScript Android开发
AutoJs4.1.0实战教程---js文件打包发布成APK文件
AutoJs4.1.0实战教程---js文件打包发布成APK文件
1753 0
AutoJs4.1.0实战教程---js文件打包发布成APK文件
|
存储 关系型数据库 数据库
用Patroni配置PostgreSQL高可用集群
Patroni是Zalando开发的数据库高可用管理软件,用于编排和自动化PostgreSQL集群的管理过程。Patroni 需要一系列其他组件的支持,通过利用第三方分布式一致性软件,组建并实现数据库高可用方案。
用Patroni配置PostgreSQL高可用集群
|
12月前
|
SQL 存储 数据管理
SQL数据库的使用指南:从入门到精通
随着信息技术的飞速发展,数据库已成为各类企业和组织不可或缺的一部分。作为最流行的数据库管理系统之一,SQL数据库广泛应用于各种场景,如数据存储、数据管理、数据分析等。本文将详细介绍SQL数据库的使用方法,帮助初学者快速入门,并帮助有经验的开发者深化理解。一、SQL数据库基础首先,我们需要理解SQL数
549 2
|
10月前
|
存储 人工智能 自然语言处理
ChatMCP:基于 MCP 协议开发的 AI 聊天客户端,支持多语言和自动化安装 MCP 服务器
ChatMCP 是一款基于模型上下文协议(MCP)的 AI 聊天客户端,支持多语言和自动化安装。它能够与多种大型语言模型(LLM)如 OpenAI、Claude 和 OLLama 等进行交互,具备自动化安装 MCP 服务器、SSE 传输支持、自动选择服务器、聊天记录管理等功能。
2368 16
ChatMCP:基于 MCP 协议开发的 AI 聊天客户端,支持多语言和自动化安装 MCP 服务器
|
SQL 数据库 数据库管理
如何使用Navicat导出数据?
【8月更文挑战第28天】如何使用Navicat导出数据?
3473 6
|
人工智能 自然语言处理 小程序
【工具】Excel竟然也能搞AI,快来玩转chatexcel
ChatExcel是由北京大学团队开发的一款人工智能办公辅助工具,用户可通过自然语言与Excel表格互动,简化数据处理任务,如排序、求和等,无需手动编写公式或函数。本文介绍了ChatExcel的功能特点、使用方法及实操步骤,展示了如何通过简单指令完成复杂操作,提高工作效率。此外,还提供了新手指南帮助快速上手。
1632 0
【工具】Excel竟然也能搞AI,快来玩转chatexcel
|
C语言 芯片 数据格式
C语言课设项目-51单片机-红外通信
C语言课设项目-51单片机-红外通信
252 0
|
XML 数据可视化 定位技术
OpenStreetMap网页界面介绍与OSM数据多种下载渠道及方式对比
OpenStreetMap网页界面介绍与OSM数据多种下载渠道及方式对比
835 1
|
关系型数据库 API 数据库
基于Patroni的PostgreSQL高可用环境部署
在部署PostgreSQL到生产环境中时,选择适合的高可用方案是一项必不可少的工作。本文介绍基于Patroni的PostgreSQL高可用的部署方法,供大家参考。
7676 1
|
域名解析 网络协议 安全
【内网安全-隧道技术】SMB、ICMP、DNS隧道、SSH协议
【内网安全-隧道技术】SMB、ICMP、DNS隧道、SSH协议
1569 0
【内网安全-隧道技术】SMB、ICMP、DNS隧道、SSH协议