Naoya:

Hi,hackers!

I have a question about txid_current(). 
it is "Why does txid_current() assign new transaction-id?".

When we executes txid_current() outside of transaction block, it assigns new transaction-id. 
I guess it doesn't need to assign a new txid because txid_current() is just a read-only function.

I found a replaceable function by walking through pg-code, that is GetStableLatestTransactionId(void).

I attached a patch which changing just 1-line. 
Could you please check the code?

Regards,

Naoya

Michael:

txid_current has had the behavior of assigning a new transaction XID 
when one is not assigned since its introduction. I don't think that it 
is wise to change it now the way you do as many applications surely 
rely on this assumption. Perhaps we could make the documentation 
clearer about those things though, changing the description of this 
function to "get current transaction ID, and assign a new one if one 
is not assigned yet": 
http://www.postgresql.org/docs/devel/static/functions-info.html

Regards, 
-- 
Michael

Naoya:

Thank you for comments.

I understand your points.

For only to read a current transaction-id, I know we just have to use 
txid_current_snapshot and that is a best way, but I feel a little bit 
hassle to explain columns of txid_current_snapshot for my supporting customers.. 
(Xmin is .... and Xmax is ....) ..

I think that a description of txid_current is too rough and it might

be confused some users. 
txid_current is a different operation depending on session situations, 
I feel if detail of txid_current is documented then it will be better.

For example... 
Inside of the transaction-block(begin..end), returns a transaction-id used by this block. 
Outside of the transaction-block, returns a next transaction-id(but it is consumed by this function).

Regards,

Naoya

Michael:

Attached is a doc patch among those lines. 
-- 
Michael

Name Return Type Description
txid_current() bigint get current transaction ID, assigning a new one if the current transaction does not have one
txid_current_snapshot() txid_snapshot get current snapshot

Snapshot Components

Name Description
xmin Earliest transaction ID (txid) that is still active. All earlier transactions will either be committed and visible, or rolled back and dead.
xmax First as-yet-unassigned txid. All txids greater than or equal to this are not yet started as of the time of the snapshot, and thus invisible.
xip_list Active txids at the time of the snapshot. The list includes only those active txids between xmin and xmax; there might be active txids higher thanxmax. A txid that is xmin <= txid < xmax and not in this list was already completed at the time of the snapshot, and thus either visible or dead according to its commit status. The list does not include txids of subtransactions.

txid_snapshot's textual representation is xmin:xmax:xip_list. For example 10:20:10,14,15 means xmin=10, xmax=20, xip_list=10, 14, 15.

参考:

http://postgresql.nabble.com/why-does-txid-current-assign-new-transaction-id-td5851159.html

http://www.postgresql.org/docs/devel/static/functions-info.html

why does txid_current() assign new transaction-id?的更多相关文章

  1. Postgresql 锁查看

    之前版本 PostgreSQL 的 pg_stat_activity 视图的 waiting 字段判断会话是否等待锁资源(通俗地讲, waiting 值为true表示申请不到锁资源处于等待状态),但是 ...

  2. FAQ – Automatic Undo Management (AUM) / System Managed Undo (SMU) (Doc ID 461480.1)

    FAQ – Automatic Undo Management (AUM) / System Managed Undo (SMU) (Doc ID 461480.1) APPLIES TO: Orac ...

  3. Transaction recovery: lock conflict caught and ignored

    Transaction recovery: lock conflict caught and ignored环境:RAC 4节点.oracle 11.2.0.4.redhat 5.9 64bit 问题 ...

  4. iOS内存管理retain,assign,copy,strong,weak

    转自:http://www.cnblogs.com/nonato/archive/2013/11/28/3447162.html iOS的对象都继承于NSObject, 该对象有一个方法:retain ...

  5. Ehcache(2.9.x) - API Developer Guide, Transaction Support

    About Transaction Support Transactions are supported in versions of Ehcache 2.0 and higher. The 2.3. ...

  6. ios中strong, weak, assign, copy

    copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是 ...

  7. 总账:日记账导入流程(文档 ID 1591640.1)

    文档内容   概要   历史记录   详细信息   GL_INTERFACE_CONTROL   GL_INTERFACE_HISTORY   GL_IMPORT_REFERENCES   摘要   ...

  8. Xcode工程编译错误:“Cannot assign to 'self' outside of a method in the init family”

    #import <Foundation/Foundation.h> @interface EOCRectangle : NSObject<NSCoding> @property ...

  9. 全局ID的重要性

    全局ID的重要性 体现在sharding的时候 gtid MySQL:global transaction id uuid:universally unique identifier guid:glo ...

随机推荐

  1. (转)SQLLite数据操作

    原文:http://dreamboy.blog.51cto.com/3180937/722352 SQLLite数据操作 一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存 ...

  2. android-volley-at-a-glance

    http://liubin.org/2013/05/27/android-volley-at-a-glance/ http://www.androidhive.info/2014/05/android ...

  3. oracle的存储结构

    表空间 当一个用户被创建以后,随之就要为用户分配数据存储的空间,这在oracle中成为“表空间”(Tablespace). 在数据库中创建用户时,基于应用性能和管理的考虑,最好为不同的用户创建独立的表 ...

  4. Objective-c 命名规则

    1.方法名:第一个单词的首字母用小写,后面的单词首字母要大写<骆驼规则>,例如doSomething . doSomethingElse 2.类名:第一个单词的首字母要求大写,后面的单词首 ...

  5. 详解定位—>"position"

    position是css中一个重要的属性,他规定元素的定位类型,默认值为static,他的值有5种,absolute,fixed,relative,static,inherit.接下来将详细具体对每一 ...

  6. ES6:模块简单解释

    modules是ES6引入的最重要的一个特性. 以后写模块的时候就直接按照ES6的modules语法来写 ,然后用babel+browserify 来打包就行了. modules规范分两部分,一部分是 ...

  7. Ubuntu安装Fcitx(小企鹅五笔输入法)

    安装配置如下: 1. 安装 fcitx sudo apt-get install fcitx 2. 配置默认输入法为 fcitx im-switch -s fcitx // 注意无须加 sudo 3. ...

  8. python3爬虫初探(三)之正则表达式

    前面已经写了如何获取网页源码,那么接下来就是该解析网页并提取需要的数据了.这里简单写一下正则表达的用法. 首先,找个要抓取图片的网站,获取源码. import requests import re # ...

  9. Android Focusable in Touch Mode 介绍

    在学习 ListView 源码时,发现了 Focusable in Touch Mode 这个概念,注释的意思是: whether this view can receive focus while ...

  10. C# string格式的日期时间字符串转为DateTime类型

    (1 )Convert.ToDateTime(string) string格式有要求,必须是yyyy-MM-dd hh:mm:ss (2):Convert.ToDateTime(string, IFo ...