Re: BUG #6088: copy to stdout cannot be stopped with kill(pid) or pg_terminate_backend

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Maksym Boguk <Maxim(dot)Boguk(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6088: copy to stdout cannot be stopped with kill(pid) or pg_terminate_backend
Date: 2011-07-02 09:29:30
Message-ID: 4E0EE4FA.2020307@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2/07/2011 12:42 PM, Maksym Boguk wrote:

> But I found I can not stop
> COPY bill.changes (id, cdate, mdate, status, table_name, pk_id, old_row,
> new_row) TO stdout;
> with pg_terminate_backend(procpid) or kill (procpid).

Which FreeBSD are you on? Version and architecture.

Can you obtain a backtrace of the backend you've sent the kill signal
to, after you've set the signal? Given the rest of what you've said,
I'll bet it's blocked in the kernel waiting to send data down a socket.
If the kernel's socket writes aren't interrupted by signals, there's
nothing much Pg can do about it.

> At the same time copy to stdout completely ignore fact other side (pg_dump
> itself) was killed long time ago.

That's got to be a buffering issue, surely. Once the TCP send buffers
fill up the backend would block in write() as the OS tries to send
enough data to make room in the send buffer for the next write.

If your OS keeps big buffers, Pg might've buffered many megabytes of
data before you killed the client side. It might keep on trying to send
that data for quite a long time if it doesn't get notified that the
other peer (pg_dump in this case) has vanished.

How were you running pg_dump? ssh was involved, so I'm wondering if you
were running pg_dump over an ssh tcp tunnel. Was that it? Or were you
running pg_dump on the server side and dumping the SQL text down the ssh
connection to the client? If the latter, then unless you killed ssh as
well the OS would merrily keep on sending the already-buffered data from
before pg_dump was killed; you'd have to kill sshd or the client side of
ssh to actually stop the data flow.

To help with this sort of thing, reduce your send and receive buffer
sizes. You'll pay a price in terms of throughput, but you'll gain
responsiveness.

Without more information, it's hard to know if this is anything except a
buffering issue. Possibly one that doesn't even have anything to do with
Pg - it could easily just be sshd writes being buffered.

--
Craig Ringer

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Maxim Boguk 2011-07-02 12:00:54 Re: BUG #6088: copy to stdout cannot be stopped with kill(pid) or pg_terminate_backend
Previous Message Chris Bandy 2011-07-02 05:50:40 Re: BUG #6080: information_schema.columns.column_default contains NULL inconsistently