Merge pull request #150 from darkfronza/PG-290_fix_crash_higher_debug_level_master

PG-290: Fix crash when enabling debugging log level on PostgreSQL.
pull/156/head
Ibrar Ahmed 2021-12-07 15:17:39 -05:00 committed by GitHub
commit 91073aad78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -1123,6 +1123,9 @@ pg_get_backend_status(void)
PgBackendStatus *beentry;
local_beentry = pgstat_fetch_stat_local_beentry(i);
if (!local_beentry)
continue;
beentry = &local_beentry->backendStatus;
if (beentry->st_procpid == MyProcPid)
@ -1135,6 +1138,8 @@ static int
pg_get_application_name(char *application_name)
{
PgBackendStatus *beentry = pg_get_backend_status();
if (!beentry)
return snprintf(application_name, APPLICATIONNAME_LEN, "%s", "postmaster");
snprintf(application_name, APPLICATIONNAME_LEN, "%s", beentry->st_appname);
return strlen(application_name);
@ -1157,6 +1162,9 @@ pg_get_client_addr(void)
char remote_host[NI_MAXHOST];
int ret;
if (!beentry)
return ntohl(inet_addr("127.0.0.1"));
memset(remote_host, 0x0, NI_MAXHOST);
ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
beentry->st_clientaddr.salen,
@ -1481,7 +1489,13 @@ pgss_store(uint64 queryid,
return;
Assert(query != NULL);
userid = GetUserId();
if (kind == PGSS_ERROR)
{
int sec_ctx;
GetUserIdAndSecContext((Oid *)&userid, &sec_ctx);
}
else
userid = GetUserId();
application_name_len = pg_get_application_name(application_name);
planid = plan_info ? plan_info->planid: 0;
@ -3303,6 +3317,10 @@ pgsm_emit_log_hook(ErrorData *edata)
if (IsParallelWorker())
return;
/* Check if PostgreSQL has finished its own bootstraping code. */
if (MyProc == NULL)
return;
if ((edata->elevel == ERROR || edata->elevel == WARNING || edata->elevel == INFO || edata->elevel == DEBUG1))
{
uint64 queryid = 0;