Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 77660779692 for ; Thu, 7 Jun 2012 07:50:41 -0300 (ADT) Received: from mail-pz0-f46.google.com ([209.85.210.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ScaIW-0001QF-Kk for pgsql-jdbc@postgresql.org; Thu, 07 Jun 2012 10:50:40 +0000 Received: by dady13 with SMTP id y13so704803dad.19 for ; Thu, 07 Jun 2012 03:50:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=ng78za6v1M8fdSCggvsMxhC6CIdt49rstVEMwkOXCG0=; b=d4MsDmfmxzjXPUFkSRDGecm7UUj/v6akBvE8pk65+H2PLP/IFDLV1lMKVnc7SUjQF7 bOHXwn2cM3mDX9aSk2rKqrgDv6/gdKKJDm58U74MUx0K/KB7cU/17+fTPrKAfxDQ1JeM yARjuOyNLNghJFzVSLCwtsPlOR31emirFPOWi/QVyQSCMVnc/RRYM7kJEAJaSkGZbRvy OR1Ix95k5S4Tz4rk9OG/xjTTr6QfkrQVdkUgVgq8P8foa1tQXOz5q4Sx64VEuQl1vqdQ /k516uI3F5drib+zRoBsh48hDArZc1o8EwR4ekSmEuMYuhJ55p784raYvSB6U7d8bDoV uzdg== Received: by 10.68.241.228 with SMTP id wl4mr8463873pbc.51.1339066221726; Thu, 07 Jun 2012 03:50:21 -0700 (PDT) Received: from wallace.localnet (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id ok6sm3725992pbb.29.2012.06.07.03.50.18 (version=SSLv3 cipher=OTHER); Thu, 07 Jun 2012 03:50:20 -0700 (PDT) Message-ID: <4FD08767.6000302@ringerc.id.au> Date: Thu, 07 Jun 2012 18:50:15 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: J Chapman Flack CC: pgsql-jdbc@postgresql.org, Kevin Grittner Subject: Re: get/setReadOnly broken if default_transaction_read_only on References: <4FCFB988.2080408@math.purdue.edu> In-Reply-To: <4FCFB988.2080408@math.purdue.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlOWIKfmIw0CErBdACE23Qr1B870daDbBYoIuCrYk4NAjXIFz+pOuwQ02v+FOQPURp6fpuq X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/23 X-Sequence-Number: 23017 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