Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSlIE-0001sm-Jy for pgsql-general@arkaria.postgresql.org; Fri, 30 Nov 2018 16:05:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gSlID-0002Vy-Bi for pgsql-general@arkaria.postgresql.org; Fri, 30 Nov 2018 16:05:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSlID-0002QM-1I for pgsql-general@lists.postgresql.org; Fri, 30 Nov 2018 16:05:25 +0000 Received: from smtp10.hushmail.com ([65.39.178.143]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSlI6-0001x8-2A for pgsql-general@lists.postgresql.org; Fri, 30 Nov 2018 16:05:24 +0000 Received: from smtp10.hushmail.com (localhost [127.0.0.1]) by smtp10.hushmail.com (Postfix) with SMTP id A9591C09B1 for ; Fri, 30 Nov 2018 16:05:13 +0000 (UTC) Received: from smtp.hushmail.com (w6.hushmail.com [65.39.178.92]) by smtp10.hushmail.com (Postfix) with ESMTP; Fri, 30 Nov 2018 16:05:12 +0000 (UTC) Subject: Re: psql is hanging To: John Smith , pgsql-general@lists.postgresql.org References: From: Chris Mair Message-ID: <285ebefdfdbaffaae8812c5ed1e695ef@smtp.hushmail.com> Date: Fri, 30 Nov 2018 17:05:09 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > We're kind of pulling out our hair here, any ideas? You might try issuing the command analyze; right *before* the command that hangs. The rationale behind this idea is that your script changed data and the "hung" command uses a wrong plan based on outdated statistics. By the time you run it manually it would be fast again, because in the mean time the statistics have been updated automatically. Analyze forces an immediate update of the statistics on the whole database. This can by itself take some time according to size of the database. If my idea works, you can then further optimize by doing analyze only on the changed tables. Bye, Chris.