Function to get a txn's replication origin - Mailing list pgsql-hackers

From Craig Ringer
Subject Function to get a txn's replication origin
Date
Msg-id CAMsr+YG_oF1694esChGSCJvrvLk9n9HbJvV0NYuS5c3ciuv_xQ@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi all

During the committs / replorigin split, the function to query the replication origin of a transaction from user space was lost.

A function to do so is utterly trivial, e.g.

Datum
pg_get_xact_replication_origin(PG_FUNCTION_ARGS)
{   
    TransactionId xid = PG_GETARG_TRANSACTIONID(0);
    TimestampTz ts;
    RepOriginId nodeid;
    
    if (TransactionIdGetCommitTsData(xid, &ts, &nodeid))
        PG_RETURN_INT32((int32)nodeid);
    else
        PG_RETURN_NULL();
}

... but it probably makes more sense to extend pg_xact_commit_timestamp with support for returning the origin too.

pg_xact_commit_timestamp() is a scalar function so I don't want to extend it directly because that'll upset existing callers.

pg_xact_commit_timestamp_origin()

(unsure if a "with" or "and" is appropriate or too long).

Attached. Also add 'roident' to pg_last_committed_xact() to make the info available there too. It was already record-returning so I'm not overly concerned about adding a column.

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

pgsql-hackers by date:

Previous
From: Pavan Deolasee
Date:
Subject: Re: PATCH: Exclude unlogged tables from base backups
Next
From: Dmitry Ivanov
Date:
Subject: Re: new function for tsquery creartion