On Wed, Jan 1, 2025 at 11:44 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Larry Rosenman <ler@lerctr.org> writes:
> > On 12/31/2024 12:22 pm, Larry Rosenman wrote:
> >> When I try to drop a database, PostgreSQL leaves files in the directory
> >> and does not even try to delete them.
> >> PostgreSQL 16.6, FreeBSD 14.2, PGDATA mounted NFS from UGreen NAS.
> What it looks like is that readdir() is skipping over some files,
> which would almost certainly be an NFS server bug. But that
> theory could be wrong.
Hmm. So in 15 and earlier, rmtree() would read all the file names
into memory and then unlink them, but 54e72b66 changed that and
started unlinking in the loop. Perhaps that wasn't a great idea, but
it's hardly the only place that directory contents might change across
readdir() calls (it's just a place that does that itself).
As has been analysed by the pgbackrest guys, readdir() can be flaky
over changing directories on some NFS (and maybe other network FSs)
implementations (unresolved AFAIK and different from this problem,
they were missing files during backups due to concurrent changes).
The implementation-specific cookie scheme for encoding a sort of
cursor position across readdir() calls has various different problems
on various different OSes, NFS implementations and underlying local
file systems (I looked into this quite a bit when that last discussion
happened, it's a mess). I wonder what a UGreen NAS is running.