Search Postgresql Archives

Runaway functions killed all active connections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux