時間:2024-02-03 17:42作者:下載吧人氣:23
前陣子某個客戶反饋他的RDS PostgreSQL無法寫入,報錯信息如下:
postgres=# select * from test;
id
—-
(0 rows)postgres=# insert into test select 1;
ERROR: database is not accepting commands to avoid wraparound data loss in database "xxxx"
HINT: Stop the postmaster and vacuum that database in single-user mode.
You might also need to commit or roll back old prepared transactions.
隨后RDS工程師介入處理以后,該問題立馬得到了解決。
XID(Transaction ID)是 PostgreSQL 內部的事務編號,每個事務都會分配一個XID,依次遞增。PostgreSQL 數據中每個元組頭部都會保存著 插入 或者 刪除 這條元組的XID(Transaction ID),然后內核通過這個 XID 構造數據庫的一致性讀。在事務隔離級別是 可重復讀 的情況下,假設如有兩個事務,xid1=200,xid2=201,那么 xid1 中只能看到 t_xmin <= 200 的元組,看不到 t_xmin > 200 的元組。
typedef uint32 TransactionId; /* 事務號定義,32位無符號整數 */ /*** 其它屬性省略 ***/
} HeapTupleFields;
struct HeapTupleHeaderData
{
union
{
HeapTupleFields t_heap;
DatumTupleFields t_datum;
} t_choice;
/*** 其它屬性省略 ***/
};
網友評論