txid_snapshot的文本表示为:xmin:xmax:xip_list。

    名称       描述                                      xmin        最早的事务ID(txid)仍然活动。所有较早事务将是已经提交可见的,或者是直接回滚。xmax     作为尚未分配的txid。所有大于或等于此txids的都是尚未开始的快照时间,因此不可见。xip_list 当前快照中活动的txids。这个列表只包含在xmin和xmax之间活动的txids;有可能活动的txids高于xmax。 介于大于等于xmin、小于xmax,并且不在这个列表中的txid,在这个时间快照已经完成的,因此按照提交状态查看他是可见还是回滚。这个列表不包含子事务的txids。

示例:10:20:10,13,15意思为:xmin=10, xmax=20, xip_list=10, 13, 15。

测试如下:

1.通过设置强制对临时对象使用COMMIT而不是2PC

SET enforce_two_phase_commit TO off;

2.正常案例演示

 postgres=# select '12:13:'::txid_snapshot;##  txid_snapshot12:13:(1 row)postgres=# select '12:18:14,16'::txid_snapshot;##  txid_snapshot12:18:14,16(1 row)

3.错误案例演示

 postgres=# select '31:12:'::txid_snapshot;ERROR:  invalid input for txid_snapshot: "31:12:"LINE 1: select '31:12:'::txid_snapshot;^CONTEXT:  referenced column: txid_snapshot
-------------------------------------------------------------------------------
 postgres=# select '0:1:'::txid_snapshot;ERROR:  invalid input for txid_snapshot: "0:1:"LINE 1: select '0:1:'::txid_snapshot;^CONTEXT:  referenced column: txid_snapshot
-------------------------------------------------------------------------------
postgres=# select '12:13:0'::txid_snapshot;ERROR:  invalid input for txid_snapshot: "12:13:0"LINE 1: select '12:13:0'::txid_snapshot;^CONTEXT:  referenced column: txid_snapshot
-------------------------------------------------------------------------------
 postgres=# select '12:16:14,13'::txid_snapshot;ERROR:  invalid input for txid_snapshot: "12:16:14,13"LINE 1: select '12:16:14,13'::txid_snapshot;^CONTEXT:  referenced column: txid_snapshot
-------------------------------------------------------------------------------
postgres=# select '12:16:14,14'::txid_snapshot;ERROR:  invalid input for txid_snapshot: "12:16:14,14"LINE 1: select '12:16:14,14'::txid_snapshot;^CONTEXT:  referenced column: txid_snapshot

通过测试看出xmax应该大于xmin,不可为0,tixds应该按增序排列,且不为0,并且不能有重复的tixds,在使用的时候应当尽量避免。

4.创建测试表及测试数据导入

 postgres=# create temp table snapshot_test(nr integer,snap txid_snapshot);CREATE TABLEpostgres=# insert into snapshot_test values (1, '12:13:');INSERT 0 1postgres=# insert into snapshot_test values (2, '12:20:13,15,18');INSERT 0 1postgres=# insert into snapshot_test values (3, '100001:100009:100005,100007,100008');INSERT 0 1postgres=# insert into snapshot_test values (4, '100:150:101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131');INSERT 0 1

查询数据情况:

postgres=# select snap from snapshot_test order by nr;snap-------------------------------------------------------------------------------------------------------------------------------------12:13:12:20:13,15,18100001:100009:100005,100007,100008100:150:101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131(4 rows)

5.函数测试

txid_snapshot_xmin()为会返回快照的xmin,

txid_snapshot_xmax()会返回快照的xmax,

txid_snapshot_xip()获取正在进行的事务ip,即txids。

postgres=# select  txid_snapshot_xmin(snap),postgres-# txid_snapshot_xmax(snap),postgres-# txid_snapshot_xip(snap)postgres-# from snapshot_test order by nr, 1, 2, 3;txid_snapshot_xmin | txid_snapshot_xmax | txid_snapshot_xip--------------------+--------------------+-------------------12 |                 20 |                1312 |                 20 |                1512 |                 20 |                18100001 |             100009 |            100005100001 |             100009 |            100007100001 |             100009 |            100008100 |                150 |               101100 |                150 |               102100 |                150 |               103100 |                150 |               104100 |                150 |               105

txid_visible_in_snapshot()会查看在快照中事务ID是否可见(不使用子事务ID)

postgres=# select id, txid_visible_in_snapshot(id, snap)postgres-# from snapshot_test, generate_series(11, 21) idpostgres-# where nr = 2;id | txid_visible_in_snapshot----+--------------------------11 | t12 | t13 | f14 | t15 | f16 | t17 | t18 | f19 | t20 | f21 | f(11 rows)

6.其他测试

测试二分查找

    postgres=# select id, txid_visible_in_snapshot(id, snap)postgres-# from snapshot_test, generate_series(90, 160) idpostgres-# where nr = 4;id  | txid_visible_in_snapshot-----+--------------------------90 | t91 | t92 | t93 | t94 | t95 | t96 | t97 | t98 | t99 | t100 | t101 | f

测试当前值

    postgres=# select txid_current() >= txid_snapshot_xmin(txid_current_snapshot());##  ?column?t(1 row)

我们不能假设当前值总是小于xmax

    postgres=# select txid_visible_in_snapshot(txid_current(), txid_current_snapshot());##  txid_visible_in_snapshotf(1 row)

