From 37a41a66f95b5cc83ba276544434b67585771e22 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 18 Mar 2019 15:26:16 +0900 Subject: [PATCH] Check node recovery type before attempting to write an event record In some corner cases (e.g. immediately after a switchover) where the current primary has not yet been determined, the provided connection might not be writeable. This prevents error messages such as "cannot execute INSERT in a read-only transaction" generating unnecessary noise in the logs. --- dbutils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbutils.c b/dbutils.c index 1b657ce5..e2636ceb 100644 --- a/dbutils.c +++ b/dbutils.c @@ -3546,9 +3546,10 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char log_verbose(LOG_DEBUG, "_create_event(): event is \"%s\" for node %i", event, node_id); /* - * Only attempt to write a record if a connection handle was provided. + * Only attempt to write a record if a connection handle was provided, + * and the connection handle points to a node which is not in recovery. */ - if (conn != NULL && PQstatus(conn) == CONNECTION_OK) + if (conn != NULL && PQstatus(conn) == CONNECTION_OK && get_recovery_type(conn) == RECTYPE_PRIMARY) { int n_node_id = htonl(node_id); char *t_successful = successful ? "TRUE" : "FALSE";