diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c index 4aff315b7c..203d4c411e 100644 --- a/contrib/postgres_fdw/connection.c +++ b/contrib/postgres_fdw/connection.c @@ -104,7 +104,7 @@ static bool pgfdw_cancel_query(PGconn *conn); static bool pgfdw_exec_cleanup_query(PGconn *conn, const char *query, bool ignore_errors); static bool pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, - PGresult **result); + PGresult **result, const char *query); static void pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql, bool toplevel); static bool UserMappingPasswordRequired(UserMapping *user); @@ -1179,7 +1179,7 @@ pgfdw_cancel_query(PGconn *conn) } /* Get and discard the result of the query. */ - if (pgfdw_get_cleanup_result(conn, endtime, &result)) + if (pgfdw_get_cleanup_result(conn, endtime, &result, "(cancel request)")) return false; PQclear(result); @@ -1223,7 +1223,7 @@ pgfdw_exec_cleanup_query(PGconn *conn, const char *query, bool ignore_errors) } /* Get the result of the query. */ - if (pgfdw_get_cleanup_result(conn, endtime, &result)) + if (pgfdw_get_cleanup_result(conn, endtime, &result, query)) return false; /* Issue a warning if not successful. */ @@ -1248,7 +1248,8 @@ pgfdw_exec_cleanup_query(PGconn *conn, const char *query, bool ignore_errors) * Sets *result except in case of a timeout. */ static bool -pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result) +pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result, + const char *query) { volatile bool timed_out = false; PGresult *volatile last_res = NULL; @@ -1270,6 +1271,10 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result) cur_timeout = TimestampDifferenceMilliseconds(now, endtime); if (cur_timeout <= 0) { + ereport(WARNING, + (errmsg("could not get query result due to timeout"), + query ? errcontext("remote SQL command: %s", query) : 0)); + timed_out = true; goto exit; } @@ -1289,6 +1294,8 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result) { if (!PQconsumeInput(conn)) { + pgfdw_report_error(WARNING, NULL, conn, false, query); + /* connection trouble; treat the same as a timeout */ timed_out = true; goto exit;