测试64bitness(MOGDB/openGauss将transactionid由int32改为了int64,64位的xid永远不可能耗尽,虽然xid改为了64位,但是过期的xid依旧需要freeze清理,只是永远不用担心会发生xid回卷宕机的风险。 )

    postgres=# select txid_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100010001013';##   txid_snapshot1000100010001000:1000100010001100:1000100010001012,1000100010001013(1 row)postgres=# select txid_visible_in_snapshot('1000100010001012', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');##  txid_visible_in_snapshotf(1 row)postgres=# select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');##  txid_visible_in_snapshott(1 row)

测试溢出64bit,9223372036854775807是是263-1,是乘方 也就是63位的最大二进制数字 。

    postgres=# SELECT txid_snapshot '1:9223372036854775807:3';##       txid_snapshot1:9223372036854775807:3(1 row)postgres=# SELECT txid_snapshot '1:9223372036854775808:3';ERROR:  invalid input for txid_snapshot: "1:9223372036854775808:3"LINE 1: SELECT txid_snapshot '1:9223372036854775808:3';^CONTEXT:  referenced column: txid_snapshot

【MOGDB/openGauss的txid_snapshot 数据类型和相关函数】相关推荐

  1. 【参赛作品65】MOGDB/openGauss的txid_snapshot 数据类型和相关函数

    作者:阎书利 txid_snapshot的文本表示为:xmin:xmax:xip_list. 名称 描述 xmin 最早的事务ID(txid)仍然活动.所有较早事务将是已经提交可见的,或者是直接回滚. ...

  2. 【参赛作品70】MOGDB/openGauss与PostgreSQL关于GDK字符集问题

    作者:阎书利 最近,在验证不同字符集数据类型存储数据位数的时候发现: PG12不支持server_encoding=GBK.以及MOGDB/openGauss 2.0.1 build d97c0e8a ...

  3. MogDB/openGauss 生态工具-MTK(Migration ToolKit) 数据库迁移

    点击上方"蓝字" 关注我们,享更多干货! 一.准备环境 1. 源库创建(Oracle) 创建Oracle 11.2.0.4 docker pull registry.cn-hang ...

  4. MogDB/openGauss 教程 浓缩版

    概述 MogDB是EnMotech openGauss DataBase Enterprise Edition的缩写,是云和恩墨基于openGauss开源数据库进行定制.推出的企业发行版.它将围绕高可 ...

  5. 【MogDB/openGauss与PG的repmgr对比】

    提到PG的repmgr,大家可能并不陌生,他是现在PG比较流行的一套开源工具,用于管理PostgreSQL服务器集群中的复制管理和故障转移,也就是相当于一个集群管理+HA工具.当前PG的高可用方案,大 ...

  6. MogDB/openGauss 手动部署(非OM工具)单机、主备、主备级联架构

    点击上方"蓝字" 关注我们,享更多干货! 一.前期准备 1. 关闭防火墙,selinux systemctl disable firewalld.service systemctl ...

  7. 【参赛作品31】ODBC驱动连接MogDB/openGauss

    作者:2020 一.环境说明 [root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) 二.unixOD ...

  8. MogDB/openGauss 故障排查思路

    点击上方"蓝字" 关注我们,享更多干货! 前提 当我们收到反馈说数据库响应慢或者压测过程中数据库有报错,第一步先收集数据库服务器资源使用情况,这一步是处理所有故障的前提. --负载 ...

  9. 【openGauss/MogDB的uncommitted xmin问题解决】

    一.问题现象 在测试openGauss/MogDB的时候,发现主库查询snapshot.tables_snap_timestamp这个表的时候,一select *,数据库就宕机,而备库是正常的.因为是 ...

最新文章

  1. oracle与mysql创建表时的区别
  2. R语言使用lubridate包的tz函数设置和查询日期、时间对象的时区信息( time zone)
  3. 社会关系分析_【图文】室外游乐设施典型案例优势分析
  4. 【深度思考】javaweb框架技术心得
  5. f450四轴使用技巧
  6. LeetCode 1681. 最小不兼容性(回溯+剪枝)
  7. Python 图片与字符串互转
  8. 软件工程复习提纲——第三章
  9. Windows7中右键菜单无新建文本文档选项的解决办法(注册表)
  10. 【转载】Spring Cloud底层原理
  11. 形象解释 undefined 和 null 之间的区别 ​
  12. 计算机组成原理第三章ppt,计算机组成原理第三章幻灯片(白中英版).ppt
  13. python下载网页方法_Python 下载网页的几种方法
  14. eplan加密狗已损坏_[转载]EPLAN Electric P8 仿真加密狗 error 1068 问题
  15. linux系统如何使用GPT工具进行分区
  16. Excel技能培训之四-按颜色排序,按自定义文字排序
  17. LTE-5G学习笔记17--COMP技术讲解
  18. Java实现简单的银行卡
  19. Python+Vue计算机毕业设计酒店管理系统(前台后台)i2agu(源码+程序+LW+部署)
  20. p2v之clonezilla(1)再生龙启动u盘制作

热门文章

  1. LinuxProbe 0x21 使用Ansible服务实现自动化运维
  2. 内存回收导致关键业务抖动案例分析-论云原生OS内存QoS保障
  3. CSS3知识点笔记————基础(五星)
  4. 《五朵金花》电影影评
  5. Knowledge Embedding Based Graph Convolutional Network
  6. UEBA中的行为基线分析
  7. 微信小程序的特点、开发能力及运行机制
  8. 【ARUN】FastAPIVue 拥有无敌颜值且易用的全栈测试平台 第三弹——测试追踪
  9. 机器学习:房价预测项目实战
  10. 电脑硬盘锁怎么解除linux,硬盘锁了怎么办_硬盘锁怎么解除