Re: Max connections reached without max connections reached

From: James Sewell <james(dot)sewell(at)jirotech(dot)com>
To: Amul Sul <sulamul(at)gmail(dot)com>
Cc: Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Max connections reached without max connections reached
Date: 2021-12-21 00:22:05
Message-ID: CAANVwEt_yZtL5N9vnbRaswo2u7cVzC7iHTKQE8fpgcsH3Wy7Aw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
>
> I'm guessing this won't be back-patched? Is it possible to somehow read
> this information from a C function?
>
>

Ok it is possible, I've got a C extension up and running which hooks
ExecutorStart, then once for each TX ( I monitor the nesting depth like in
pg_stat_statements, and only attach at the top level) attaches a sub
transaction callback, tracking start subtransaction events and incrementing
a counter / keeping track of the worst offenders in a hashmap.

This seems to work very well - but I've got a question. How many sub
transactions would you expect the following anon block and function to
create respectively? The first seems to report 9, and the second 10 - is
this expected? It feels like it might be - I just want to make sure.

do $$
begin
for counter in 1..10 loop
begin
INSERT INTO a VALUES (counter);
exception
when no_data_found then raise exception 'gosh';
end;
end loop;
end;
$$

CREATE OR REPLACE FUNCTION public.create_subtransactions()
RETURNS void
LANGUAGE plpgsql
AS $function$
begin
for counter in 1..10 loop
begin
INSERT INTO a VALUES (counter);
exception
when no_data_found then raise exception 'gosh';
end;
end loop;
end;
$function$

- James

--
The contents of this email are confidential and may be subject to legal or
professional privilege and copyright. No representation is made that this
email is free of viruses or other defects. If you have received this
communication in error, you may not copy or distribute any part of it or
otherwise disclose its contents to anyone. Please advise the sender of your
incorrect receipt of this correspondence.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message James Sewell 2021-12-21 00:25:54 Re: Max connections reached without max connections reached
Previous Message David G. Johnston 2021-12-20 22:37:12 Re: How best to turn select result into options like 'a|b|c''