Skip to content

Files

Latest commit

Dec 15, 2023
f400df2 · Dec 15, 2023

History

History
103 lines (73 loc) · 4.18 KB

20210801_06.md

File metadata and controls

103 lines (73 loc) · 4.18 KB

PostgreSQL 15 preivew - getRecoveryStopReason 打印recovery停止的信息

作者

digoal

日期

2021-08-01

标签

PostgreSQL , 恢复截止信息


背景

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=4fe8dcdff3af73f6ca16eb3edfa3339c7ee0d2c4

Extract code to describe recovery stop reason to a function.  
author	Heikki Linnakangas <heikki.linnakangas@iki.fi>	  
Sat, 31 Jul 2021 06:49:30 +0000 (09:49 +0300)  
committer	Heikki Linnakangas <heikki.linnakangas@iki.fi>	  
Sat, 31 Jul 2021 06:49:30 +0000 (09:49 +0300)  
commit	4fe8dcdff3af73f6ca16eb3edfa3339c7ee0d2c4  
tree	1bc56331e5efc23b6de67f7b096abef8d913e2e1	tree  
parent	6b16532811f07fbb58e4b1b248775acbf9f732a2	commit | diff  
Extract code to describe recovery stop reason to a function.  
  
StartupXLOG() is very long, this makes it a little bit more readable.  
  
Reviewed-by: Andres Freund  
Discussion: https://www.postgresql.org/message-id/b3b71061-4919-e882-4857-27e370ab134a%40iki.fi  

在数据库配置了recovery时, 恢复可截止于指定的xid, time, lsn, targetname, 或者到一致状态后立即停止恢复.

getRecoveryStopReason函数打印恢复截止的信息, 具有更好的可读性.

+/*  
+ * Create a comment for the history file to explain why and where  
+ * timeline changed.  
+ */  
+static char *  
+getRecoveryStopReason(void)  
+{  
+   char        reason[200];  
+  
+   if (recoveryTarget == RECOVERY_TARGET_XID)  
+       snprintf(reason, sizeof(reason),  
+                "%s transaction %u",  
+                recoveryStopAfter ? "after" : "before",  
+                recoveryStopXid);  
+   else if (recoveryTarget == RECOVERY_TARGET_TIME)  
+       snprintf(reason, sizeof(reason),  
+                "%s %s\n",  
+                recoveryStopAfter ? "after" : "before",  
+                timestamptz_to_str(recoveryStopTime));  
+   else if (recoveryTarget == RECOVERY_TARGET_LSN)  
+       snprintf(reason, sizeof(reason),  
+                "%s LSN %X/%X\n",  
+                recoveryStopAfter ? "after" : "before",  
+                LSN_FORMAT_ARGS(recoveryStopLSN));  
+   else if (recoveryTarget == RECOVERY_TARGET_NAME)  
+       snprintf(reason, sizeof(reason),  
+                "at restore point \"%s\"",  
+                recoveryStopName);  
+   else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE)  
+       snprintf(reason, sizeof(reason), "reached consistency");  
+   else  
+       snprintf(reason, sizeof(reason), "no recovery target specified");  
+  
+   return pstrdup(reason);  
+}  
+  

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

digoal's wechat