pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: ecpglib: call newlocale() once per process.
Date: Sat, 02 Jul 2022 20:02:13 +0000
Message-ID: <E1o7jJk-000syA-56@gemulon.postgresql.org> (raw)

ecpglib: call newlocale() once per process.

ecpglib has been calling it once per SQL query and once per EXEC SQL GET
DESCRIPTOR.  Instead, if newlocale() has not succeeded before, call it
while establishing a connection.  This mitigates three problems:
- If newlocale() failed in EXEC SQL GET DESCRIPTOR, the command silently
  proceeded without the intended locale change.
- On AIX, each newlocale()+freelocale() cycle leaked memory.
- newlocale() CPU usage may have been nontrivial.

Fail the connection attempt if newlocale() fails.  Rearrange
ecpg_do_prologue() to validate the connection before its uselocale().

The sort of program that may regress is one running in an environment
where newlocale() fails.  If that program establishes connections
without running SQL statements, it will stop working in response to this
change.  I'm betting against the importance of such an ECPG use case.
Most SQL execution (any using ECPGdo()) has long required newlocale()
success, so there's little a connection could do without newlocale().

Back-patch to v10 (all supported versions).

Reviewed by Tom Lane.  Reported by Guillaume Lelarge.

Discussion: https://postgr.es/m/20220101074055.GA54621@rfd.leadboat.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/12b2a2369debca1fa0c61a7db2a50152668e64dc

Modified Files
--------------
src/interfaces/ecpg/ecpglib/connect.c    | 40 ++++++++++++++++++++++++++++++++
src/interfaces/ecpg/ecpglib/descriptor.c | 15 ++++++++----
src/interfaces/ecpg/ecpglib/execute.c    | 40 ++++++++++++++------------------
src/interfaces/ecpg/ecpglib/extern.h     |  5 +++-
4 files changed, 71 insertions(+), 29 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1o7jJk-000syA-56@gemulon.postgresql.org>
Permalink:  ../E1o7jJk-000syA-56@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1o7jJk-000syA-56@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: noah@leadboat.com
  Subject: Re: pgsql: ecpglib: call newlocale() once per process.
  In-Reply-To: <E1o7jJk-000syA-56@gemulon.postgresql.org>
  References: <E1o7jJk-000syA-56@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox