1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-21 05:21:08 +03:00

Add logical change details to logical replication worker errcontext.

Previously, on the subscriber, we set the error context callback for the
tuple data conversion failures. This commit replaces the existing error
context callback with a comprehensive one so that it shows not only the
details of data conversion failures but also the details of logical change
being applied by the apply worker or table sync worker. The additional
information displayed will be the command, transaction id, and timestamp.

The error context is added to an error only when applying a change but not
while doing other work like receiving data etc.

This will help users in diagnosing the problems that occur during logical
replication. It also can be used for future work that allows skipping a
particular transaction on the subscriber.

Author: Masahiko Sawada
Reviewed-by: Hou Zhijie, Greg Nancarrow, Haiying Tang, Amit Kapila
Tested-by: Haiying Tang
Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
This commit is contained in:
Amit Kapila
2021-08-27 08:30:23 +05:30
parent 191dce109b
commit abc0910e2e
4 changed files with 235 additions and 80 deletions

View File

@@ -1156,3 +1156,56 @@ logicalrep_read_stream_abort(StringInfo in, TransactionId *xid,
*xid = pq_getmsgint(in, 4);
*subxid = pq_getmsgint(in, 4);
}
/*
* Get string representing LogicalRepMsgType.
*/
char *
logicalrep_message_type(LogicalRepMsgType action)
{
switch (action)
{
case LOGICAL_REP_MSG_BEGIN:
return "BEGIN";
case LOGICAL_REP_MSG_COMMIT:
return "COMMIT";
case LOGICAL_REP_MSG_ORIGIN:
return "ORIGIN";
case LOGICAL_REP_MSG_INSERT:
return "INSERT";
case LOGICAL_REP_MSG_UPDATE:
return "UPDATE";
case LOGICAL_REP_MSG_DELETE:
return "DELETE";
case LOGICAL_REP_MSG_TRUNCATE:
return "TRUNCATE";
case LOGICAL_REP_MSG_RELATION:
return "RELATION";
case LOGICAL_REP_MSG_TYPE:
return "TYPE";
case LOGICAL_REP_MSG_MESSAGE:
return "MESSAGE";
case LOGICAL_REP_MSG_BEGIN_PREPARE:
return "BEGIN PREPARE";
case LOGICAL_REP_MSG_PREPARE:
return "PREPARE";
case LOGICAL_REP_MSG_COMMIT_PREPARED:
return "COMMIT PREPARED";
case LOGICAL_REP_MSG_ROLLBACK_PREPARED:
return "ROLLBACK PREPARED";
case LOGICAL_REP_MSG_STREAM_START:
return "STREAM START";
case LOGICAL_REP_MSG_STREAM_STOP:
return "STREAM STOP";
case LOGICAL_REP_MSG_STREAM_COMMIT:
return "STREAM COMMIT";
case LOGICAL_REP_MSG_STREAM_ABORT:
return "STREAM ABORT";
case LOGICAL_REP_MSG_STREAM_PREPARE:
return "STREAM PREPARE";
}
elog(ERROR, "invalid logical replication message type \"%c\"", action);
return NULL; /* keep compiler quiet */
}