Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f91Zq-0005tS-CW for pgsql-admin@arkaria.postgresql.org; Thu, 19 Apr 2018 04:53:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f91Zo-0003UU-Ok for pgsql-admin@arkaria.postgresql.org; Thu, 19 Apr 2018 04:53:44 +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.89) (envelope-from ) id 1f91Zo-0003UK-Dd for pgsql-admin@lists.postgresql.org; Thu, 19 Apr 2018 04:53:44 +0000 Received: from cat-porwal-prod-mail1.catalyst.net.nz ([2404:130:4080::4]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f91Zj-0000C8-Sd for pgsql-admin@postgresql.org; Thu, 19 Apr 2018 04:53:42 +0000 Authentication-Results: auth=pass smtp.auth=mark.kirkwood@catalyst.net.nz smtp.mailfrom=mark.kirkwood@catalyst.net.nz Received: from [IPv6:2406:e001:e07:1:687e:4cb7:65ed:8007] (unknown [IPv6:2406:e001:e07:1:687e:4cb7:65ed:8007]) (Authenticated sender: mark.kirkwood@catalyst.net.nz) by cat-porwal-prod-mail1.catalyst.net.nz (Postfix) with ESMTPSA id A03AA80C63; Thu, 19 Apr 2018 16:53:31 +1200 (NZST) Subject: Re: Never kill -9 postgres client processes on Linux... but why not? To: Wells Oliver , pgsql-admin@postgresql.org References: From: Mark Kirkwood Message-ID: <57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz> Date: Thu, 19 Apr 2018 16:53:31 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 19/04/18 16:40, Wells Oliver wrote: > Had an issue tonight where I had a bunch of stalled queries from a > client connection and I just... could... not... kill... them. We > disconnected the client machine, turned it off, picked it up, shook it > around, yelled at it, and still these idle queries remained in > pg_stat_activity. > > Then I did select pg_cancel_backend(pid) from pg_stat_activity where > client_addr = '..' and they just would... not... go.. away. > > So me being the big smart system administrator guy with shell access, > I logged in, and did a kill -9 xxx where xxx was the sme pid from the > pg_stat_activity result and... they finally went away! > > Felt good about myself until I realized, well, so did every other > connection, and in fact PG momentarily went into recovery mode. > > Everything was fine, but a) why is it a bad idea to kill -9 a client > PG process, but pg_cancel_backend() is OK-- and b) what to do about > stalled PG queries that won't die when you disconnect AND when you > pg_cancel_backend() them? > Did you try pg_terminate_backend? I'm guessing that might not have worked either...but is worth it trying before belting them with kill -9! Kill -9 leaves the shared memory the backend was using intact but possibly corrupted (partial writes etc), so Postgres shuts down everything! This is pretty 'normal' in the db world (I think DB2 does the same if you kill -9 a connection from the OS). regards Mark