diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-16 11:52:05 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-16 11:52:05 -0400 |
commit | 6b787d9e32005867ee3660d1ea20f447810a403d (patch) | |
tree | ba42afc0950af8d974a174e1bfff32f89ee74fb4 /src/backend/replication/logical/tablesync.c | |
parent | d0303bc8d2670d11c9df9220aa08a2c33529e100 (diff) | |
download | postgresql-6b787d9e32005867ee3660d1ea20f447810a403d.tar.gz postgresql-6b787d9e32005867ee3660d1ea20f447810a403d.zip |
Improve SQLSTATE reporting in some replication-related code.
I started out with the goal of reporting ERRCODE_CONNECTION_FAILURE
when walrcv_connect() fails, but as I looked around I realized that
whoever wrote this code was of the opinion that errcodes are purely
optional. That's not my understanding of our project policy. Hence,
make sure that an errcode is provided in each ereport that (a) is
ERROR or higher level and (b) isn't arguably an internal logic error.
Also fix some very dubious existing errcode assignments.
While this is not per policy, it's also largely cosmetic, since few
of these cases could get reported to applications. So I don't
feel a need to back-patch.
Discussion: https://postgr.es/m/2189704.1623512522@sss.pgh.pa.us
Diffstat (limited to 'src/backend/replication/logical/tablesync.c')
-rw-r--r-- | src/backend/replication/logical/tablesync.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 67f907cdd96..cc50eb875b1 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -723,13 +723,15 @@ fetch_remote_table_info(char *nspname, char *relname, if (res->status != WALRCV_OK_TUPLES) ereport(ERROR, - (errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s", + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s", nspname, relname, res->err))); slot = MakeSingleTupleTableSlot(res->tupledesc, &TTSOpsMinimalTuple); if (!tuplestore_gettupleslot(res->tuplestore, true, false, slot)) ereport(ERROR, - (errmsg("table \"%s.%s\" not found on publisher", + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("table \"%s.%s\" not found on publisher", nspname, relname))); lrel->remoteid = DatumGetObjectId(slot_getattr(slot, 1, &isnull)); @@ -764,7 +766,8 @@ fetch_remote_table_info(char *nspname, char *relname, if (res->status != WALRCV_OK_TUPLES) ereport(ERROR, - (errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s", + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s", nspname, relname, res->err))); /* We don't know the number of rows coming, so allocate enough space. */ @@ -851,7 +854,8 @@ copy_table(Relation rel) pfree(cmd.data); if (res->status != WALRCV_OK_COPY_OUT) ereport(ERROR, - (errmsg("could not start initial contents copy for table \"%s.%s\": %s", + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("could not start initial contents copy for table \"%s.%s\": %s", lrel.nspname, lrel.relname, res->err))); walrcv_clear_result(res); @@ -967,7 +971,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) walrcv_connect(MySubscription->conninfo, true, slotname, &err); if (LogRepWorkerWalRcvConn == NULL) ereport(ERROR, - (errmsg("could not connect to the publisher: %s", err))); + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("could not connect to the publisher: %s", err))); Assert(MyLogicalRepWorker->relstate == SUBREL_STATE_INIT || MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC || @@ -1050,7 +1055,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) 0, NULL); if (res->status != WALRCV_OK_COMMAND) ereport(ERROR, - (errmsg("table copy could not start transaction on publisher: %s", + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("table copy could not start transaction on publisher: %s", res->err))); walrcv_clear_result(res); @@ -1110,7 +1116,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) res = walrcv_exec(LogRepWorkerWalRcvConn, "COMMIT", 0, NULL); if (res->status != WALRCV_OK_COMMAND) ereport(ERROR, - (errmsg("table copy could not finish transaction on publisher: %s", + (errcode(ERRCODE_CONNECTION_FAILURE), + errmsg("table copy could not finish transaction on publisher: %s", res->err))); walrcv_clear_result(res); |