On Aug 16, 2009, at 8:25 PM, Tom Lane wrote:
Jan Otto <as...@me.com> writes:
ERROR:  could not read directory "pg_tblspc/16464": Invalid argument
STATEMENT:  DROP TABLESPACE testspace;

Hmm ... can't reproduce this here, not even on OSX.  From the version
number I suspect you are using unreleased Snow Leopard.  I'd venture
it's a newly-introduced kernel bug and you need to talk to Apple about
it.

                        regards, tom lane

I have digged a bit around in the source code of postgresql to build a
self contained test-case for Apple and found that the implementation
of Apples readdir() is buggy. readdir() fails under some circumstances.
So i have build a patch against current pgsql's HEAD to work around
the issue. If the bug in readdir() goes into the final release snow leopard
we have a solution.

This patch basically frees dirdesc and rereads the tablespace location
in case a subdirectory was deleted from the tablespace. this is the place
where snow leopard fails to read the next entry with readdir().

regards, jan otto

diff -c -r1.61 tablespace.c
*** pgsql/src/backend/commands/tablespace.c 22 Jan 2009 20:16:02 -0000 1.61 --- pgsql/src/backend/commands/tablespace.c 17 Aug 2009 22:36:01 -0000
***************
*** 611,616 ****
--- 611,623 ----
errmsg("could not remove directory \"%s\": %m",
                                                        subfile)));

+               /*
+ * The following two lines work around a bug in Mac OS X Snow Leopard (Build 10A432) + * readdir() implementation. We free dirdesc and reread location from start.
+                */
+               FreeDir(dirdesc);
+               dirdesc = AllocateDir(location);
+
                pfree(subfile);
        }

Reply via email to