diff --git a/repmgr.c b/repmgr.c index 7ff975cb..a541faef 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1035,6 +1035,10 @@ stop_backup: log_info(_("%s requires primary to keep WAL files %s until at least %s\n"), progname, first_wal_segment, last_wal_segment); + /* Finished with the database connection now */ + PQclear(res); + PQfinish(conn); + /* * Only free the first_wal_segment since it was copied out of the * pqresult. @@ -1042,9 +1046,6 @@ stop_backup: free(first_wal_segment); first_wal_segment = NULL; - PQclear(res); - PQfinish(conn); - /* If the rsync failed then exit */ if (r != 0) exit(ERR_BAD_RSYNC); @@ -1064,9 +1065,6 @@ stop_backup: /* Finally, write the recovery.conf file */ create_recovery_file(runtime_options.dest_dir, NULL); - PQclear(res); - PQfinish(conn); - /* * We don't start the service yet because we still may want to * move the directory