Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aeBxH-0005MN-1Q for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2016 01:33:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aeBxG-0007uu-KA for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2016 01:33:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aeBvv-0006RT-DY for pgsql-hackers@postgresql.org; Fri, 11 Mar 2016 01:32:03 +0000 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aeBvs-00040e-9T for pgsql-hackers@postgresql.org; Fri, 11 Mar 2016 01:32:02 +0000 Received: by mail-lb0-x22a.google.com with SMTP id xr8so131529921lbb.1 for ; Thu, 10 Mar 2016 17:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trustly-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=ZRiS9fF0+/qIhz/rKEr29X0tq/zm35HZRAbfN4jK+u8=; b=BnbHB65WQe1XRFrlToR81gb3SCOrMquOPlkBoRI/u4foc1zNapDUDlDzSWY67Uzsf6 AoCvAtxozc7/+CbQUWEtp7IZlkqnog2qfJ3UF5YDzrPCdOoECCFXNCy8vv86buoAx9HW JxH6RxpuDcOr/Oa6xVR2Yaob2IF583BLg/AKGbE96G6N/sDg0PiA5Ukx4Ed8qbsHkuKx qLJSIfNs5cGnNCoc7tBFOWhn8StxGqRWgdVooNKkhjoa+upPliI1/oXndLuWOd80fk2e kiZQgJtgOZok2Zbkoul4G0SKkuvmbwo70MbC9GJZ5T5pUynSLe9MIUOIL+c9gO9ITsL9 rlnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=ZRiS9fF0+/qIhz/rKEr29X0tq/zm35HZRAbfN4jK+u8=; b=Fios4NI6qVUeNBbFgeGUKuk9fvNnY1rK1fIbkslcQlZMdNRwwOjMcoe/qyugV0SHSJ E/IRxDbiJKkOLFolLf05aFLSSPInUhXEqCpL6bvI1pXIgI6mL09rav7P8ER4BAhUXpD8 avX6xzBIJ1CkEG6avAJX7duaDuGtJ82RYVMcf3tByGfEDOx5trd3KoXGKgI5NUNudYZ7 p1Sak3hHH8gGMrK9hMpoP548SaC9ZK2+N8xk8xffyoTQzK6RN3JVHqEZWgVRwPo9Bx2i mIJQLH7qtIVpKMfJx3tW2sLTyj4HgOEhE3EFX50Lnmh60/4cT57bgKwugCMNcyHiNjAP GlcQ== X-Gm-Message-State: AD7BkJJ0DbIL0OHdaq8YiRgE97mJm64UZNvwNnh2Js7ND1geTw28PLh4E027Iv92BNx5wDi2HMpgSDh/m9bMlQ== MIME-Version: 1.0 X-Received: by 10.112.211.168 with SMTP id nd8mr2230848lbc.116.1457659917023; Thu, 10 Mar 2016 17:31:57 -0800 (PST) Received: by 10.25.133.131 with HTTP; Thu, 10 Mar 2016 17:31:56 -0800 (PST) In-Reply-To: <15170.1457651842@sss.pgh.pa.us> References: <15170.1457651842@sss.pgh.pa.us> Date: Fri, 11 Mar 2016 08:31:56 +0700 Message-ID: Subject: Re: [COMMITTERS] pgsql: Provide much better wait information in pg_stat_activity. From: Joel Jacobson To: Tom Lane Cc: Robert Haas , Pavel Stehule , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is an excellent feature, thanks! But can we please keep the old boolean waiting column? I see no reason to break backward-compatibility. Or maybe I'm missing something. I just had to commit this to make our system run locally on 9.6: commit 2e189f85fa56724bec5c5cab2fcf0d2f3a4ce22a Author: Joel Jacobson Date: Fri Mar 11 08:19:52 2016 +0700 Make Have_Queries_Waiting() work with both <9.6 and >=9.6. Apparently pg_stat_activity.waiting was removed by this commit: commit 53be0b1add7064ca5db3cd884302dfc3268d884e Author: Robert Haas Date: Thu Mar 10 12:44:09 2016 -0500 Provide much better wait information in pg_stat_activity. This forces us to do some ugly version checking to know which column to use. I for one can think it would have been better to keep the old boolean column, which is not entirely useless as sometimes you just want to know if something is waiting and don't care about the details, then it's convenient to have a boolean column instead of having to write "wait_event IS NOT NULL". Let's hope they will add back our dear waiting column so we can avoid this ugly hack before upgrading to 9.6. diff --git a/public/FUNCTIONS/have_queries_waiting.sql b/public/FUNCTIONS/have_queries_waiting.sql index d83e7c8..b54caf5 100644 --- a/public/FUNCTIONS/have_queries_waiting.sql +++ b/public/FUNCTIONS/have_queries_waiting.sql @@ -3,9 +3,16 @@ SET search_path TO 'public', pg_catalog; CREATE OR REPLACE FUNCTION have_queries_waiting() RETURNS boolean SECURITY DEFINER SET search_path TO public, pg_temp - LANGUAGE sql + LANGUAGE plpgsql AS $$ - SELECT EXISTS (SELECT 1 FROM pg_stat_activity WHERE waiting) +DECLARE +BEGIN +IF version() ~ '^PostgreSQL 9\.[1-5]' THEN + RETURN EXISTS (SELECT 1 FROM pg_stat_activity WHERE waiting); +ELSE + RETURN EXISTS (SELECT 1 FROM pg_stat_activity WHERE wait_event IS NOT NULL); +END IF; +END; $$; On Fri, Mar 11, 2016 at 6:17 AM, Tom Lane wrote: > Robert Haas writes: >> Or ... maybe this is intentional behavior? Now that I think about it, >> doesn't each backend cache this info the first time its transaction >> reads the data? > > Your view of pg_stat_activity is supposed to hold still within a > transaction, yes. Otherwise it'd be really painful to do any complicated > joins. I think there may be a function to explicitly flush the cache, > if you really need to see intratransaction changes. > > regards, tom lane > > > -- > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-hackers -- Joel Jacobson Mobile: +46703603801 Trustly.com | Newsroom | LinkedIn | Twitter -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers