Thread: Way to access LSN (for each transaction) by directly talking to postgres?

Way to access LSN (for each transaction) by directly talking to postgres?

From
Joshua Bay
Date:
Hi,

Could you please let me know if there is a way to get LSN of each transaction by directly communicating with Postgres server and NOT by accessing logs.

Thanks!
Joshua

Re: Way to access LSN (for each transaction) by directly talking to postgres?

From
Craig Ringer
Date:


On 3 August 2016 at 11:37, Joshua Bay <joshuabay93@gmail.com> wrote:
Hi,

Could you please let me know if there is a way to get LSN of each transaction by directly communicating with Postgres server and NOT by accessing logs.


To what end? What problem are you trying to solve?

What LSN, exactly? The LSN of the first write and xid allocation? The LSN of the commit record? What if it's a complex commit like with prepared xacts?


--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
Thanks for responses!

The problem I wanted to solve was to find the (global) order of commits across the postgres cluster. So, my attempt was to use the LSN.



On Wed, Aug 3, 2016 at 9:47 AM, Craig Ringer <craig@2ndquadrant.com> wrote:


On 3 August 2016 at 11:37, Joshua Bay <joshuabay93@gmail.com> wrote:
Hi,

Could you please let me know if there is a way to get LSN of each transaction by directly communicating with Postgres server and NOT by accessing logs.


To what end? What problem are you trying to solve?

What LSN, exactly? The LSN of the first write and xid allocation? The LSN of the commit record? What if it's a complex commit like with prepared xacts?


--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Re: Way to access LSN (for each transaction) by directly talking to postgres?

From
Craig Ringer
Date:
On 4 August 2016 at 01:35, Joshua Bay <joshuabay93@gmail.com> wrote:
Thanks for responses!

The problem I wanted to solve was to find the (global) order of commits across the postgres cluster. So, my attempt was to use the LSN.

Have a look at how logical decoding does it. Check out ReorderBufferCommit in src/backend/replication/logical/reorderbuffer.c  .

Or just write a trivial a logical decoding plugin that only implements the commit callback and only emits the LSN.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services