From: movead.li@highgo.ca <movead.li@highgo.ca>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Subject: A patch for get origin from commit_ts.
Date: Mon, 11 May 2020 16:43:11 +0800
Message-ID: <2020051116430836450630@highgo.ca> (raw)
Hello hackers,
I am researching about 'origin' in PostgreSQL, mainly it used in logical
decoding to filter transaction from non-local source. I notice that the
'origin' is stored in commit_ts so that I think we are possible to get 'origin'
of a transaction from commit_ts.
But I can not fond any code to get 'origin' from commit_ts, just like it is
producing data which nobody cares about. Can I know what's the purpose
of the 'origin' in commit_ts? Do you think we should add some support
to the careless data?
For example, I add a function to get 'origin' from commit_ts:
=======================================
postgres=# select pg_xact_commit_origin('490');
pg_xact_commit_origin
-----------------------
test_origin
(1 row)
postgres=# select pg_xact_commit_origin('491');
pg_xact_commit_origin
-----------------------
test_origin1
(1 row)
postgres=#
=======================================
Regards,
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca
Attachments:get_origin_from_commit_ts.patch (application/octet-stream, 1.5K) downloaddiff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.cindex 630df672cc..85e03efe4e 100644--- a/src/backend/access/transam/commit_ts.c+++ b/src/backend/access/transam/commit_ts.c@@ -416,6 +416,29 @@ pg_xact_commit_timestamp(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(ts);
}
+/*+ * SQL-callable wrapper to obtain commit origin of a transaction+ */+Datum+pg_xact_commit_origin(PG_FUNCTION_ARGS)+{+ TransactionId xid = PG_GETARG_UINT32(0);+ RepOriginId nodeid;+ TimestampTz ts;+ bool found;+ char *roname = NULL;++ found = TransactionIdGetCommitTsData(xid, &ts, &nodeid);++ if (!found || (InvalidRepOriginId == nodeid))+ PG_RETURN_NULL();++ replorigin_by_oid(nodeid, false, &roname);++ PG_RETURN_TEXT_P(cstring_to_text(roname));+}++
Datum
pg_last_committed_xact(PG_FUNCTION_ARGS)
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.datindex 4bce3ad8de..5e67ace32d 100644--- a/src/include/catalog/pg_proc.dat+++ b/src/include/catalog/pg_proc.dat@@ -5945,6 +5945,12 @@
prorettype => 'timestamptz', proargtypes => 'xid',
prosrc => 'pg_xact_commit_timestamp' },
+{ oid => '3435', descr => 'get commit origin of a transaction',+ proname => 'pg_xact_commit_origin', provolatile => 'v',+ prorettype => 'text', proargtypes => 'xid',+ prosrc => 'pg_xact_commit_origin' },++
{ oid => '3583',
descr => 'get transaction Id and commit timestamp of latest transaction commit',
proname => 'pg_last_committed_xact', provolatile => 'v',
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: movead.li@highgo.ca, pgsql-hackers@lists.postgresql.org
Subject: Re: A patch for get origin from commit_ts.
In-Reply-To: <2020051116430836450630@highgo.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox