Orphaned relation files after crash recovery

From: Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Orphaned relation files after crash recovery
Date: 2020-02-17 10:19:27
Message-ID: CA+fd4k7KHw0E5t9_4LFmsiFYL7SQrtwK312TQQ8q0gUDmy3jkw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

During testing recovery, I realized that it's possible that a relation
file is orphaned (probably) forever if postgres crashes during
executing a transaction that creates a new relation and loads data.

After postgres crashing, the relation is recovered during crash
recovery and the transaction is regards as aborted, but that relation
file exists in database cluster. There seems no way for postgres to
know that that relation is now garbage and can be deleted. The entry
of that relation in pg_class exists but it is never detected even by
autovacuum because autovacuum's snapshot doesn't include that. In
addition, that relfilenode number is never be reused because the file
already exists. Therefore I think that such orphaned relation file is
left forever. The orphaned relation can be large if we are loading
large data or creating a large materialized view.

Is this a bug? Has this ever been discussed?

Regards,

--
Masahiko Sawada http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2020-02-17 11:04:54 Re: Orphaned relation files after crash recovery
Previous Message Michael Paquier 2020-02-17 09:48:57 Re: Wait event that should be reported while waiting for WAL archiving to finish