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 1nLUxq-00071q-W9 for pgsql-general@arkaria.postgresql.org; Sat, 19 Feb 2022 19:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLUxp-0003LO-NH for pgsql-general@arkaria.postgresql.org; Sat, 19 Feb 2022 19:00:13 +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 1nLUxp-0003LF-CO for pgsql-general@lists.postgresql.org; Sat, 19 Feb 2022 19:00:13 +0000 Received: from smtprelay07.ispgateway.de ([134.119.228.97]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLUxm-0003xt-6W for pgsql-general@lists.postgresql.org; Sat, 19 Feb 2022 19:00:12 +0000 Received: from [109.90.124.214] (helo=mail.office.datagis.com) by smtprelay07.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nLUxi-0004m6-Ui for pgsql-general@lists.postgresql.org; Sat, 19 Feb 2022 20:00:07 +0100 Received: from localhost (intranator.datagis.local [127.0.0.1]) by localhost (Postfix) with ESMTP id 25D4E32F for ; Sat, 19 Feb 2022 20:00:08 +0100 (CET) X-Virus-Scanned: by Intra2net Mail Security (AVE=8.3.64.92,VDF=8.19.7.162) X-Spam-Status: X-Spam-Level: 0 Received: from [192.168.12.10] (dslb-002-205-128-037.002.205.pools.vodafone-ip.de [2.205.128.37]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: smtp-auth-user) by mail.office.datagis.com (Postfix) with ESMTPSA id E2FE924A for ; Sat, 19 Feb 2022 20:00:06 +0100 (CET) Message-ID: <99c8bac2-98e1-5315-7bca-d02d867c2b25@datagis.com> Date: Sat, 19 Feb 2022 20:00:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: Strange results when casting string to double Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <0d711ac6-6975-ae07-8963-aa91c6500776@datagis.com> <4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com> <3950189.1645198347@sss.pgh.pa.us> <6593fee3-477b-6069-f91e-79f91075808f@datagis.com> <20220218214249.su6x5hi6ixauggku@hjp.at> <8c20dba1-4631-67c1-d317-a5e144acd821@sourcepole.ch> From: Carsten Klein Organization: DataGis In-Reply-To: <8c20dba1-4631-67c1-d317-a5e144acd821@sourcepole.ch> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Df-Sender: NTkwMDE1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 19.02.2022 15:35, Tomas Pospisek wrote: > That would be visible via `lsof`. `libc. The file `...libc...so` that > `postgres` is keeping open would have the text `DEL` (as in deleted) in > the `FD` column of `lsof`'s output. > > As opposed to a newly started program which would have `REG` (regular > file) there. > *t Actually, PostgreSLQ uses the same libc than any recently started program. lsof reports REG and my /lib/x86_64-linux-gnu/libc-2.19.so has file date Mar 27, 2019, so it's much older than the point in time when PostgreSQL was started the last time (aprx. 480 days ago). After all, I guess the idea of a wrong rounding setting (set to round down, raised by Peter J. Holzer) seems most plausible to me. In particular, since the "right" and "wrong" values caused by wrong rounding shown by Tom Lane are exactly the values I am seeing. Also, there is a quite aggressive import script running for some days, which even tried to replace some of the core functions, like array_length (it added a pure PL/pgSQL version in public schema). Seems like they wanted to "Polyfill" some required functions. Maybe that script is responsible for changing the process' rounding mode? The customer started that script without thinking too much about it... :( @Tom Lane: you say, PostgreSQL does not / cannot change rounding mode at any time? There is no function to do so? So, the script (it's more like a module) must provide a Shared Object module with a C function in order to change the FPU's rounding mode? Because several people recommended using a debugger in order to see whats going on here: actually I have no expertise with debugging on Linux without an IDE. So I did not yet think of using a debugger so far. I will try a restart of the DB ASAP. However, in order to prove the rounding mode thesis: someone knows whether fesetround(FE_DOWNWARD) just sets a flag in the C runtime environment or does this call actually set the rounding mode in the FPU's control word? Is there any chance to get that current rounding mode with or even without a debugger? (Maybe some file in /proc filesystem?) I'm very unhappy with the customer starting that import script. In order to find the `smoking gun`, I will now have a closer look at the "product" that import is based on and what they have done to the database... Regards, Carsten