pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13671: pg_terminate_backend(pid) does not work
4+ messages / 3 participants
[nested] [flat]

* BUG #13671: pg_terminate_backend(pid) does not work
@ 2015-10-09 07:43  oktogen@mail.ru
  0 siblings, 1 reply; 4+ messages in thread

From: oktogen@mail.ru @ 2015-10-09 07:43 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13671
Logged by:          alex
Email address:      oktogen@mail.ru
PostgreSQL version: 9.4.5
Operating system:   ubuntu
Description:        

The command pg_terminate_backend(pid) does not terminate sql session
in case incorrect formed COPY command(without terminate-symbol)
Example
--SESSION #1
CREATE TABLE public.comments (
  user_id INTEGER NOT NULL,
  description TEXT NOT NULL,
  path public.ltree NOT NULL,
  CONSTRAINT comments_idx PRIMARY KEY(user_id, description, path)
)WITHOUT OIDS;

COPY comments (user_id, description, path) FROM stdin;
1	efbb974bcf5af8f2ba8f352225ecff63	0001
2	8dcdb42684773f413b40d63f5ef0722e	0001.0001.0001
--

--SESSION #2
-- Now SESSION # 1 can not be forced to complete the outside.
-- learn pid process which need  terminate
SELECT a.pid,
    a.usename,
    a.application_name,
    a.client_addr,
    clock_timestamp() - a.query_start AS duration,
    a.state,
    a.query,
    a.waiting
FROM pg_stat_activity a;

--attempt to finish the session with incorrect COPY command
SELECT pg_terminate_backend(6476) AS output;
--   output
-------------
-- TRUE
 
SELECT 
	a.pid,
  a.state,
  a.query
FROM pg_stat_activity a
WHERE a.pid = 6476;
-- output(failed attempt) 
+-----+--------+---------------------------------------------------------+
| pid | state  |                  query                                  |
+-----+--------+---------------------------------------------------------+
|6476 | active |  COPY comments (user_id, description, path) FROM stdin; |
+-----+--------+---------------------------------------------------------+



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13671: pg_terminate_backend(pid) does not work
@ 2015-10-09 08:56  Haribabu Kommi <kommi.haribabu@gmail.com>
  parent: oktogen@mail.ru
  0 siblings, 1 reply; 4+ messages in thread

From: Haribabu Kommi @ 2015-10-09 08:56 UTC (permalink / raw)
  To: oktogen@mail.ru; +Cc: pgsql-bugs

On Fri, Oct 9, 2015 at 6:43 PM,  <oktogen@mail.ru> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      13671
> Logged by:          alex
> Email address:      oktogen@mail.ru
> PostgreSQL version: 9.4.5
> Operating system:   ubuntu
> Description:
>
> The command pg_terminate_backend(pid) does not terminate sql session
> in case incorrect formed COPY command(without terminate-symbol)
> Example
> --SESSION #1
> CREATE TABLE public.comments (
>   user_id INTEGER NOT NULL,
>   description TEXT NOT NULL,
>   path public.ltree NOT NULL,
>   CONSTRAINT comments_idx PRIMARY KEY(user_id, description, path)
> )WITHOUT OIDS;
>
> COPY comments (user_id, description, path) FROM stdin;
> 1       efbb974bcf5af8f2ba8f352225ecff63        0001
> 2       8dcdb42684773f413b40d63f5ef0722e        0001.0001.0001
> --
>
> --SESSION #2
> -- Now SESSION # 1 can not be forced to complete the outside.
> -- learn pid process which need  terminate
> SELECT a.pid,
>     a.usename,
>     a.application_name,
>     a.client_addr,
>     clock_timestamp() - a.query_start AS duration,
>     a.state,
>     a.query,
>     a.waiting
> FROM pg_stat_activity a;
>
> --attempt to finish the session with incorrect COPY command
> SELECT pg_terminate_backend(6476) AS output;
> --   output
> -------------
> -- TRUE
>
> SELECT
>         a.pid,
>   a.state,
>   a.query
> FROM pg_stat_activity a
> WHERE a.pid = 6476;
> -- output(failed attempt)
> +-----+--------+---------------------------------------------------------+
> | pid | state  |                  query                                  |
> +-----+--------+---------------------------------------------------------+
> |6476 | active |  COPY comments (user_id, description, path) FROM stdin; |
> +-----+--------+---------------------------------------------------------+
>

Thanks for the bug report. This issue happens only for version 9.4 and below.
In 9.5 and Head branches, because of the following commit, that introduces the
wait logic in reading/writing from client, thus it detects the interrupts and
terminates the backend. But in version 9.4 and below, the wait logic
doesn't exist
because of this reason, the backend is not terminated.

