lightdb 支持 timestamp_to_scn 和 ora_rowscn

背景

Oracle 的 timestamp_to_scn 函数能根据时间戳返回一个 SCN(System Change Number).
scn 与事务有关,当系统有事务提交后,最新的 scn 就会变更成一个更大的值。
ORA_ROWSCN 在 Oracle 中记录了每一行提交后的 scn.

在 LightDB 中,scn 被替换成 xid, 即事务ID. 该功能自 LightDB 24.1 后可以使用。

样例

在 LightDB 中使用 timestamp_to_scn 和 ORA_ROWSCN 需要开启 GUC 配置 track_commit_timestamp. 该配置更改后,需要重启 lightdb.

show track_commit_timestamp;
 track_commit_timestamp
------------------------
 on
(1 row)

获取最新的 scn,
ps: sysdate 函数需要配置对应的 GUC 参数 orafce.timezone 为系统的 timezone 参数。详情见这

set orafce.timezone = 'Asia/Shanghai';
select timestamp_to_scn(sysdate) from dual;
 timestamp_to_scn
------------------
          5288085
(1 row)

对于 ORA_ROWSCN, 在 LigthtDB 的 Oracle 模式,是一个非保留关键字,

create table foo(a int);
insert into foo values (1);
select ora_rowscn, xmin from foo;
 ora_rowscn |  xmin
------------+---------
    5288454 | 5288454
(1 row)

posted on 2024-03-12 16:17  winter-loo  阅读(20)  评论(0编辑  收藏  举报

导航