Runaway functions killed all active connections

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Runaway functions killed all active connections
Дата
Msg-id 1161391240.25690.0.camel@dogma.v10.wvs
обсуждение исходный текст
Список 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


В списке pgsql-general по дате отправления:

Предыдущее
От: "Wes Sheldahl"
Дата:
Сообщение: unstable postgres on freebsd
Следующее
От: "Gregory S. Williamson"
Дата:
Сообщение: Re: Question with tsearch2 (or it might be a general one too)