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 1sjm9x-003rE1-2A for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 20:54:25 +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 1sjm9v-007gKD-3h for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 20:54:23 +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 1sjm9u-007gK5-I3 for pgsql-hackers@lists.postgresql.org; Thu, 29 Aug 2024 20:54:23 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sjm9r-0024Rr-VY for pgsql-hackers@lists.postgresql.org; Thu, 29 Aug 2024 20:54:21 +0000 Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6bf7a2035d9so21576606d6.1 for ; Thu, 29 Aug 2024 13:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1724964858; x=1725569658; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ATI28GYnIbvfi64veM2T6Yyb+RNy8hIh1Ij7Y9VbTbs=; b=QSQ5UIm1HfqKJxTah8+9nMzdgwLeM32/+yGf4i2tmFVjD2R1RM8OAt+Xpah+qdTacN KBZFl8elncmYSVo10oXUWLFcOFNQ8FafJTNBvRhYnVEngdmkXtsGQ+jyW3MGEYSs1wVW yH+HXNwVBNZBWEfklxMjSd5mSpAu0SAVaIe4O5dujv5+YzoKGVqhKkoTbqOMnKXoPyAb q3LrUp5I0nfYUy9H6AEI/1cfXRTc94lwlFW4xDZPgB5IXp0NIET6HxIpHE9dbvPMVXeJ a3TF7qHCZQPPWXlJGwWegFsUAe1f0L8oT3K2f88GjSCltxMWHDO89iz5i11n2ZllO2Lm EEfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724964858; x=1725569658; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ATI28GYnIbvfi64veM2T6Yyb+RNy8hIh1Ij7Y9VbTbs=; b=GEsaF51ZIR0RtndG51LOx0Lv6qqC+GId7Lx5G6zokJlD6xRrNgAHlss9k/+YzcdBX6 JDrhIHE47n1TZTp9NL+aU65O8MO+/lgg09iBr5kzFm4ldSdKK4AVjrqUpZvxsjANzo/U ntxspHTRAZXU3PZg8vFteExGiYSkbOSEJYgUUyfp7BFYUULoyF06+yGMRdrLlGC/YJbO SFeWhAfmk7q8mHH5eZF4fccAuFtDcWNMsmCzxoxfNU0JLw+fk7kgV8wl1hbNIJysNSSL 2ChiV5YpTQ81LXMYWphB50PFr5jCIYodxmGGsy03HSwIh8RQACfG9jrd3qQ2Wl7032/W e4Ag== X-Forwarded-Encrypted: i=1; AJvYcCWWIpZsqMQ1wcONY31P6l6RTGOee94qzL7tw7HQkO8Wu9f6aTewrqQSyem1P6CEJGauIRn4EtfqNbiws5lD@lists.postgresql.org X-Gm-Message-State: AOJu0Yz3xALin/LUTp+QO8WfiLXKZ5rzq0LvtZHzAGVzs8hiA6n5SuSI jfMolqZOeSq6XWnuzhe0T0E44G7NRiTIdldjeH57DTOyT6loUhz3QZacoPE0Lh4= X-Google-Smtp-Source: AGHT+IGKyVpDXlBF897QxAC5GNKMkAs15ZFGwwRYcM/dXs+p34NClWlWZQEz5nxKfqpLr/StfE3KYA== X-Received: by 2002:a05:6214:2f03:b0:6c1:637e:b5c8 with SMTP id 6a1803df08f44-6c3496af7a0mr1667626d6.5.1724964858281; Thu, 29 Aug 2024 13:54:18 -0700 (PDT) Received: from ?IPV6:2605:a601:9180:9800::2bb? ([2605:a601:9180:9800::2bb]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-6c340c96804sm8621906d6.93.2024.08.29.13.54.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Aug 2024 13:54:17 -0700 (PDT) Message-ID: Date: Thu, 29 Aug 2024 16:54:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pl/pgperl Patch for adding $_FN detail just like triggers have for $_TD To: Mark Murawski , pgsql-hackers@lists.postgresql.org References: <5d3f6ead-fb58-44bd-9ef4-2283af66a664@intellasoft.net> <8527bb5f-7507-4b44-badf-4ba53e63f531@intellasoft.net> <1b0bef66-f5ae-434e-a9e1-201c5fbab4ce@dunslane.net> <102c0925-7ba5-4aec-9160-945d4b5ee4bf@intellasoft.net> From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNJEFuZHJldyBEdW5zdGFuIDxh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DQ4 6bmDCy/sBgcbz9mTpoLC11HLoPae6YN9nBNQRZDcEFEu54OaVOqlIdbA6m+POIBCXZdHOFc0 WoDTgxHRzC1jgQNidyd6tKqcsVJs0dzF0oKTmFFmUAqTdJO12LBuNA1rlqrR3EtpYk8B/wtS 5dIMD7Q8hwQpL+4C6GNpb6ZKnPkLi47pDOLhz2qBrqN+rqUEsT3YnExYpzj5yOBi+FlmV1Hw 49QYe1sn2ZPs In-Reply-To: <102c0925-7ba5-4aec-9160-945d4b5ee4bf@intellasoft.net> 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 2024-08-29 Th 1:01 PM, Mark Murawski wrote: > > > On 8/29/24 11:56, Andrew Dunstan wrote: >> >> On 2024-08-28 We 5:53 PM, Mark Murawski wrote: >>> Hi Hackers! >>> >>> This would be version v1 of this feature >>> >>> Basically, the subject says it all: pl/pgperl Patch for being able >>> to tell which function you're in. >>> This is a hashref so it will be possible to populate new and >>> exciting other details in the future as the need arises >>> >>> This also greatly improves logging capabilities for things like >>> catching warnings,  Because as it stands right now, there's no >>> information that can assist with locating the source of a warning >>> like this: >>> >>> # tail -f /var/log/postgresql.log >>> ******* GOT A WARNING - Use of uninitialized value $prefix in >>> concatenation (.) or string at (eval 531) line 48. >>> >>> Now, with $_FN you can do this: >>> >>> >>> CREATE OR REPLACE FUNCTION throw_warning() RETURNS text LANGUAGE >>> plperlu AS $function$ >>> >>> use warnings; >>> use strict; >>> use Data::Dumper; >>> >>> $SIG{__WARN__} = sub { >>>   elog(NOTICE, Dumper($_FN)); >>> >>>   print STDERR "In Function: $_FN->{name}: $_[0]\n"; >>> }; >>> >>> my $a; >>> print "$a"; # uninit! >>> >>> return undef; >>> >>> $function$ >>> ; >>> >>> This patch is against 12 which is still our production branch. This >>> could easily be also patched against newer releases as well. >>> >>> I've been using this code in production now for about 3 years, it's >>> greatly helped track down issues.  And there shouldn't be anything >>> platform-specific here, it's all regular perl API >>> >>> I'm not sure about adding testing.  This is my first postgres patch, >>> so any guidance on adding regression testing would be appreciated. >>> >>> The rationale for this has come from the need to know the source >>> function name, and we've typically resorted to things like this in >>> the past: >>> >>> CREATE OR REPLACE FUNCTION throw_warning() RETURNS text LANGUAGE >>> plperlu AS $function$ >>> my $function_name = 'throw_warning'; >>> $SIG{__WARN__} = sub { print STDERR "In Function: $function_name: >>> $_[0]\n"; } >>> $function$ >>> ; >>> >>> We've literally had to copy/paste this all over and it's something >>> that postgres should just 'give you' since it knows the name >>> already, just like when triggers pass you $_TD with all the >>> pertinent information >>> >>> A wishlist item would be for postgres plperl to automatically >>> prepend the function name and schema when throwing perl warnings so >>> you don't have to do your own __WARN__ handler, but this is the next >>> best thing. >> >> >> >> I'm not necessarily opposed to this, but the analogy to $_TD isn't >> really apt.  You can't know the trigger data at compile time, whereas >> you can know the function's name at compile time, using just the >> mechanism you find irksome. >> >> And if we're going to do it for plperl, shouldn't we do it for other >> PLs? >> >> >> > > Hi Andrew, > > > Thanks for the feedback. > > > 1) Why is this not similar to _TD?  It literally operates identically. > At run-time it passes you $_TD  for triggers.    Same her for > functions.  This is all run-time.   What exactly is the issue you're > trying to point out? It's not the same as the trigger data case because the function name is knowable at compile time, as in fact you have demonstrated. You just find it a bit inconvenient to have to code for that knowledge. By contrast, trigger data is ONLY knowable at run time. But I don't see that it is such a heavy burden to have to write   my $funcname = "foo"; or similar in your function. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com