From: "David M. Richter" <D.Richter@DKFZ-heidelberg.de>
> I have wrote a function. If I call this function the following output
> appears:
>
> psql:restructure.sql:139: ERROR: cannot extend image: No space left on
> device.
> Check free disk space.
[snip]
> BEGIN
> FOR psr_rec IN SELECT * FROM relseries_image000 LOOP
> UPDATE image
> SET seriesoid = psr_rec.parentoid
> WHERE chilioid = psr_rec.childoid;
> i := i + 1;
> END LOOP;
> IF NOT FOUND THEN RETURN -1;
> ELSE RETURN i;
> END IF;
> END;
>
> ' LANGUAGE 'plpgsql';
>
>
>
> I saw during the execute of the function that the Ram was fully used and
> also the swap space was also fully used.
> the table relseries_image000 has ca. 3 Millions of rows. Every row has 3
> columns.
You're probably taking up all the space because PG is trying to keep track
of 3 million separate operations inside the transaction. You can replace the
function with a single query using something like:
UPDATE image SET seriesoid = r.parentoid
FROM image i JOIN relseries r ON i.childoid=r.childoid;
This isn't standard SQL mind you.
- Richard Huxton