Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBBB8-009jXX-Ln for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 10:00:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rBBB6-00GJS0-Gt for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 10:00:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBBB4-00GJRr-BC for pgsql-hackers@lists.postgresql.org; Thu, 07 Dec 2023 10:00:20 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBBB0-009E7z-Ra for pgsql-hackers@postgresql.org; Thu, 07 Dec 2023 10:00:16 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 82AD35C020B for ; Thu, 7 Dec 2023 05:00:13 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 07 Dec 2023 05:00:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1701943213; x=1702029613; bh=xa5cRgoHbI3aHe3HXkaHWJibZIqLEl7pUmE rAjrVaWU=; b=eKdyY/AUZhKC2Va7lGRwHL4xXyqN0fA/3DAa+GZyeollulHj9Ed bHUl3V0RwQ/KCG0ngIy6ZN7nsf5xgExPpor7Cq7ILSdVIdSwdP9ONiPkEvXypL4Q zzb4Zhx+8T3wa+AZW5qHvSRSev9WJNMx65U5pqO5MNxaS8WgQsvhFXaqvyp8pHEz TuICW+xaVfgoYIQY6g4XK2PwA6eXe/KUtnpKDg7xd3eTftL4b1cb71TkuzAe1GnL IxxFmNZh+8LOLo2AFbUX1+uMQjMHB+w189k7j2bFxzx+T7MigBqT1flktwZlCOlC tHmhI7PpRp5XQORZlGHyJZQUU2p1Efo1suQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1701943213; x= 1702029613; bh=xa5cRgoHbI3aHe3HXkaHWJibZIqLEl7pUmErAjrVaWU=; b=2 p1lnzTLsXGvwk+LXiEbnYeoaK7FfW3QXhERh9mxRYICwowjHnbJA88RQ3fP/bIx4 McgI2GYaRhS+5FLuPLFKx6UVWVaEOFXGAA9d01n8eGuBPMZ5hNsSTaotmMOXwAFx WCX3o87689rr1sl+cYe8g2rj56bnFleT9MysMR5LTq+uoGCL9/8yknmAeHuDw/RE y502nD96PPUGXq3Zlomrt79Kr/Gh0s4RWrB2yHD/mdl2JzYIdagcwKBzKFsMC8zk kstO54rFE/NtDgCvU0irThzcHbREJTMvasoH1OjKRlWwy8Oo+5Qvl3tqhv1+zxrL d4z87jS+WIeKcnpZ7gB1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudekvddguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuhffvfhgjtgfgsehtke ertddtvdejnecuhfhrohhmpefrvghtvghrucfgihhsvghnthhrrghuthcuoehpvghtvghr segvihhsvghnthhrrghuthdrohhrgheqnecuggftrfgrthhtvghrnhepledttdfftdevud eludeffeetgfehgeeuieeuhfeikeefledvteeutdduffduudetnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhesvghishgvnhhtrh gruhhtrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 7 Dec 2023 05:00:12 -0500 (EST) Message-ID: <93f32d1a-9309-48dc-9b7f-c110c4d48126@eisentraut.org> Date: Thu, 7 Dec 2023 11:00:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: backtrace_on_internal_error Content-Language: en-US From: Peter Eisentraut To: pgsql-hackers References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 05.12.23 11:55, Peter Eisentraut wrote: > I think the implementation would be very simple, something like > > diff --git a/src/backend/utils/error/elog.c > b/src/backend/utils/error/elog.c > index 6aeb855e49..45d40abe92 100644 > --- a/src/backend/utils/error/elog.c > +++ b/src/backend/utils/error/elog.c > @@ -498,9 +498,11 @@ errfinish(const char *filename, int lineno, const > char *funcname) > >     /* Collect backtrace, if enabled and we didn't already */ >     if (!edata->backtrace && > -       edata->funcname && > -       backtrace_functions && > -       matches_backtrace_functions(edata->funcname)) > +       ((edata->funcname && > +         backtrace_functions && > +         matches_backtrace_functions(edata->funcname)) || > +        (edata->sqlerrcode == ERRCODE_INTERNAL_ERROR && > +         backtrace_on_internal_error))) >         set_backtrace(edata, 2); > >     /* > > where backtrace_on_internal_error would be a GUC variable. It looks like many people found this idea worthwhile. Several people asked for a way to set the minimum log level for this treatment. Something else to note: I wrote the above code to check the error code; it doesn't check whether the original code write elog() or ereport(). There are some internal errors that are written as ereport() now. Others might be changed from time to time; until now there would have been no external effect from this. I think it would be weird to introduce a difference between these forms now. But then, elog() only uses the error code ERRCODE_INTERNAL_ERROR if the error level is >=ERROR. So this already excludes everything below. Do people want a way to distinguish ERROR/FATAL/PANIC? Or do people want a way to enable backtraces for elog(LOG)? This didn't look too interesting to me. (Many current elog(LOG) calls are behind additional guards like TRACE_SORT or LOCK_DEBUG.) If neither of these two are very interesting, then the above code would already appear to do what was asked.