为什么 txid 会增加?

Why does the txid increment?

我有以下脚本:

select txid_current();

显示的txid为=001

begin;
insert into tab values(10,20); insert into values(20,40);
commit;

现在当我这样做时: select txid_current();

txid 看到的是:004 为什么会有 2 的增量,即为什么 txid 增加 2 不应该增量只是 1,即 txid 应该是 003 不应该 select txid_current() 显示 003 吗?

有没有办法将 003 显示为当前 txid()?

Transaction

PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. A group of statements surrounded by BEGIN and COMMIT is sometimes called a transaction block.

这意味着当你 运行 select txid_current(); 你在交易中,然后 运行 你得到新的交易 ID。

begin;
select txid_current(); // 1
end;

begin;
insert into tab values(10,20); insert into values(20,40);
select txid_current(); // 2
commit;

begin;
select txid_current(); // 3
end;