RE: Patch for migration of the pg_commit_ts directory
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi, Per my understanding, track_commit_timestamp must be on the new instance, otherwise it would be removed when new instance starts. Is it correct? If so, should we detect the difference and do some warnings/errors here? Or it is just the user's responsibility? Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi,
(Sorry but I cannot find your name)
> Yes, track_commit_timestamp must be installed in the new instance.
> This is only the responsibility of an experienced user.
> pg_upgrage should allow you to save pg_commit_ts if this data exists at the time of migration.
> Warnings are not needed, the loss of this data is not critical in most cases.
> They were lost with each migration if users did not manually migrate them.
So, your policy is that commit_ts is not the user data thus it is OK to drop during
the upgrade, is it correct? I want to know other's opinion around here.
Note that if we want to check, it can be done in check_control_data().
Regarding the patch:
```
-
+ cluster->controldata.chkpnt_oldstCommitTsxid = 0;
+ cluster->controldata.chkpnt_newstCommitTsxid = 0;
```
Other attributes are not initialized, you can follow.
```
+ if (old_cluster.controldata.chkpnt_oldstCommitTsxid > 0)
+ copy_subdir_files("pg_commit_ts", "pg_commit_ts");
```
Indent should be fixed. Please run pgindent.
```
- old_cluster.controldata.chkpnt_nxtxid,
- old_cluster.controldata.chkpnt_nxtxid,
+ old_cluster.controldata.chkpnt_oldstCommitTsxid == 0 ? old_cluster.controldata.chkpnt_nxtxid : old_cluster.controldata.chkpnt_oldstCommitTsxid,
+ old_cluster.controldata.chkpnt_newstCommitTsxid == 0 ? old_cluster.controldata.chkpnt_nxtxid : old_cluster.controldata.chkpnt_newstCommitTsxid,
```
To confirm, is there a possibility that only either of oldest/newest CommitTs exists?
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Re: Patch for migration of the pg_commit_ts directory
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Thu, Oct 2, 2025 at 12:10 PM Hayato Kuroda (Fujitsu) wrote: > > > Yes, track_commit_timestamp must be installed in the new instance. > > This is only the responsibility of an experienced user. > > pg_upgrage should allow you to save pg_commit_ts if this data exists at the time of migration. > > Warnings are not needed, the loss of this data is not critical in most cases. > > They were lost with each migration if users did not manually migrate them. > > So, your policy is that commit_ts is not the user data thus it is OK to drop during > the upgrade, is it correct? > IIUC, the proposal is that if GUC track_commit_timestamp is enabled on the new instance then we should copy it, otherwise, we can drop copying it. Is my understanding correct? I think we can follow what is done check_new_cluster_replication_slots() for the case when track_commit_timestamp is not set on the new server. When we try to copy slots and the wal_level on the new server is minimal, we error out, so shouldn't we do the same here and error_out if track_commit_timestamp is not enabled and we have some valid commit_ts data to copy? -- With Regards, Amit Kapila.
Re: Patch for migration of the pg_commit_ts directory
От:
Maxim Orlov <orlovmg@gmail.com>
Дата:
On Thu, 2 Oct 2025 at 11:49, Amit Kapila <amit.kapila16@gmail.com> wrote:
When we try to
copy slots and the wal_level on the new server is minimal, we error
out, so shouldn't we do the same here and error_out if
track_commit_timestamp is not enabled and we have some valid commit_ts
data to copy?
+1 Sounds reasonable to me. It's better to give an explicit error;
otherwise, we would remove data that the user clearly wants to migrate
to the new cluster. And deleting data just because the user forgot to
specify one parameter in a new cluster looks like a bad joke to me.
otherwise, we would remove data that the user clearly wants to migrate
to the new cluster. And deleting data just because the user forgot to
specify one parameter in a new cluster looks like a bad joke to me.
Best regards,
Maxim Orlov.
Re: Patch for migration of the pg_commit_ts directory
От:
Bruce Momjian <bruce@momjian.us>
Дата:
On Mon, Oct 6, 2025 at 07:31:52PM +0500, ls7777 wrote: > Hi, > I'll try to return it to the original thread. > > I absolutely agree with you. Data loss during migration is an unacceptable > situation. And why it's still happening, I don't understand. But issuing > messages will require translating it into other languages and complicate the > patch. I'm not a programmer to do it beautifully. And not a beautiful patch is > unlikely to be accepted. > I will do a parameter check and an ERROR message. You don't need to worry about translations. Each language team will make sure your English message is translated. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future.
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi, Thanks for updating the patch. Regarding the check_track_commit_timestamp_parameter(), I'm not sure the function is needed. Since pg_controldata outputs whether the commit_ts module is enabled or not [1], can we obtain there instead? I imagined like we can add a new field at ControlData, it could be obtained in get_control_data(), values for instances could be compared in check_control_data(). Another possibility is that oldestCommitTsXid/newestCommitTsXid can be always valid if track_commit_timestamp is on. In this case the attribute is not needed anymore. It is enough to check these values. Can you check them? Regarding the test, I feel it is unnecessary long. I feel it is enough to ensure one or two transactions have the same timestamp on the both nodes, pgbench is not needed. Current test may not be able to finish on the slow machine. [1] ``` $ pg_controldata data/ | grep "track_" track_commit_timestamp setting: off ``` Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi,
> At the time check_control_data is launched for the new cluster, the control file
> does not contain information about the set track_commit_timestamp=on. It is
> installed only in postgresql.conf.
You did consider the case that track_commit_timestamp is set to on but the instance
has not started before the pg_upgrade, right? Valid point.
> The check_track_commit_timestamp_parameter function is only needed for the new
> cluster. And you can not run it for the old cluster, but use data from the
> old_cluster.controldata.chkpnt_newstCommitTsxid control file. But this will be
> less clear than using the check_track_commit_timestamp_parameter function.
Sorry, I'm not very clear this part. Can you describe the point bit more?
Other comments:
01. get_control_data
```
+ if (GET_MAJOR_VERSION(cluster->major_version) < 905)
+ {
+ cluster->controldata.chkpnt_oldstCommitTsxid = 0;
+ cluster->controldata.chkpnt_newstCommitTsxid = 0;
+ }
```
IIUC, checksum_version is checked like this because got_data_checksum_version
must be also set.
Since we do not have the boolean for commit_ts, not sure it is needed.
old_cluster and new_cluster are the global variable and they are initialized with
zero.
02. check_track_commit_timestamp_parameter
```
+ conn = connectToServer(cluster, "template1");
+ res = executeQueryOrDie(conn, "SELECT count(*) AS is_set "
+ "FROM pg_settings WHERE name = 'track_commit_timestamp' and setting = 'on'");
+ is_set = PQfnumber(res, "is_set");
+ cluster->track_commit_timestamp_on = atoi(PQgetvalue(res, 0, is_set)) == 1;
```
The SQL looks strange for me. Isn't it enough to directly obtain "setting" attribute
and check it is "on" or not? Also, conn and res can be the local variable of the
else part.
03. ClusterInfo
```
+ bool track_commit_timestamp_on; /* track_commit_timestamp for
+ * cluster */
```
The indent is broken, please run pgindent.
04. test
Could you please update meson.build? Otherwise the added test could not be run for meson build.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi,
Thanks for updating the patch and sorry for the late reply. Here are my comments.
01.
```
+ prep_status("Checking for pg_commit_ts");
```
I think we must clarify which node is being checked. Something like:
Checking for new cluster configuration for commit timestamp
02.
```
}
-
/* we have the result of cmd in "output". so parse it line by line now */
```
This change is not needed.
03.
```
+ /*
+ * Copy pg_commit_ts
+ */
```
I feel it can be removed or have more meanings. Something lile:
Copy old commit_timestamp data to new, if available.
04.
Regarding the test,
05.
```
+sub command_output
```
Can run_command() be used instead of defining new function?
06.
```
+$old->command_ok([ 'pgbench', '-i', '-s', '1' ], 'init pgbench');
+$old->command_ok([ 'pgbench', '-t', '1', '-j', '1' ], 'pgbench it');
```
I think no need to use pgbench anymore. Can we define tables and insert tuples
by myself?
07.
```
+command_fails(
+ [
+ 'pg_upgrade', '--no-sync',
+ '-d', $old->data_dir,
+ '-D', $new->data_dir,
+ '-b', $old->config_data('--bindir'),
+ '-B', $new->config_data('--bindir'),
+ '-s', $new->host,
+ '-p', $old->port,
+ '-P', $new->port,
+ $mode
+ ],
+ 'run of pg_upgrade fails with mismatch parameter track_commit_timestamp');
```
According to other test files, we do not use the shorten option.
Also, please verify the actual output by command_ok_or_fails_like() or command_checks_all().
08.
```
+sub xact_commit_ts
```
Not sure, but this function is introduced because we have 100 transactions. Can we omit this now?
09.
```
+# The new cluster should contain timestamps created during the pg_upgrade and
+# some more created by the pgbench.
+#
+print "\nCommit timestamp only in new cluster:\n";
+for my $line (@b) {
+ print "$line\n" unless $h1{$line};
+}
```
I don't think this is needed because the output is not verified.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Re: Patch for migration of the pg_commit_ts directory
От:
Maxim Orlov <orlovmg@gmail.com>
Дата:
Looks good to me. As I see it, the patch is almost ready, so I decided
to create an CF entry [0]. Feel free to edit it as you see fit.
RE: Patch for migration of the pg_commit_ts directory
Hi, Thanks for updating the patch. ``` +my ($xid,$ts) = $resold =~ /\s*(\d+)\s*\|(.*)/; ``` Per my understanding $ts is not used here. Can you remove it? Apart from above, I found some cosmetic issues. Please see attached my fix which can be applied atop HEAD. Can you check and include if it is OK? Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Patch for migration of the pg_commit_ts directory
От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Hi,
On Wed, Mar 11, 2026 at 10:51 AM ls7777 wrote:
>
> Hello,
> I saw a big comment that I had missed.
> Added fixes in two patches:
> v11-0001-Migration-of-the-pg_commit_ts-directory.patch - main changes
> v11-0002-Migration-of-the-pg_commit_ts-directory-desc.patch - changes to documentation and comments
>
>
> ----------------
> Кому: 'ls7777' (ls7777@yandex.ru);
> Копия: pgsql-hackers@postgresql.org, orlovmg@gmail.com;
> Тема: Patch for migration of the pg_commit_ts directory;
> 11.03.2026, 12:55, "Hayato Kuroda (Fujitsu)" :
>
> Dear Sergey,
>
>
> I don't understand what I need to do.
> Subject: [PATCH v10] Migration of the pg_commit_ts directory
> I have specified a new version in the patch. Do I need to add anything else?
>
>
> When we see the commit message in postgres repo, you can see that each commit
> contain the background, what we did in the commit, considerations, and etc.
> Compared with them, the description you added seems insufficient.
> Of course the committer will take care, but Amit suggested [1] to write a draft.
> The basic style guide is determined in [2].
>
> Actually I wrote a draft for the patch set in v9-0002, but you miss. You may
> able to refer it, and re-create new version or use the same one.
>
I've reviewed this patch and have one question.
The commit timestamp has not only the timestamp data but also
replication origin id. The replication origin id assigned to the
subscription on the new cluster is not necessarily the same as the
ones assigned on the old cluster. Therefore, if there is mismatch,
replication conflict 'update_origin_differs' could wrongly happen,
even though the new subscriber starts logical replication from the
same publisher. I've confirmed this behavior in the following
scenario:
1. Setup publication.
-- on publisher
CREATE TABLE test (id int primary key, t text);
CREATE PUBLICATION pub FOR TABLE test;
2. Setup subscription.
-- on subscriber
CREATE TABLE test (id int primary key, t text);
CREATE SUBSCRIPTION mysub CONNECTION '...' PUBLICATION pub;
CREATE SUBSCRIPTION a_dummy CONNECTION '...' PUBLICATION pub WITH
(connect = false, enabled = false);
-- confirm that mysub's origin id is 1 and a_dummy's origin id is 2.
SELECT oid, subname FROM pg_subscription;
oid | subname
-------+---------
16392 | mysub
16393 | a_dummy
(2 rows)
SELECT * FROM pg_replication_origin;
roident | roname
---------+----------
1 | pg_16392
2 | pg_16393
(2 rows)
3. Insert a tuple to the test table and wait for it to be replicated.
-- on publisher
INSERT INTO test VALUES (1, 'replicated change');
The change is applied on the subscription with replication origin id 1:
-- on subscriber
SELECT * FROM test, pg_xact_commit_timestamp_origin(test.xmin);
id | c | timestamp | roident
----+-------------------+-------------------------------+---------
1 | replicated change | 2026-03-16 13:49:35.211316-07 | 1
(1 row)
4. Do pg_upgrade
5. Check the replication origins in the new subscriber
SELECT oid, subname FROM pg_subscription;
oid | subname
-------+---------
16402 | a_dummy
16403 | mysub
(2 rows)
SELECT * FROM pg_replication_origin;
roident | roname
---------+----------
1 | pg_16402
2 | pg_16403
(2 rows)
The replication origin 1 is now used by a_dummy subscription.
6. Update the tuple on the publisher
-- on publisher
UPDATE test SET c = 'change after upgrade' WHERE id = 1;
Then I got the following LOG:
LOG: conflict detected on relation "public.test":
conflict=update_origin_differs
2026-03-16 13:53:41.992 PDT [1247879] DETAIL: Updating the row that
was modified by a different origin "pg_16402" in transaction 760 at
2026-03-16 13:53:33.448002-07: local row (1, replicated change),
remote row (1, change after upgrade), replica identity (id)=(1).
2026-03-16 13:53:41.992 PDT [1247879] CONTEXT: processing remote data
for replication origin "pg_16403" during message type "UPDATE" for
replication target relation "public.test" in transaction 664, finished
at 0/017ED910
I think that this patch works fine only when users don't use the
replication origins. On the other hand, I think we should ensure that
subscriptions use the same replication origins even after upgrade in
cases where users are upgrading subscribers.
Also, regarding the patch, with the following change we disallow the
case where users want to disable the commit timestamp in the new
cluster. IIUC migrating the commit timestamps is not mandatory in
practice, so I think we do the migration when applicable or raise a
warning if only the new cluster disables the commit timestamps.
+ if (!commit_ts_is_enabled &&
+ old_cluster.controldata.chkpnt_newstCommitTsxid > 0)
+ pg_fatal("\"track_commit_timestamp\" must be \"on\" but is set
to \"off\"");
+
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Re: Patch for migration of the pg_commit_ts directory
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Tue, Mar 17, 2026 at 2:34 AM Masahiko Sawada wrote: > > I've reviewed this patch and have one question. > > The commit timestamp has not only the timestamp data but also > replication origin id. The replication origin id assigned to the > subscription on the new cluster is not necessarily the same as the > ones assigned on the old cluster. Therefore, if there is mismatch, > replication conflict 'update_origin_differs' could wrongly happen, > even though the new subscriber starts logical replication from the > same publisher. I've confirmed this behavior in the following > scenario: > > 1. Setup publication. > -- on publisher > CREATE TABLE test (id int primary key, t text); > CREATE PUBLICATION pub FOR TABLE test; > > 2. Setup subscription. > -- on subscriber > CREATE TABLE test (id int primary key, t text); > CREATE SUBSCRIPTION mysub CONNECTION '...' PUBLICATION pub; > CREATE SUBSCRIPTION a_dummy CONNECTION '...' PUBLICATION pub WITH > (connect = false, enabled = false); > > -- confirm that mysub's origin id is 1 and a_dummy's origin id is 2. > SELECT oid, subname FROM pg_subscription; > oid | subname > -------+--------- > 16392 | mysub > 16393 | a_dummy > (2 rows) > > SELECT * FROM pg_replication_origin; > roident | roname > ---------+---------- > 1 | pg_16392 > 2 | pg_16393 > (2 rows) > > 3. Insert a tuple to the test table and wait for it to be replicated. > -- on publisher > INSERT INTO test VALUES (1, 'replicated change'); > > The change is applied on the subscription with replication origin id 1: > -- on subscriber > SELECT * FROM test, pg_xact_commit_timestamp_origin(test.xmin); > id | c | timestamp | roident > ----+-------------------+-------------------------------+--------- > 1 | replicated change | 2026-03-16 13:49:35.211316-07 | 1 > (1 row) > > 4. Do pg_upgrade > 5. Check the replication origins in the new subscriber > > SELECT oid, subname FROM pg_subscription; > oid | subname > -------+--------- > 16402 | a_dummy > 16403 | mysub > (2 rows) > > SELECT * FROM pg_replication_origin; > roident | roname > ---------+---------- > 1 | pg_16402 > 2 | pg_16403 > (2 rows) > > The replication origin 1 is now used by a_dummy subscription. > > 6. Update the tuple on the publisher > -- on publisher > UPDATE test SET c = 'change after upgrade' WHERE id = 1; > > Then I got the following LOG: > > LOG: conflict detected on relation "public.test": > conflict=update_origin_differs > 2026-03-16 13:53:41.992 PDT [1247879] DETAIL: Updating the row that > was modified by a different origin "pg_16402" in transaction 760 at > 2026-03-16 13:53:33.448002-07: local row (1, replicated change), > remote row (1, change after upgrade), replica identity (id)=(1). > 2026-03-16 13:53:41.992 PDT [1247879] CONTEXT: processing remote data > for replication origin "pg_16403" during message type "UPDATE" for > replication target relation "public.test" in transaction 664, finished > at 0/017ED910 > > I think that this patch works fine only when users don't use the > replication origins. > But is there any value of this patch without replication origins? I thought the value of this patch is to detect conflicts correctly after upgrade. IIUC, in some cases, the commit time on subscriber could still be later than the conflicting transaction from publisher in which case timing data can also be used for last_write_win kind of strategy but without origin that also won't be possible. > On the other hand, I think we should ensure that > subscriptions use the same replication origins even after upgrade in > cases where users are upgrading subscribers. > Right, I think we need to ensure that for detecting conflicts. -- With Regards, Amit Kapila.
Re: Patch for migration of the pg_commit_ts directory
От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Mon, Mar 16, 2026 at 9:17 PM Amit Kapila wrote: > > On Tue, Mar 17, 2026 at 2:34 AM Masahiko Sawada wrote: > > > > I've reviewed this patch and have one question. > > > > The commit timestamp has not only the timestamp data but also > > replication origin id. The replication origin id assigned to the > > subscription on the new cluster is not necessarily the same as the > > ones assigned on the old cluster. Therefore, if there is mismatch, > > replication conflict 'update_origin_differs' could wrongly happen, > > even though the new subscriber starts logical replication from the > > same publisher. I've confirmed this behavior in the following > > scenario: > > > > 1. Setup publication. > > -- on publisher > > CREATE TABLE test (id int primary key, t text); > > CREATE PUBLICATION pub FOR TABLE test; > > > > 2. Setup subscription. > > -- on subscriber > > CREATE TABLE test (id int primary key, t text); > > CREATE SUBSCRIPTION mysub CONNECTION '...' PUBLICATION pub; > > CREATE SUBSCRIPTION a_dummy CONNECTION '...' PUBLICATION pub WITH > > (connect = false, enabled = false); > > > > -- confirm that mysub's origin id is 1 and a_dummy's origin id is 2. > > SELECT oid, subname FROM pg_subscription; > > oid | subname > > -------+--------- > > 16392 | mysub > > 16393 | a_dummy > > (2 rows) > > > > SELECT * FROM pg_replication_origin; > > roident | roname > > ---------+---------- > > 1 | pg_16392 > > 2 | pg_16393 > > (2 rows) > > > > 3. Insert a tuple to the test table and wait for it to be replicated. > > -- on publisher > > INSERT INTO test VALUES (1, 'replicated change'); > > > > The change is applied on the subscription with replication origin id 1: > > -- on subscriber > > SELECT * FROM test, pg_xact_commit_timestamp_origin(test.xmin); > > id | c | timestamp | roident > > ----+-------------------+-------------------------------+--------- > > 1 | replicated change | 2026-03-16 13:49:35.211316-07 | 1 > > (1 row) > > > > 4. Do pg_upgrade > > 5. Check the replication origins in the new subscriber > > > > SELECT oid, subname FROM pg_subscription; > > oid | subname > > -------+--------- > > 16402 | a_dummy > > 16403 | mysub > > (2 rows) > > > > SELECT * FROM pg_replication_origin; > > roident | roname > > ---------+---------- > > 1 | pg_16402 > > 2 | pg_16403 > > (2 rows) > > > > The replication origin 1 is now used by a_dummy subscription. > > > > 6. Update the tuple on the publisher > > -- on publisher > > UPDATE test SET c = 'change after upgrade' WHERE id = 1; > > > > Then I got the following LOG: > > > > LOG: conflict detected on relation "public.test": > > conflict=update_origin_differs > > 2026-03-16 13:53:41.992 PDT [1247879] DETAIL: Updating the row that > > was modified by a different origin "pg_16402" in transaction 760 at > > 2026-03-16 13:53:33.448002-07: local row (1, replicated change), > > remote row (1, change after upgrade), replica identity (id)=(1). > > 2026-03-16 13:53:41.992 PDT [1247879] CONTEXT: processing remote data > > for replication origin "pg_16403" during message type "UPDATE" for > > replication target relation "public.test" in transaction 664, finished > > at 0/017ED910 > > > > I think that this patch works fine only when users don't use the > > replication origins. > > > > But is there any value of this patch without replication origins? I > thought the value of this patch is to detect conflicts correctly after > upgrade. IIUC, in some cases, the commit time on subscriber could > still be later than the conflicting transaction from publisher in > which case timing data can also be used for last_write_win kind of > strategy but without origin that also won't be possible. I don't have the specific example, but thought there might be use cases without logical replication, for example, pulling all the new records inserted within the last 30min to another system etc. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Sergey, > This is a safer strategy to help you avoid losing the data that the user needs. I received a recommendation to do so. I think we need stronger use-case to proceed like that. Did you get recommendations from customers/users? If so, why do they want to avoid losing the commit timestamp? Are they collaborating some other systems? Your voice/experience is really needed. Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Sergey, Sorry for being late, I was busy in another project. Not sure we have enough time to rush this for PG19 because some new parts are added recently. Personally considered, the patch might be able to separate into two parts. 0001 contains changes to migrate the replication origin, and 0002 contains to migrate the commit_ts directory. For 0001, we may need a new SQL function to migrate replication origins, and it could be used only while in the binary upgrade mode like binary_upgrade_add_sub_rel_state(). We must not directly update the system catalog via UPDATE command. 0002 might be the same as what we discussed earlier. > 1. Added the --pg-commit-ts command line key for pg_upgrade. > Migration of the pg_commit_ts directory will be performed only if the user explicitly wishes. I cannot find the reason why you changed here. Can you share me your opinion? Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Sergey, While considering the feature once again, I came up with another issue. When pg_upgrade migrates objects to a new instance, it normally checks whether the new instance does not have existing objects. E.g., check_new_cluster_is_empty() checks if no tables exist, and check_new_cluster_replication_slots() ensures there are no logical slots. Based on that, how should we handle the commit timestamp? Since the patch simply copies the pg_commit_ts subdir, existing entries in the new cluster will be overwritten. So we may have to check if the commit_ts entries are empty when the pg_upgrade command runs, but not sure how to do that. Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Вложения:
Dear Sergey, (BTW, your mail looks broken on the web mail archive [1]. Please check settings) > Are you talking about checking for files in the pg_commit_ts directory of the old cluster? > The possibility of copying the catalog is checked here: No. IIUC, the code check whether the old node has a commit timestamps, and copies them if it has. My scenario was that if the NEW node has already had a commit timestamps. In this case, existing entries would be overwritten after the upgrade. Then my question was that whether we need to ensure there are no commit timestamp entries in the new cluster. [1]: https://www.postgresql.org/message-id/7105101784659908@mail.yandex.ru Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
Hi hackers, I did a self reviewing for 0001 and 0002, and updated the doc a bit. PSA new patch set. > If you accept part 1, many users who use logical replication will see > many messages like “conflict detected on relation” that didn’t exist before. Sorry, I'm not sure the part, can you please clarify more? When can it happen? Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Patch for migration of the pg_commit_ts directory
От:
Maxim Orlov <orlovmg@gmail.com>
Дата:
On Thu, 15 Oct 2026 at 06:54, Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com> wrote:
Hi hackers,Sorry for my brief absence; I’ve been a bit busy lately. Anyway,
I did a self reviewing for 0001 and 0002, and updated the doc a bit.
PSA new patch set.
> If you accept part 1, many users who use logical replication will see
> many messages like “conflict detected on relation” that didn’t exist before.
Sorry, I'm not sure the part, can you please clarify more? When can it happen?
I think Sergey is trying to say that without the second patch, users
might encounter false-positive errors.
You see, we do change pg_resetwal here:
exec_prog(UTILITY_LOG_FILE, NULL, true, true,
"\"%s/pg_resetwal\" -f -c %u,%u \"%s\"",
new_cluster.bindir,
- old_cluster.controldata.chkpnt_nxtxid,
- old_cluster.controldata.chkpnt_nxtxid,
+ oldest_xid,
+ newest_xid,
new_cluster.pgdata);
Thus, we change the tuples XID valid range of some sort.
Prior to this patch, a call of TransactionIdGetCommitTsData() would
return false, meaning no origin_differs were calculated and,
consequently, no messages were generated.
With 0001, we are effectively modifying the permissible XID range for
tuples. XIDs limits are restored from old cluster. Then lookup will
succeed and conflict detection will be reported. This is likely false
positive, but very annoying.
And patch 0001 makes this behavior the only option.
And patch 0001 makes this behavior the only option.
0002 makes it opt-in.
In short, if I were the committer, I wouldn’t consider committing patch
0001 separately from 0002.
In short, if I were the committer, I wouldn’t consider committing patch
0001 separately from 0002.
--
Best regards,
Maxim Orlov.
Re: Patch for migration of the pg_commit_ts directory
От:
Ajin Cherian <itsajin@gmail.com>
Дата:
On Thu, Oct 15, 2026 at 2:55 PM Hayato Kuroda (Fujitsu) wrote: > > Hi hackers, > > I did a self reviewing for 0001 and 0002, and updated the doc a bit. > PSA new patch set. > Hi Kuroda-san, Thanks for splitting the patch set; it makes this much easier to review. A few comments on v16. 1. The patch set no longer applies cleanly on HEAD. t/009 is now taken by 009_composite_types.pl, and there are conflicts in check.c and pg_upgrade.c. 2. 0003: There is already a separate patch that preserves replication origins during upgrade [1], so I suggest removing 0003 from this patch set. 3. 0001/0002: I agree with Maxim that 0001 shouldn't be committed without 0002 (or without origins being preserved). Otherwise the wider commit_ts range turns stale origin IDs into false update/delete_origin_differs conflicts, as Sawada-san showed. 4. 0002: The option name --pg-commit-ts and the help text "copy pg_commit_ts directory" describe the implementation rather than the behaviour. How about something like --preserve-commit-timestamps? Also, the help line is placed between -V and --clone, which breaks the alphabetical order of the long options. [1] https://www.postgresql.org/message-id/CAFPTHDbPXU7cs189J=BrzSa20EJzajOU25N7G7nT6UZqMkRnXg@mail.gmail.com Regards, Ajin Cherian Fujitsu Australia
RE: Patch for migration of the pg_commit_ts directory
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi Maxim, Thanks for the reply and sorry for the late response. > With 0001, we are effectively modifying the permissible XID range for > tuples. XIDs limits are restored from old cluster. Then lookup will > succeed and conflict detection will be reported. This is likely false > positive, but very annoying. Sorry, I'm still bit unclear the situation. Can you share me a concrete reproducer to demonstrate it? Best regards, Hayato Kuroda FUJITSU LIMITED
RE: Patch for migration of the pg_commit_ts directory
Hi Ajin, Thanks for the review, PSA new version. > 2. 0003: There is already a separate patch that preserves replication > origins during upgrade [1], so I suggest removing 0003 from this patch > set. I just retained just in case, dropped now. > 3. 0001/0002: I agree with Maxim that 0001 shouldn't be committed > without 0002 (or without origins being preserved). Otherwise the wider > commit_ts range turns stale origin IDs into false > update/delete_origin_differs conflicts, as Sawada-san showed. Hmm, I'm still unclear the situation. Can you share me the workload? > 4. 0002: The option name --pg-commit-ts and the help text "copy > pg_commit_ts directory" describe the implementation rather than the > behaviour. How about something like --preserve-commit-timestamps? > Also, the help line is placed between -V and --clone, which breaks the > alphabetical order of the long options. Updated. how do you feel? Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Patch for migration of the pg_commit_ts directory
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Hello
Without the origin preservation patch Sawada-san's scenario upthread
still reproduces:
-- On the old subscriber (track_commit_timestamp=on):
CREATE TABLE test (id int primary key, t text);
CREATE SUBSCRIPTION mysub CONNECTION '...' PUBLICATION pub;
CREATE SUBSCRIPTION a_dummy CONNECTION '...' PUBLICATION pub WITH
(connect = false, enabled = false);
-- wait for mysub's table sync to reach 'r', then on the publisher:
INSERT INTO test VALUES (1, 'pub-insert');
-- subscriber: pg_xact_commit_timestamp_origin(xmin).roident = 1 (mysub)
ALTER SUBSCRIPTION mysub DISABLE;
Then pg_upgrade --preserve-commit-timestamps into a new cluster with
track_commit_timestamp=on, enable mysub, and run UPDATE test SET t =
'pub-update' WHERE id = 1 on the publisher. Origins are recreated in
subscription name order, so a_dummy gets roident 1 and mysub gets 2,
but the copied commit_ts entry still says 1:
LOG: conflict detected on relation "public.test":
conflict=update_origin_differs
DETAIL: Updating the row that was modified by a different origin
"pg_16408" in transaction 672 ...: local row (1, pub-insert), remote
row (1, pub-update), replica identity (id)=(1).
CONTEXT: processing remote data for replication origin "pg_16409"
during message type "UPDATE" ...
Even as an opt-in feature, this doesn't seem right if this gets
committed first. Maybe that has to be an explicit prerequisite for the
patch, or until the origin preservation patch gets committed,
pg_upgrade could refuse or at least warn when the option is used and
the old cluster has subscriptions?
And there's another corner case issue: the commit_ts window is read
before the old server is started, and it isn't re-read later.
If that start runs with track_commit_timestamp=off,
DeactivateCommitTs() deletes everything in pg_commit_ts. pg_upgrade
then copies the empty directory, sets the stale window with
pg_resetwal -c, and finishes successfully. That cam be reproduced in
multiple ways: either the old cluster's postgresql.conf was changed to
off before the shutdown for the upgrade, or pg_upgrade -o "-c
track_commit_timestamp=off".
After the upgrade, once the old xids are more than one segment behind nextXid:
SELECT pg_xact_commit_timestamp('666'::xid);
ERROR: could not open file "pg_commit_ts/0000": No such file or directory
DETAIL: Could not access commit timestamp of transaction 666.
- Commit timestamps and origin data are not preserved during the upgrade.
- As a result, even if
+ FIXME: must be updated after the replication origin can be preserved.
+ Origin data is not preserved during the upgrade. As a result, even if
Shouldn't this also mention that preserve-commit-timestamps is opt-in?
RE: Patch for migration of the pg_commit_ts directory
Hey Zsolt, Thanks for paying attention the thread! PSA new version. > Without the origin preservation patch Sawada-san's scenario upthread > still reproduces: > > -- On the old subscriber (track_commit_timestamp=on): > CREATE TABLE test (id int primary key, t text); > CREATE SUBSCRIPTION mysub CONNECTION '...' PUBLICATION pub; > CREATE SUBSCRIPTION a_dummy CONNECTION '...' PUBLICATION pub WITH > (connect = false, enabled = false); > -- wait for mysub's table sync to reach 'r', then on the publisher: > INSERT INTO test VALUES (1, 'pub-insert'); > -- subscriber: pg_xact_commit_timestamp_origin(xmin).roident = 1 (mysub) > ALTER SUBSCRIPTION mysub DISABLE; > > Then pg_upgrade --preserve-commit-timestamps into a new cluster with > track_commit_timestamp=on, enable mysub, and run UPDATE test SET t = > 'pub-update' WHERE id = 1 on the publisher. Origins are recreated in > subscription name order, so a_dummy gets roident 1 and mysub gets 2, > but the copied commit_ts entry still says 1: > > LOG: conflict detected on relation "public.test": > conflict=update_origin_differs > DETAIL: Updating the row that was modified by a different origin > "pg_16408" in transaction 672 ...: local row (1, pub-insert), remote > row (1, pub-update), replica identity (id)=(1). > CONTEXT: processing remote data for replication origin "pg_16409" > during message type "UPDATE" ... > > Even as an opt-in feature, this doesn't seem right if this gets > committed first. To clarify, we're not intended that this patch can be pushed alone, a patch which preserves replication origins [1] is a prerequisite. I'm not motivated to add additional guard in the patch, the commit message was updated for it. > And there's another corner case issue: the commit_ts window is read > before the old server is started, and it isn't re-read later. Good catch. I don't think it's like to happen but should be fixed. My fix idea is to check the GUC parameter for the target (old) instance and migrate commit_ts only if it's true. New version implemented the same. > Shouldn't this also mention that preserve-commit-timestamps is opt-in? I'm not excited to update docs around here because it's entangled with another thread, but added an one line. BTW, while updating the doc, I found that all entries in the same variablelist must have id attributes if we want to refer one of them. It's not directly related with the code but done in 0001. [1]: https://commitfest.postgresql.org/patch/6743/ Best regards, Hayato Kuroda FUJITSU LIMITED