BUG #16974: memory leak

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: rekgrpth(at)gmail(dot)com
Subject: BUG #16974: memory leak
Date: 2021-04-20 10:34:47
Message-ID: 16974-4f1a4803e727c3cf@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16974
Logged by: RekGRpth
Email address: rekgrpth(at)gmail(dot)com
PostgreSQL version: 13.2
Operating system: docker alpine
Description:

1) create type
CREATE TYPE state AS ENUM
('PLAN',
'TAKE',
'WORK',
'DONE',
'FAIL',
'STOP');
2) create table
CREATE TABLE task (
id bigserial NOT NULL,
parent bigint DEFAULT (current_setting('pg_task.id'::text,
true))::bigint,
dt timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
start timestamp with time zone,
stop timestamp with time zone,
"group" text NOT NULL DEFAULT 'group'::text,
max integer,
pid integer,
input text NOT NULL,
output text,
error text,
state state NOT NULL DEFAULT 'PLAN'::state,
timeout interval,
delete boolean NOT NULL DEFAULT false,
repeat interval,
drift boolean NOT NULL DEFAULT true,
count integer,
live interval,
remote text,
append boolean NOT NULL DEFAULT false,
header boolean NOT NULL DEFAULT true,
string boolean NOT NULL DEFAULT true,
"null" text NOT NULL DEFAULT '\N'::text,
delimiter "char" NOT NULL DEFAULT ' '::"char",
quote "char",
escape "char",
CONSTRAINT task_pkey PRIMARY KEY (id),
CONSTRAINT task_parent_fkey FOREIGN KEY (parent)
REFERENCES task (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE SET NULL
)
3) create indexes
CREATE INDEX task_dt_idx ON task USING btree (dt);
CREATE INDEX task_parent_idx ON task USING btree (parent);
CREATE INDEX task_state_idx ON task USING btree (state);
4) create file update.sql
WITH s AS (SELECT id FROM task AS t WHERE dt < current_timestamp -
concat_ws(' ', (60::int4 * 1000::int4)::text, 'msec')::interval AND state IN
('TAKE'::state, 'WORK'::state) AND pid NOT IN (
SELECT pid FROM pg_stat_activity
WHERE datname = current_catalog AND usename = current_user AND
application_name = concat_ws(' ', 'pg_task',
current_setting('pg_task.schema', true), 'task', "group")
) FOR UPDATE SKIP LOCKED) UPDATE task AS u SET state = 'PLAN'::state FROM s
WHERE u.id = s.id
5) create file timeout.sql
WITH s AS (WITH s AS (WITH s AS (WITH s AS (WITH s AS (
SELECT t.id, t.group, COALESCE(t.max, ~(1<<31)) AS max, a.pid FROM
task AS t
LEFT JOIN task AS a ON a.state = 'WORK'::state AND t.group = a.group
WHERE t.state = 'PLAN'::state AND t.dt + concat_ws(' ', (CASE WHEN
t.max < 0 THEN -t.max ELSE 0 END)::text, 'msec')::interval <=
current_timestamp
) SELECT id, "group", CASE WHEN max > 0 THEN max ELSE 1 END - count(pid) AS
count FROM s GROUP BY id, "group", max
) SELECT array_agg(id ORDER BY id) AS id, "group", count FROM s WHERE count
> 0 GROUP BY "group", count
) SELECT unnest(id[:count]) AS id, "group", count FROM s ORDER BY count
DESC
) SELECT s.* FROM s INNER JOIN task USING (id) FOR UPDATE SKIP LOCKED
) UPDATE task AS u SET state = 'TAKE'::state FROM s WHERE u.id = s.id
RETURNING u.id, u.group, u.remote, COALESCE(u.max, ~(1<<31)) AS max
6) open psql
7) in opened psql execute above two files periodically
\i sql/update.sql
\i sql/timeout.sql
8) the memory (using by corresponded postgres backend) is increasing
constantly

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-04-20 14:32:48 Re: BUG #16974: memory leak
Previous Message Bharath Rupireddy 2021-04-20 08:08:48 Re: BUG #16972: parameter parallel_leader_participation's category problem