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 1gULBE-00050T-C3 for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 00:36:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gULBB-0006xn-0W for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 00:36:41 +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 1gULBA-0006uI-MB for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 00:36:40 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gULB3-00087h-5y for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 00:36:39 +0000 Received: by mail-oi1-x233.google.com with SMTP id c206so16070526oib.0 for ; Tue, 04 Dec 2018 16:36:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=HwrgSv78C5+WQj+CIRLR62XFPWjksj8cKirPvJSrxRo=; b=e0OTFor0p50QzNyVudU99op7jVH4wSdMrOXao/M23IrysZTrWjMBxAZEEnHkifvB2U 7xka2d4ZomBC9upc7QQKQeyaLJbgJ+ZCWJIZejjktH+CLzk2UyBkQ47IO5ziZVtEx3r0 uIxDIcTXrx9IBTdEB+/M+jET9GQqYUvTtCzEH+j+8yp9IZDdWmyt3mFkIduRBmEYVTAn 7R4EqkDE7b1s+SnMAPLzIvzZesKU7Ss0U/K2zBc5Mgel+NMKtpg+sZyAypZedsvOHSlW 4JneAuifO4U0VwXyRkgczqYI6vOeUchZPZAozCJMken2nYD+0B0BK43fWPTx5lQZxguF ZOfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=HwrgSv78C5+WQj+CIRLR62XFPWjksj8cKirPvJSrxRo=; b=RYdMxdvtmk8gHeHUVDCd6gCdu1r5cq7TgSka1V4HITBI/ZBmxkdCip4rx/UAFTtxfe DldHQ5JUNEiDXHJ8TgvWtTtnazwDGAkoNH70loUk6TJaQYOnqSlQdxuzfZ24R3rofkH7 kzj18P+p550lt7RwKOtVCGj5CbVfZWIW0S1dZbCxyduTKQWkCqEw2hOlpgeIdTY0YQd1 g2fg1AonoUJGfuhu3ybA++YLBrgu0z6xYPEmXZNQa+4Kk0sHjpBSalic5BRblLkUuwKE BU5IUn/4YoG2YuPJ/cGampLmRGx3P/GJ9BtP1ePg6RHW07DVbtuUJrcYEMsezznHkRM1 /bog== X-Gm-Message-State: AA+aEWYb5LXjByt2MHxYjNkg1w16Egv4LRn6TQrkn387zA14iobwdf2J EN0WZjNSQVa1EyQNlgxn9xsIgMNn X-Google-Smtp-Source: AFSGD/XB/Sy/rpx8E1GHsTWvJJAzk3Z7gO03dt7udkQYuL2pIFCExQYbPyYQmRyGjmLSByK2sU24dQ== X-Received: by 2002:aca:4ed8:: with SMTP id c207mr14250968oib.276.1543970190510; Tue, 04 Dec 2018 16:36:30 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id t2sm8597691otl.4.2018.12.04.16.36.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 16:36:29 -0800 (PST) Subject: Re: psql is hanging To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <14c6e880-0a16-9bd0-42d1-da45d59a22ed@gmail.com> Date: Tue, 4 Dec 2018 18:36:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/30/2018 09:53 AM, John Smith wrote: > We have a long script of sql that we run, several thousand lines of sql. > If I execute the script from start to finish, somewhere in the middle of > it, one sql command will hang and take 2 to 3 hours. During this time, > "htop" shows 100% cpu usage with a postgresql process, so it appears to be > doing something. > > If I stop that command, then immediately rerun the rest of the script > starting from the command that "hung", the "hung" command then completes > in 5 seconds and the rest of the script just continues on perfectly. I can > interrupt the command within 30 mins of hanging, or 2 hours of hanging; > regardless of when I interrrupt the hung command, it always immediately > completes successully in < 5 seconds when I rerun the script immediately > after that. > > I have noticed this in multiple scripts, multiple commands; one was an > "insert into", a different script hung on a "update" and a third one would > hang on a "create table x as (select ... )". These are all short running > commands normally, and we have indexes on all the columns for the > appropriate "where" clauses. > > I can't send the sql (forbidden), but the actual command does not appear > to be the issue. Rerunning the same little section of sql manually which > includes the hung command, always takes less than a minute, but the entire > sql which should only take 30 minutes in total will always hang at the > same spot; and then interrupting it (regardless of how long it was > running) and rerunning immediately completes. > > The "hung" command does eventually finish at times after 2 to 3 hours, > most often we can't afford to wait for it to run since this batch of sql > has to run daily. > > Some other notes: > - Environment is Ubuntu 16.04; postgresql version was originaly 9.5(?) but > we have upgraded to 11.1 using postgresql packages for ubuntu and the > problem has persisted across postgresql versions. > - There are no other queries running on the postgresql server during this > time, and server load is idling (other than whatever psql is doing). > - It is an amazon server, with ZFS as the files system, it has 50% disk > free on this storage partition that postgresql database is on. > - We have 60 gigs of ram total, 8 cores. > - We have run the entire script using "create unlogged table" everywhere > as well, no difference. > - We have made tunings to the postgresql configuration to make it use more > RAM. > - All sql commands are sent through a custom Java application; so we use > java + JDBC to connect to postgresql for this. The script has custom > commands which are interpreted by the Java app, so we can't test running > the exact script start to finish in psql native tools since the native > tools won't understand our custom sql. However the java app is very > simple. All individual sql commands are committed immediately after they > run so there is no long transaction in play here. The psql jdbc driver is > "postgresql-42.2.4". > - One may suspect the custom java app; but again, htop shows postgresql > using 100% CPU usage on one core, so postgresql is chewing on the command, > doing something. > > I have attached our current postgresql.conf file. > > We're kind of pulling out our hair here, any ideas? The (apparent) solution for us was to upgrade the JDBC driver from 42.2.1 to 42.2.5.  Note, though, that our giant script only does DDL statements. -- Angular momentum makes the world go 'round.