時間:2024-02-03 17:42作者:下載吧人氣:21
前陣子某個客戶反饋他的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 內(nèi)部的事務(wù)編號,每個事務(wù)都會分配一個XID,依次遞增。PostgreSQL 數(shù)據(jù)中每個元組頭部都會保存著 插入 或者 刪除 這條元組的XID(Transaction ID),然后內(nèi)核通過這個 XID 構(gòu)造數(shù)據(jù)庫的一致性讀。在事務(wù)隔離級別是 可重復(fù)讀 的情況下,假設(shè)如有兩個事務(wù),xid1=200,xid2=201,那么 xid1 中只能看到 t_xmin <= 200 的元組,看不到 t_xmin > 200 的元組。
typedef uint32 TransactionId; /* 事務(wù)號定義,32位無符號整數(shù) */ /*** 其它屬性省略 ***/
} HeapTupleFields;
struct HeapTupleHeaderData
{
union
{
HeapTupleFields t_heap;
DatumTupleFields t_datum;
} t_choice;
/*** 其它屬性省略 ***/
};
網(wǎng)友評論