pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <ringerc@ringerc.id.au>
To: J Chapman Flack <jflack@math.purdue.edu>
Cc: pgsql-jdbc@postgresql.org, Kevin Grittner <Kevin.Grittner@wicourts.gov>
Subject: Re: get/setReadOnly broken if default_transaction_read_only on
Date: Thu, 07 Jun 2012 18:50:15 +0800
Message-ID: <4FD08767.6000302@ringerc.id.au> (raw)
In-Reply-To: <4FCFB988.2080408@math.purdue.edu>
References: <4FCFB988.2080408@math.purdue.edu>

On 06/07/2012 04:11 AM, J Chapman Flack wrote:
>
> Hi,
>
> I've found this in the git head so it applies to current versions.
>
> AbstractJdbc2Connection initializes its readOnly member to a
> hardcoded false instead of to 'show default_transaction_read_only'
> from the backend.
>
> That means two things: 1. getReadOnly() is wrong in case the
> backend has default_transaction_read_only on, and
>
> 2. setReadOnly(false) doesn't work in that case, because the value
> is compared to readOnly and looks the same, so no set session
> characteristics command is sent to the backend.
>
>
> An application can work around (2) by always calling
> setReadOnly(true);setReadOnly(false); if it wants to write.
> But that's a bit ugly.
>
> The driver could do that too for a quick hack, but it would
> be nice to query the correct value from the backend and use that.

This may be an opportunity to improve how PgJDBC finds out important 
details about the backend in general.

Right now, lots of things require individual queries of GUCs via SHOW 
commands or other misc queries. A typical JDBC session may do several 
round trips before running its first real query, and it's only going to 
get worse.

The JDBC driver really needs a way to grab everything it needs to know 
efficiently during initial connection setup, with some extensibility so 
connection parameters can specify other things to request and cache when 
the connection is first established.

(Why extensibility? Because various layers - ORMs, query builders, etc 
etc etc - tend to ask for more GUCs, and having the JDBC driver able to 
immediately return them without more round trips would be great).

I'm dreaming of a situation where the JDBC driver sends a list of GUCs 
it wants values for, caches the results, and most importantly keeps them 
up to date by capturing the value sent in any SET commands issued via 
the driver on that session.

This has been in the back of my mind a bit lately, as I look at the spew 
of SHOW commands and similar shown when log_statement=all is enabled and 
something like Hibernate/JPA2 is talking to the database.

--
Craig Ringer



view thread (10+ messages)  latest in thread

Message-ID: <4FD08767.6000302@ringerc.id.au>
Permalink:  ../4FD08767.6000302@ringerc.id.au/
Also on:    postgresql.org/message-id/4FD08767.6000302@ringerc.id.au

 · 

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-jdbc@postgresql.org
  Cc: ringerc@ringerc.id.au, jflack@math.purdue.edu, Kevin.Grittner@wicourts.gov
  Subject: Re: get/setReadOnly broken if default_transaction_read_only on
  In-Reply-To: <4FD08767.6000302@ringerc.id.au>
  References: <4FCFB988.2080408@math.purdue.edu> <4FD08767.6000302@ringerc.id.au>

* 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