1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

Improve logical replication connection-failure messages.

These messages mostly said "could not connect to the publisher: %s"
which is lacking context.  Add some verbiage to indicate which
subscription or worker process is failing.

Nisha Moond

Discussion: https://postgr.es/m/CABdArM7q1=zqL++cYd0hVMg3u_tc0S=0Of=Um-KvDhLony0cSg@mail.gmail.com
This commit is contained in:
Tom Lane 2024-07-11 13:21:13 -04:00
parent a0f1fce80c
commit 0d8bd0a72e
7 changed files with 20 additions and 12 deletions

View File

@ -755,7 +755,8 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt,
if (!wrconn)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the publisher: %s", err)));
errmsg("subscription \"%s\" could not connect to the publisher: %s",
stmt->subname, err)));
PG_TRY();
{
@ -888,7 +889,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data,
if (!wrconn)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the publisher: %s", err)));
errmsg("subscription \"%s\" could not connect to the publisher: %s",
sub->name, err)));
PG_TRY();
{
@ -1521,7 +1523,8 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
if (!wrconn)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the publisher: %s", err)));
errmsg("subscription \"%s\" could not connect to the publisher: %s",
sub->name, err)));
PG_TRY();
{

View File

@ -1463,7 +1463,8 @@ ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len)
if (!wrconn)
ereport(ERROR,
errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the primary server: %s", err));
errmsg("synchronization worker \"%s\" could not connect to the primary server: %s",
app_name.data, err));
/*
* Register the disconnection callback.

View File

@ -1342,7 +1342,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
if (LogRepWorkerWalRcvConn == NULL)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the publisher: %s", err)));
errmsg("table synchronization worker for subscription \"%s\" could not connect to the publisher: %s",
MySubscription->name, err)));
Assert(MyLogicalRepWorker->relstate == SUBREL_STATE_INIT ||
MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC ||

View File

@ -4500,7 +4500,8 @@ run_apply_worker()
if (LogRepWorkerWalRcvConn == NULL)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the publisher: %s", err)));
errmsg("apply worker for subscription \"%s\" could not connect to the publisher: %s",
MySubscription->name, err)));
/*
* We don't really use the output identify_system for anything but it does

View File

@ -898,7 +898,8 @@ pg_sync_replication_slots(PG_FUNCTION_ARGS)
if (!wrconn)
ereport(ERROR,
errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the primary server: %s", err));
errmsg("synchronization worker \"%s\" could not connect to the primary server: %s",
app_name.data, err));
SyncReplicationSlots(wrconn);

View File

@ -195,6 +195,7 @@ WalReceiverMain(char *startup_data, size_t startup_data_len)
char *err;
char *sender_host = NULL;
int sender_port = 0;
char *appname;
Assert(startup_data_len == 0);
@ -298,13 +299,13 @@ WalReceiverMain(char *startup_data, size_t startup_data_len)
sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
/* Establish the connection to the primary for XLOG streaming */
wrconn = walrcv_connect(conninfo, true, false, false,
cluster_name[0] ? cluster_name : "walreceiver",
&err);
appname = cluster_name[0] ? cluster_name : "walreceiver";
wrconn = walrcv_connect(conninfo, true, false, false, appname, &err);
if (!wrconn)
ereport(ERROR,
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("could not connect to the primary server: %s", err)));
errmsg("streaming replication receiver \"%s\" could not connect to the primary server: %s",
appname, err)));
/*
* Save user-visible connection string. This clobbers the original

View File

@ -139,7 +139,7 @@ ERROR: invalid connection string syntax: invalid connection option "i_dont_exis
-- fail, connection string parses, but doesn't work (and does so without
-- connecting, so this is reliable and safe)
CREATE SUBSCRIPTION regress_testsub5 CONNECTION 'port=-1' PUBLICATION testpub;
ERROR: could not connect to the publisher: invalid port number: "-1"
ERROR: subscription "regress_testsub5" could not connect to the publisher: invalid port number: "-1"
-- fail - invalid connection string during ALTER
ALTER SUBSCRIPTION regress_testsub CONNECTION 'foobar';
ERROR: invalid connection string syntax: missing "=" after "foobar" in connection info string