Nasty resource-leak problem in sort code - Mailing list pgsql-hackers

From Tom Lane
Subject Nasty resource-leak problem in sort code
Date
Msg-id 29883.925830451@sss.pgh.pa.us
Whole thread Raw
Responses Re: Nasty resource-leak problem in sort code  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
If a CREATE INDEX fails, the backend returns to the main loop without
having closed the temporary files that are created for sorting.
An easy example that provokes this is
create table titles (adate date);insert into titles values ('today');create index titles_f_ind on titles (date(adate)
date_ops);ERROR: SQL-language function not supported in this context.
 

after which the backend has about a dozen more open files than it had
before.

If you then try to create another index, you will crash for
lack of free file descriptors (unless your kernel has a
higher-than-usual open-files-per-process limit).  In any case, the
sort temp files will never get deleted from your database directory.

Offhand I'm not sure how to fix this.  The system knows about releasing
memory after an elog(ERROR), but does it have any provisions for
releasing other kinds of resources?  I suspect we need something
analogous to the on_shmem_exit() callback-registration list, but I
don't know whether it already exists.  Comments?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] posmaster failed under high load
Next
From: Dirk Lutzebaeck
Date:
Subject: major flaw in 6.5beta1??? (UPDATE/INSERT waiting)