Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9177545

Browse files
committed
Make pg_createsubscriber warn if publisher has two-phase commit enabled.
pg_createsubscriber currently always sets up logical replication with two-phase commit disabled. Improving that is not going to happen for v17. In the meantime, document the deficiency, and adjust pg_createsubscriber so that it will emit a warning if the source installation has max_prepared_transactions > 0. Hayato Kuroda (some mods by Amit Kapila and me), per complaint from Noah Misch Discussion: https://postgr.es/m/20240623062157.97.nmisch@google.com
1 parent b3f5cce commit 9177545

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

doc/src/sgml/ref/pg_createsubscriber.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@ PostgreSQL documentation
353353
<application>pg_createsubscriber</application>.
354354
</para>
355355

356+
<para>
357+
<application>pg_createsubscriber</application> sets up logical
358+
replication with two-phase commit disabled. This means that any
359+
prepared transactions will be replicated at the time
360+
of <command>COMMIT PREPARED</command>, without advance preparation.
361+
Once setup is complete, you can manually drop and re-create the
362+
subscription(s) with
363+
the <link linkend="sql-createsubscription-params-with-two-phase"><literal>two_phase</literal></link>
364+
option enabled.
365+
</para>
366+
356367
<para>
357368
<application>pg_createsubscriber</application> changes the system
358369
identifier using <application>pg_resetwal</application>. It would avoid

src/bin/pg_basebackup/pg_createsubscriber.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
823823
int cur_repslots;
824824
int max_walsenders;
825825
int cur_walsenders;
826+
int max_prepared_transactions;
826827

827828
pg_log_info("checking settings on publisher");
828829

@@ -849,23 +850,12 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
849850
* -----------------------------------------------------------------------
850851
*/
851852
res = PQexec(conn,
852-
"WITH wl AS "
853-
"(SELECT setting AS wallevel FROM pg_catalog.pg_settings "
854-
"WHERE name = 'wal_level'), "
855-
"total_mrs AS "
856-
"(SELECT setting AS tmrs FROM pg_catalog.pg_settings "
857-
"WHERE name = 'max_replication_slots'), "
858-
"cur_mrs AS "
859-
"(SELECT count(*) AS cmrs "
860-
"FROM pg_catalog.pg_replication_slots), "
861-
"total_mws AS "
862-
"(SELECT setting AS tmws FROM pg_catalog.pg_settings "
863-
"WHERE name = 'max_wal_senders'), "
864-
"cur_mws AS "
865-
"(SELECT count(*) AS cmws FROM pg_catalog.pg_stat_activity "
866-
"WHERE backend_type = 'walsender') "
867-
"SELECT wallevel, tmrs, cmrs, tmws, cmws "
868-
"FROM wl, total_mrs, cur_mrs, total_mws, cur_mws");
853+
"SELECT pg_catalog.current_setting('wal_level'),"
854+
" pg_catalog.current_setting('max_replication_slots'),"
855+
" (SELECT count(*) FROM pg_catalog.pg_replication_slots),"
856+
" pg_catalog.current_setting('max_wal_senders'),"
857+
" (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE backend_type = 'walsender'),"
858+
" pg_catalog.current_setting('max_prepared_transactions')");
869859

870860
if (PQresultStatus(res) != PGRES_TUPLES_OK)
871861
{
@@ -879,6 +869,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
879869
cur_repslots = atoi(PQgetvalue(res, 0, 2));
880870
max_walsenders = atoi(PQgetvalue(res, 0, 3));
881871
cur_walsenders = atoi(PQgetvalue(res, 0, 4));
872+
max_prepared_transactions = atoi(PQgetvalue(res, 0, 5));
882873

883874
PQclear(res);
884875

@@ -887,6 +878,8 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
887878
pg_log_debug("publisher: current replication slots: %d", cur_repslots);
888879
pg_log_debug("publisher: max_wal_senders: %d", max_walsenders);
889880
pg_log_debug("publisher: current wal senders: %d", cur_walsenders);
881+
pg_log_debug("publisher: max_prepared_transactions: %d",
882+
max_prepared_transactions);
890883

891884
disconnect_database(conn, false);
892885

@@ -914,6 +907,13 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
914907
failed = true;
915908
}
916909

910+
if (max_prepared_transactions != 0)
911+
{
912+
pg_log_warning("two_phase option will not be enabled for slots");
913+
pg_log_warning_detail("Subscriptions will be created with the two_phase option disabled. "
914+
"Prepared transactions will be replicated at COMMIT PREPARED.");
915+
}
916+
917917
pg_free(wal_level);
918918

919919
if (failed)

0 commit comments

Comments
 (0)