Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZz9A-0001hv-09 for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2018 13:13:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZz99-00013i-5a for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2018 13:13:23 +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_2) (envelope-from ) id 1eZz98-00013T-Pn for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2018 13:13:23 +0000 Received: from mail-oi0-x22f.google.com ([2607:f8b0:4003:c06::22f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eZz94-0003KK-Lm for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2018 13:13:21 +0000 Received: by mail-oi0-x22f.google.com with SMTP id u83so3883247oie.7 for ; Fri, 12 Jan 2018 05:13:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=A8w3llfL8kYJZIUPeV5RoxImF1BvZbJavVr/PERu/nc=; b=az4yWMgYMvXePC0QSiGwxGRr07l6vvA1bA8txVP4kbneKYKFJGPFtEjkg6N/khL1F8 b2hpqSi3MJuMzXBkSSPjo6+wkSNFveaTUVmVAFtiDO7+1xu75QhDojDjk23KD6pb47cb ceaNa9q2L99o/EnCDJH8k/jd+okI6CpWmwk3+s1y/oZpHsv0YOwYkDZMhp4n9fvAqeif 734P1pEYiQ8lQ1Yf8fY7sATzToAubJ2rHcLaxczukeGQ4/vPBOYEzQtLWDrYbaUF4P+s kuIcoE2Bc31N3DCjYq/vZ+a8F9YHe0t8Cl7d4Y5Yno2kcJO4Czghhsvczj85HLQ4yuZ+ Alnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=A8w3llfL8kYJZIUPeV5RoxImF1BvZbJavVr/PERu/nc=; b=oZ+hEH4fOLS7Y5cXcO77nRLRJKORrWrm/Ae+/uFw2YxHnm8UCXfNcm9p75UXoBNtbn rLltuDbxcQJ7+Z6UK+aCOECDmS5HMX5WLvWzXS35G0OoOL0f1ZBku5QKXFfeZopExGJ4 2IZbQa9iNyjeNho+0Bm72FPeXO6T56VTSr8nN6RKoEf7AJ2HNxYyZDztF3LQ2ZXR9b1V L5JtFcG7aq2aRt8mNP6eYgdezwffNVaMG+bUxq5yj4rIqnCyVOYqTsGErfqtsk/JqJG2 f9CH5+/bW4WKXghGh8n3BvwD0tv/+t8YDCEy5uqz6rJ0B3AFytIQtlgpjNh2qnjziDdf 1XVw== X-Gm-Message-State: AKGB3mJD1ItCWiQ+oiGtC7o+yNOLVWtRkbMByXGXJw40y6l1d3WOK5iL phHhDXQb6hZUCHgASfHm+6Px3pc+/sobNErNceQ= X-Google-Smtp-Source: ACJfBosrTHUYE3v/twqCeVBkSgflYtnUPVh4/H4yRLs1ya1suLz7sOpuTShlxRx9Z3r3wqBBun5RAu1h6ctyP5sakLA= X-Received: by 10.202.219.213 with SMTP id s204mr14001891oig.60.1515762797460; Fri, 12 Jan 2018 05:13:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.5.67 with HTTP; Fri, 12 Jan 2018 05:12:47 -0800 (PST) In-Reply-To: References: <20180112092655.1419.45992@wrigleys.postgresql.org> From: Laurent Martelli Date: Fri, 12 Jan 2018 14:12:47 +0100 Message-ID: Subject: Re: BUG #15008: Need a pause To: Greg Clough Cc: "pgsql-bugs@lists.postgresql.org" Content-Type: multipart/alternative; boundary="001a113d35d61b416b05629407d6" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --001a113d35d61b416b05629407d6 Content-Type: text/plain; charset="UTF-8" You are absolutely right ! Sorry for the noise here. Next time, I'll post on the user ML first. Cheers, Laurent 2018-01-12 10:39 GMT+01:00 Greg Clough : > > The following bug has been logged on the website: > > > > Bug reference: 15008 > > Logged by: Laurent Martelli > > Email address: martellilaurent@gmail.com > > PostgreSQL version: 9.6.6 > > Operating system: Debian 9.3 > > Description: > > > > I have a set of scripts I execute with psql, and for some reason, a > query in one of them take forever (never had the patience to wait for more > than 15 minutes), eating 1 CPU, unless I insert a pause (sleep 60) before > that script, and then it only takes a few seconds. > > > > It only occurs when the tables we operate on have a sufficient number of > rows. When we do "unit" tests with a subset of the data, it all goes > smoothly. > > > > Please, tell me what additional information I can provide to help fix > this. > > It sounds like you're bulk-loading rows, and not updating the table > statistics before running a query. The pause may give autovacuum time to > find and analyze the table so you get the correct query plan. I'd suggest > you modify your script to add EXPLAIN ANALYZE to your query and then run it > with and without the pause. Probably you'll find one is doing a full table > scan, and the other is using an index. > > More than likely you will need to add an "ANALYZE table_name;" into your > script in place of the pause > > Greg Clough > Senior Technology Engineer > O | +44 (0) 20 7665 9787 > M | +44 (0) 7803 142 292 > > Ipreo > Castle House | 37-35 Paul St | London EC2A 4LS > -- http://www.laurentmartelli.com // http://www.imprimart.fr --001a113d35d61b416b05629407d6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You are absolutely right !

So= rry for the noise here. Next time, I'll post on the user ML first.
<= br>
Cheers,
Laurent

<= div class=3D"gmail_quote">2018-01-12 10:39 GMT+01:00 Greg Clough <gre= g.clough@ipreo.com>:
> T= he following bug has been logged on the website:
>
> Bug reference:=C2=A0 =C2=A0 =C2=A0 15008
> Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Laurent Martelli
> Email address:=C2=A0 =C2=A0 =C2=A0 martellilaurent@gmail.com
> PostgreSQL version: 9.6.6
> Operating system:=C2=A0 =C2=A0Debian 9.3
> Description:
>
> I have a set of scripts I execute with psql, and for some reason, a qu= ery in one of them take forever (never had the patience to wait for more th= an 15 minutes), eating 1 CPU, unless I insert a pause (sleep 60) before tha= t script, and then it only takes a few seconds.
>
> It only occurs when the tables we operate on have a sufficient number = of rows. When we do "unit" tests with a subset of the data, it al= l goes smoothly.
>
> Please, tell me what additional information I can provide to help fix = this.

It sounds like you're bulk-loading rows, and not updating the table sta= tistics before running a query.=C2=A0 The pause may give autovacuum time to= find and analyze the table so you get the correct query plan.=C2=A0 I'= d suggest you modify your script to add EXPLAIN ANALYZE to your query and t= hen run it with and without the pause.=C2=A0 Probably you'll find one i= s doing a full table scan, and the other is using an index.

More than likely you will need to add an "ANALYZE table_name;" in= to your script in place of the pause

Greg Clough
Senior Technology Engineer
O=C2=A0 | +44 (0) 20 7665 9787
M | +44 (0) 7803 142 292

Ipreo
Castle House | 37-35 Paul St | London EC2A 4LS



--
http://www.laurentmartelli.com=C2=A0=C2=A0= =C2=A0 //=C2=A0=C2=A0=C2=A0 http://www.imprimart.fr
--001a113d35d61b416b05629407d6--