pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
To: Wells Oliver <wells.oliver@gmail.com>
To: pgsql-admin@postgresql.org
Subject: Re: Never kill -9 postgres client processes on Linux... but why not?
Date: Thu, 19 Apr 2018 16:53:31 +1200
Message-ID: <57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz> (raw)
In-Reply-To: <CAOC+FBVsc3ehFduq_z=5H6k2G-KyNCKnBzkzY0Q53nVpEasnhw@mail.gmail.com>
References: <CAOC+FBVsc3ehFduq_z=5H6k2G-KyNCKnBzkzY0Q53nVpEasnhw@mail.gmail.com>

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




view thread (5+ messages)  latest in thread

Message-ID: <57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz>
Permalink:  ../57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz/
Also on:    postgresql.org/message-id/57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mark.kirkwood@catalyst.net.nz, wells.oliver@gmail.com
  Subject: Re: Never kill -9 postgres client processes on Linux... but why not?
  In-Reply-To: <57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz>
  References: <CAOC+FBVsc3ehFduq_z=5H6k2G-KyNCKnBzkzY0Q53nVpEasnhw@mail.gmail.com> <57d6f3fa-3d9f-9dda-f2a2-131966b5f407@catalyst.net.nz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox