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. Java 嵌套作用域

    在C/C++中,当一个块处于另一个块作用域内的时候,内层定义的变量会把外层的变量隐藏, 遵循所谓的就近原则. 在Java中,在内层定义与外层同名的变量是禁止的! 如下: int i = 0; for( ...

  2. python saltstack

    1. 拷贝文件 # salt ‘*‘ cp.get_file salt://first.xml /tmp/first.xml 或 gzip=1-9,数字越大,压缩越高; makedirs=True 自 ...

  3. 将byte[]数组数据转换为图片用于预览显示

    假如服务器返回给你的图片信息是byte[] 然后你需要将起转换成图片显示到你的view中去: 按以下的步骤 1.将获取的byte数组保存 假如为temp[]; 2.将temp[]转化为bitmap,你 ...

  4. phpstom 实用laravel 需要附加的 命令

    首先利用composer 下载相关的插件 在根目录执行此代码 composer require barryvdh/laravel-ide-helper 再者在config/app.php 添加一条命令 ...

  5. Android沉浸式(侵入式)标题栏(状态栏)Status(一)

     Android沉浸式(侵入式)标题栏(状态栏)Status(一) 现在越来越多的APP设计采用这种称之为沉浸式状态栏(Status)的设计,这种沉浸式状态栏又称之"侵入式"状 ...

  6. Qt简介

    一.Qt与Qt Creator简介        Qt是一个跨平台应用程序和 UI 开发框架.使用 Qt 您只需一次性开发应用程序,无须重新编写源代码,便可跨不同桌面和嵌入式操作系统部署这些应用程序. ...

  7. java中byte数据转换为c#的byte数据

    最近在做下载方面的开发.有一个需求,就是读取要下载的文件中的一些数据,比如要读取这个文件包含的用户信息,但是怎么读都不对.后来搞了很久才发现,服务器上的文件里的用户信息,用C#写的存储方法来存储的,而 ...

  8. UI学习笔记---第八天

    UINavigationController的用法   界面间传值 UInavigationController继承于UIViewController,以栈的方式管理所控制的师徒控制器,至少要有一个被 ...

  9. CentOS云服务器数据盘分区和格式化

    1. 查看数据盘信息 登录CentOS云服务器后,可以使用“fdisk -l”命令查看数据盘相关信息. 使用“df –h”命令,无法看到未分区和格式化的数据盘,只能看到已挂载的. [root@VM_7 ...

  10. 快速对字符转义,避免跨站攻击XSS

    XSS已经成为非常流行的网站攻击方式,为了安全起见,尽量避免用户的输入.可是有些情况下不仅不避免,反而要求鼓励输入,比如写博客.博客园开放性很高,可以运行手写的JS.之前比较著名的例子就是,凡是看到某 ...