commit - 80788a431e9bff06314a054109fdea66ac538199
Simplify waiting logic in reading from / writing to client.

Similar fix is needed in the back branches. Comments?

Regards,
Hari Babu
Fujitsu Australia


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13671: pg_terminate_backend(pid) does not work
@ 2015-10-09 13:36  Andres Freund <andres@anarazel.de>
  parent: Haribabu Kommi <kommi.haribabu@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Andres Freund @ 2015-10-09 13:36 UTC (permalink / raw)
  To: Haribabu Kommi <kommi.haribabu@gmail.com>; +Cc: pgsql-bugs

On 2015-10-09 19:56:16 +1100, Haribabu Kommi wrote:
> Thanks for the bug report. This issue happens only for version 9.4 and below.
> In 9.5 and Head branches, because of the following commit, that introduces the
> wait logic in reading/writing from client, thus it detects the interrupts and
> terminates the backend. But in version 9.4 and below, the wait logic
> doesn't exist

> because of this reason, the backend is not terminated.
> 
> commit - 80788a431e9bff06314a054109fdea66ac538199
> Simplify waiting logic in reading from / writing to client.

Are you sure that it is this commit? That's just unifying existing
logic between ssl/nossl, no?

> Similar fix is needed in the back branches. Comments?

I don't think we easily can - the whole interrupt/signal handling
overhaul was quite invasive.

Greetings,

Andres Freund


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13671: pg_terminate_backend(pid) does not work
@ 2015-10-11 23:58  Haribabu Kommi <kommi.haribabu@gmail.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Haribabu Kommi @ 2015-10-11 23:58 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-bugs

On Sat, Oct 10, 2015 at 12:36 AM, Andres Freund <andres@anarazel.de> wrote:
> On 2015-10-09 19:56:16 +1100, Haribabu Kommi wrote:
>> Thanks for the bug report. This issue happens only for version 9.4 and below.
>> In 9.5 and Head branches, because of the following commit, that introduces the
>> wait logic in reading/writing from client, thus it detects the interrupts and
>> terminates the backend. But in version 9.4 and below, the wait logic
>> doesn't exist
>
>> because of this reason, the backend is not terminated.
>>
>> commit - 80788a431e9bff06314a054109fdea66ac538199
>> Simplify waiting logic in reading from / writing to client.
>
> Are you sure that it is this commit? That's just unifying existing
> logic between ssl/nossl, no?

Yes, The above commit is just unifying the logic between ssl/nossl.
In a quick look, I though that the above commit has introduced the wait logic.
But actually the following commits has introduced the wait logic.

commit- 387da18874afa17156ee3af63766f17efb53c4b9
Use a nonblocking socket for FE/BE communication and block using latches.

commit - 4f85fde8eb860f263384fffdca660e16e77c7f76
Introduce and use infrastructure for interrupt processing during client reads.

>> Similar fix is needed in the back branches. Comments?
>
> I don't think we easily can - the whole interrupt/signal handling
> overhaul was quite invasive.

Thanks for the details. I understand the difficulty.
Is it worth of adding a note in the documentation section of administration
functions such as cancel and terminate backend functions like the attached?

Regards,
Hari Babu
Fujitsu Australia

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

cancel_or_terminate_backend_doc.patch (application/octet-stream, 905B) download *** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** *** 16178,16184 **** SELECT set_config('log_statement_stats', 'off', false); <structfield>usename</structfield> column of the <structname>pg_stat_activity</structname> view. </para> ! <para> <function>pg_reload_conf</> sends a <systemitem>SIGHUP</> signal to the server, causing configuration files --- 16178,16190 ---- <structfield>usename</structfield> column of the <structname>pg_stat_activity</structname> view. </para> ! ! <para> ! Note that the backend processes that are waiting on client input, ! for example COPY ... FROM STDIN and etc will get canceled or ! terminated once their waiting finishes. ! </para> ! <para> <function>pg_reload_conf</> sends a <systemitem>SIGHUP</> signal to the server, causing configuration files
^ permalink raw reply [nested|flat] 4+ messages in thread


end of thread, other threads:[~2015-10-11 23:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-10-09 07:43 BUG #13671: pg_terminate_backend(pid) does not work oktogen@mail.ru
2015-10-09 08:56 ` Haribabu Kommi <kommi.haribabu@gmail.com>
2015-10-09 13:36   ` Andres Freund <andres@anarazel.de>
2015-10-11 23:58     ` Haribabu Kommi <kommi.haribabu@gmail.com>

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