Runaway functions killed all active connections

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Runaway functions killed all active connections
Date: 2006-10-21 00:40:40
Message-ID: 1161391240.25690.0.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I got the following error (v8.1.4):

PANIC: ERRORDATA_STACK_SIZE exceeded

There was a discussion about this same error on the list 3 days ago.
However, it looks like I'm having a different problem.

I have an ON INSERT rule that executes 3 functions similar to the
following function:

CREATE OR REPLACE FUNCTION get_text_id(TEXT) RETURNS INT
VOLATILE LANGUAGE plpgsql AS
$get_text_id$
DECLARE
text_id INT;
BEGIN
LOOP
SELECT INTO text_id id FROM textid WHERE name=$1;
IF FOUND THEN
RETURN text_id;
END IF;
BEGIN
INSERT INTO textid(name) VALUES($1);
RETURN CURRVAL('textid_id_seq');
EXCEPTION WHEN unique_violation THEN
END;
END LOOP;
END;
$get_text_id$;

And I received the error when I inserted about 2M records. I assume it's
this function. Would this be expected to cause that problem? Is there an
easier way to do what I need? How can I try to be safe from this problem
in the future (at least so it doesn't kill other active connections)?

I have another simpler function which I don't think would be the
problem:

CREATE OR REPLACE FUNCTION value(TEXT) RETURNS INT
STABLE LANGUAGE plpgsql AS
$$
DECLARE
value INT;
BEGIN
SELECT INTO value my_value FROM my_table
WHERE name = $1;
IF FOUND THEN
RETURN value;
ELSE
RAISE EXCEPTION 'Invalid name';
END IF;
END;
$$;

Also, I am inserting the records from a temporary table that was created
in the same transaction, if that makes any difference.

Regards,
Jeff Davis

Browse pgsql-general by date

  From Date Subject
Next Message Gregory S. Williamson 2006-10-21 01:02:16 Re: Question with tsearch2 (or it might be a general one too)
Previous Message Stephan Szabo 2006-10-20 23:38:03 Re: c (lowercase) privilege