src/server/plugins/postgresql/resource.c

changeset 655
337cda289f34
parent 390
144332e23ffd
--- a/src/server/plugins/postgresql/resource.c	Sun Dec 07 17:50:52 2025 +0100
+++ b/src/server/plugins/postgresql/resource.c	Sun Dec 07 17:58:47 2025 +0100
@@ -118,6 +118,16 @@
 }
 
 int pg_resourcepool_prepare(PgResourcePool *pg, PgResource *res) {
+    if(PQstatus(res->connection) != CONNECTION_OK) {
+        log_ereport(LOG_WARN, "pg_resourcepool_prepare: connection not ok");
+        // try to recreate the resource
+        PQfinish(res->connection);
+        res->connection = PQconnectdb(pg->connection);
+        if(pg_check_connection(LOG_FAILURE, pg->name, res->connection)) {
+            return 1;
+        }
+    }
+    
     PGresult *result = PQexec(res->connection, "BEGIN");
     PQclear(result); // TODO: handle error
     return 0;

mercurial