pg_createsubscriber: Remove some code bloat in the atexit() callback

This commit adjusts some code added by e117cfb2f6c6 in the atexit()
callback of pg_createsubscriber.c, in charge of performing post-failure
cleanup actions.  The code loops over all the databases specified, and
it is changed here to rely on a single LogicalRepInfo for each database
rather than always using LogicalRepInfos, simplifying its logic.

Author: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/CAHut+PtdBSVi4iH7BObDVwDNVwOpn+H3fezOBdSTtENx+rhNMw@mail.gmail.com
This commit is contained in:
Michael Paquier 2025-03-16 19:20:49 +09:00
parent 771ba90298
commit 83e5763d4d

View File

@ -184,17 +184,19 @@ cleanup_objects_atexit(void)
for (int i = 0; i < num_dbs; i++) for (int i = 0; i < num_dbs; i++)
{ {
if (dbinfos.dbinfo[i].made_publication || dbinfos.dbinfo[i].made_replslot) struct LogicalRepInfo *dbinfo = &dbinfos.dbinfo[i];
if (dbinfo->made_publication || dbinfo->made_replslot)
{ {
PGconn *conn; PGconn *conn;
conn = connect_database(dbinfos.dbinfo[i].pubconninfo, false); conn = connect_database(dbinfo->pubconninfo, false);
if (conn != NULL) if (conn != NULL)
{ {
if (dbinfos.dbinfo[i].made_publication) if (dbinfo->made_publication)
drop_publication(conn, &dbinfos.dbinfo[i]); drop_publication(conn, dbinfo);
if (dbinfos.dbinfo[i].made_replslot) if (dbinfo->made_replslot)
drop_replication_slot(conn, &dbinfos.dbinfo[i], dbinfos.dbinfo[i].replslotname); drop_replication_slot(conn, dbinfo, dbinfo->replslotname);
disconnect_database(conn, false); disconnect_database(conn, false);
} }
else else
@ -204,18 +206,18 @@ cleanup_objects_atexit(void)
* that some objects were left on primary and should be * that some objects were left on primary and should be
* removed before trying again. * removed before trying again.
*/ */
if (dbinfos.dbinfo[i].made_publication) if (dbinfo->made_publication)
{ {
pg_log_warning("publication \"%s\" created in database \"%s\" on primary was left behind", pg_log_warning("publication \"%s\" created in database \"%s\" on primary was left behind",
dbinfos.dbinfo[i].pubname, dbinfo->pubname,
dbinfos.dbinfo[i].dbname); dbinfo->dbname);
pg_log_warning_hint("Drop this publication before trying again."); pg_log_warning_hint("Drop this publication before trying again.");
} }
if (dbinfos.dbinfo[i].made_replslot) if (dbinfo->made_replslot)
{ {
pg_log_warning("replication slot \"%s\" created in database \"%s\" on primary was left behind", pg_log_warning("replication slot \"%s\" created in database \"%s\" on primary was left behind",
dbinfos.dbinfo[i].replslotname, dbinfo->replslotname,
dbinfos.dbinfo[i].dbname); dbinfo->dbname);
pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files."); pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files.");
} }
} }