Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qF3di-0006H9-LY for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jun 2023 02:13:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qF3dh-000181-H6 for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Jun 2023 02:13:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qF3dh-00017s-2x for pgsql-bugs@lists.postgresql.org; Fri, 30 Jun 2023 02:13:37 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qF3dZ-001H6d-RK for pgsql-bugs@lists.postgresql.org; Fri, 30 Jun 2023 02:13:36 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-392116b8f31so951950b6e.2 for ; Thu, 29 Jun 2023 19:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=neon-tech.20221208.gappssmtp.com; s=20221208; t=1688091208; x=1690683208; h=in-reply-to:references:message-id:from:to:subject:cc:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Lewig+kML8RLSj+bfJKxCCQgUGHWkMT14sA9iyURfeQ=; b=d423rUpf3gRrIfKeitu7C/RVO90bSz4H3c3mZPWcEdJgcXBMKDUWe47jmK+ZaVdQDx 3cCTcNsfxthFIBAueGvyhuNUNzNNCEzh6I9aeqriOOnKqcyg1ri+vQjalzHZ7zReIk2z WU8yN9U1qlcQ2LEefVkKerWsm9XQi8v+gvqRtMB2M0vPIOzaQi19jgTO3MIMrbEvW/bz 1h+oUb1lQ2NVOtRDQoa6WYVBw5RfzbpEVWHxreGrOfG6x62hjT7aQYhxBRuYjOeRsRNU WjbOwV6voFEju8ZMKlnlFywooyi8JmM/FgAvVQwkW1odgRojBvvAPXtVuhon56bRiKPr Mmfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688091208; x=1690683208; h=in-reply-to:references:message-id:from:to:subject:cc:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Lewig+kML8RLSj+bfJKxCCQgUGHWkMT14sA9iyURfeQ=; b=G2mqNfYYlIwsXq1H4d09CQ/tR59kSzBbjVWd96UscXeaFpoGChzT1X6gbIxjYf470G nhdgTJLrKuexfVnCR6d2OMxq9JPUPXeOk/OprLU9L7GLqylYOmQTbNTYcSUEfLPNzzPb rx1TIS9mEcl6I2/6zjm73fQ14W5N0e1EImzeaStUE9KvA4AzbgpzF1yQRBsRdPrMn92e mpN9qyVVFOPXJbddOhnAWL3xbWFCwpaclY9mcLbWFZSpbIlMqlABJJRN1ebWUP6TMx0T dEyaIFAaRUl0GI9aKxFepDHeJMbFoSt6zDwk72OWGB/I+A90hzlrJYSL1bT7rs0k+opV eMcA== X-Gm-Message-State: AC+VfDyuZ+jpsArwKbF3eUJQal7u2/dw+kuipAnojzkRN/DTfl97yp9x IIjUtKV0h9CSyQdMWonVUD6WkA== X-Google-Smtp-Source: ACHHUZ5+Q64vT3smLkHXgYge15XlFwv3pTASt+mr0v1KfuAKd76/AVyAZO4+ADMXkVb2T4pRFMb3IA== X-Received: by 2002:a05:6808:cf:b0:3a3:6f96:f15f with SMTP id t15-20020a05680800cf00b003a36f96f15fmr1336243oic.15.1688091207805; Thu, 29 Jun 2023 19:13:27 -0700 (PDT) Received: from localhost ([2607:fb90:f280:130d:3996:e070:71ee:42fb]) by smtp.gmail.com with ESMTPSA id v9-20020a056808004900b0039ee0bd8a11sm179247oic.42.2023.06.29.19.13.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 19:13:27 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 29 Jun 2023 21:13:26 -0500 Cc: Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG To: "Heikki Linnakangas" , "Tom Lane" , , "Joe Conway" From: "Tristan Partin" Message-Id: X-Mailer: aerc 0.15.2-74-gdfabb5232875 References: <17946-3e84cb577e9551c3@postgresql.org> <1564676.1685043220@sss.pgh.pa.us> <555bb26e-c27c-ab65-028f-3fd5b82df9de@iki.fi> In-Reply-To: <555bb26e-c27c-ab65-028f-3fd5b82df9de@iki.fi> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon Jun 5, 2023 at 11:00 AM CDT, Heikki Linnakangas wrote: > On 25/05/2023 15:33, Tom Lane wrote: > > PG Bug reporting form writes: > >> After upgrading an application using Postgresql from version 10 to 12, > >> fields of type "money" are no longer generated with the =E2=82=AC symb= ol but with > >> $. > >=20 > > Hmm, seems to work for me: > > I can reproduce this: > > psql (16beta1) > Type "help" for help. > > postgres=3D# DO LANGUAGE 'plperl' $$ elog(NOTICE, 'foo') $$; > NOTICE: foo > DO > postgres=3D# SET lc_monetary TO 'en_GB.UTF-8'; > SET > postgres=3D# SELECT 12.34::money AS price; > price > -------- > $12.34 > (1 row) > > > If I don't call the plperl function, it works as expected: > > sql (16beta1) > Type "help" for help. > > postgres=3D# SET lc_monetary TO 'en_GB.UTF-8'; > SET > postgres=3D# SELECT 12.34::money AS price; > price > -------- > =C2=A312.34 > (1 row) > > I should note that 'en_GB.UTF-8' is the default locale in my system, and= =20 > that's what I used in initdb. I don't know if it makes a difference. > > > IIRC, we've seen trouble in the past with some versions of libperl > > clobbering the host application's locale settings. Maybe you > > have a plperl.on_init or plperl.on_plperl_init action that is > > causing that to happen? In any case, I'd call it a Perl bug not > > a Postgres bug > I did some debugging, initializing the perl interpreter calls uselocale()= : > > #0 __GI___uselocale (newloc=3D0x7f9f47ff0940 <_nl_C_locobj>) at=20 > ./locale/uselocale.c:31 > #1 0x00007f9f373bd069 in ?? () from=20 > /usr/lib/x86_64-linux-gnu/libperl.so.5.36 > #2 0x00007f9f373bce74 in ?? () from=20 > /usr/lib/x86_64-linux-gnu/libperl.so.5.36 > #3 0x00007f9f373bfc15 in Perl_init_i18nl10n () from=20 > /usr/lib/x86_64-linux-gnu/libperl.so.5.36 > #4 0x00007f9f48b74cfb in plperl_init_interp () at plperl.c:809 > #5 0x00007f9f48b78adc in _PG_init () at plperl.c:483 > #6 0x000055c98b8e9b63 in internal_load_library (libname=3D0x55c98bebaf90= =20 > "/home/heikki/pgsql.fsmfork/lib/plperl.so") at dfmgr.c:289 > #7 0x000055c98b8ea1c2 in load_external_function=20 > (filename=3Dfilename@entry=3D0x55c98bebb1c0 "$libdir/plperl",=20 > funcname=3Dfuncname@entry=3D0x55c98beba378 "plperl_inline_handler", > signalNotFound=3DsignalNotFound@entry=3Dtrue,=20 > filehandle=3Dfilehandle@entry=3D0x7ffd20942b48) at dfmgr.c:116 > #8 0x000055c98b8ea864 in fmgr_info_C_lang (functionId=3D129304,=20 > procedureTuple=3D0x7f9f4778ccb8, finfo=3D0x7ffd20942bf0) at fmgr.c:386 > #9 fmgr_info_cxt_security (functionId=3D129304, finfo=3D0x7ffd20942bf0,= =20 > mcxt=3D, ignore_security=3D) at fmgr.c:246 > #10 0x000055c98b8eba72 in fmgr_info (finfo=3D0x7ffd20942bf0,=20 > functionId=3D) at fmgr.c:129 > #11 OidFunctionCall1Coll (functionId=3D,=20 > collation=3Dcollation@entry=3D0, arg1=3D94324124262840) at fmgr.c:1386 > #12 0x000055c98b5e1385 in ExecuteDoStmt=20 > (pstate=3Dpstate@entry=3D0x55c98beba0b0, stmt=3Dstmt@entry=3D0x55c98be908= 58,=20 > atomic=3Datomic@entry=3Dfalse) at functioncmds.c:2144 > #13 0x000055c98b7c24ce in standard_ProcessUtility (pstmt=3D0x55c98be908e0= ,=20 > queryString=3D0x55c98be8fd50 "DO LANGUAGE 'plperl' $$ elog(NOTICE, 'foo')= =20 > $$;", readOnlyTree=3D, > context=3DPROCESS_UTILITY_TOPLEVEL, params=3D0x0, queryEnv=3D0x0,=20 > dest=3D0x55c98be90b80, qc=3D0x7ffd20942f30) at utility.c:714 > #14 0x000055c98b7c0d9f in PortalRunUtility=20 > (portal=3Dportal@entry=3D0x55c98bf0b710, pstmt=3Dpstmt@entry=3D0x55c98be9= 08e0,=20 > isTopLevel=3DisTopLevel@entry=3Dtrue, > setHoldSnapshot=3DsetHoldSnapshot@entry=3Dfalse, dest=3D0x55c98be90b= 80,=20 > qc=3D0x7ffd20942f30) at pquery.c:1158 > #15 0x000055c98b7c0ecb in PortalRunMulti=20 > (portal=3Dportal@entry=3D0x55c98bf0b710, isTopLevel=3DisTopLevel@entry=3D= true,=20 > setHoldSnapshot=3DsetHoldSnapshot@entry=3Dfalse,=20 > dest=3Ddest@entry=3D0x55c98be90b80, > altdest=3Daltdest@entry=3D0x55c98be90b80, qc=3Dqc@entry=3D0x7ffd2094= 2f30)=20 > at pquery.c:1322 > #16 0x000055c98b7c139d in PortalRun (portal=3Dportal@entry=3D0x55c98bf0b7= 10,=20 > count=3Dcount@entry=3D9223372036854775807, isTopLevel=3DisTopLevel@entry= =3Dtrue,=20 > run_once=3Drun_once@entry=3Dtrue, > dest=3Ddest@entry=3D0x55c98be90b80,=20 > altdest=3Daltdest@entry=3D0x55c98be90b80, qc=3D0x7ffd20942f30) at pquery.= c:791 > #17 0x000055c98b7bd85d in exec_simple_query (query_string=3D0x55c98be8fd5= 0=20 > "DO LANGUAGE 'plperl' $$ elog(NOTICE, 'foo') $$;") at postgres.c:1274 > #18 0x000055c98b7bf978 in PostgresMain (dbname=3D,=20 > username=3D) at postgres.c:4632 > #19 0x000055c98b73f743 in BackendRun (port=3D,=20 > port=3D) at postmaster.c:4461 > #20 BackendStartup (port=3D) at postmaster.c:4189 > #21 ServerLoop () at postmaster.c:1779 > #22 0x000055c98b74077a in PostmasterMain (argc=3Dargc@entry=3D3,=20 > argv=3Dargv@entry=3D0x55c98be88fc0) at postmaster.c:1463 > #23 0x000055c98b4a96be in main (argc=3D3, argv=3D0x55c98be88fc0) at main.= c:198 > > I think the uselocale() call renders ineffective the setlocale() calls=20 > that we make later. Maybe we should replace our setlocale() calls with=20 > uselocale(), too. For what it's worth to everyone else in the thread (especially Joe), I have a patch locally that fixes the mentioned bug using uselocale(). I am not sure that it is worth committing for v16 given how _large_ (the patch is actually quite small, +216 -235) of a change it is. I am going to spend tomorrow combing over it a bit more and evaluating other setlocale uses in the codebase. --=20 Tristan Partin Neon (https://neon.tech)