diff --git a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp index afccc4b6b..312665d50 100755 --- a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp +++ b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp @@ -887,7 +887,6 @@ static void FlushAllStatement() static void StatementFlush() { - const int flush_usleep_interval = 100000; int count = 0; bool is_readonly_log_needed = false; @@ -899,7 +898,7 @@ static void StatementFlush() ereport(WARNING, (errmodule(MOD_INSTR), errmsg("[Statement] cannot flush suspend list to statement_history in a read-only transaction"))); } - pg_usleep(flush_usleep_interval); + pg_usleep(FLUSH_USLEEP_INTERVAL); continue; } if (is_readonly_log_needed) { @@ -919,7 +918,7 @@ static void StatementFlush() /* report statement_history state to pgstat */ if (OidIsValid(u_sess->proc_cxt.MyDatabaseId)) pgstat_report_stat(true); - pg_usleep(flush_usleep_interval); + pg_usleep(FLUSH_USLEEP_INTERVAL); } } diff --git a/src/gausskernel/storage/ipc/ipc.cpp b/src/gausskernel/storage/ipc/ipc.cpp index b1e426dd0..b5e2c738a 100644 --- a/src/gausskernel/storage/ipc/ipc.cpp +++ b/src/gausskernel/storage/ipc/ipc.cpp @@ -51,6 +51,7 @@ #include "utils/plog.h" #include "threadpool/threadpool.h" #include "instruments/instr_user.h" +#include "instruments/instr_statement.h" #include "utils/postinit.h" #ifdef ENABLE_MOT #include "storage/mot/mot_fdw.h" @@ -167,6 +168,15 @@ void proc_exit(int code) } } + /* Wait for all statements that have not been flushed to complete flushing. + * The flush usleep wait interval is 100,000 microseconds, + * therefore we set it here to 300,000 microseconds for a safe margin. + */ + if (u_sess->statement_cxt.suspend_count != 0) { + int flushWaitInterval = 3 * FLUSH_USLEEP_INTERVAL; + pg_usleep(flushWaitInterval); + } + if (t_thrd.utils_cxt.backend_reserved) { ereport(DEBUG2, (errmodule(MOD_MEM), errmsg("[BackendReservedExit] current thread role is: %d, used memory is: %d MB\n", diff --git a/src/include/instruments/instr_statement.h b/src/include/instruments/instr_statement.h index 49161d897..2d35adda7 100644 --- a/src/include/instruments/instr_statement.h +++ b/src/include/instruments/instr_statement.h @@ -162,7 +162,7 @@ struct StatementDetail { #define STATEMENT_DETAIL_TYPE_PRETTY "pretty" #define Anum_statement_history_finish_time 12 - +#define FLUSH_USLEEP_INTERVAL 100000 /* entry for full/slow sql stat */ typedef struct StatementStatContext { void *next; /* next item if in free or suspend list */