Thread: [Admin] Deleting Orphan Relfilenode

[Admin] Deleting Orphan Relfilenode

From
Rahul Saha
Date:
Hi Experts,

Background - PG version 9.4
Running in Linux Rhel

We have a scenario where we ran Vacuum Full (2 TB Table)but due to some reason Vacuum Full failed.

These have let almost 1 TB orphan Relfilenodes inside base directory under the concern database which does not map with
pg_class. 

For example - Select * from pg_class where relfilenode = 123456. It does not return any row but those relfilenode exist
insidebase.  

It would be great if you can suggest how to remove those orphan files. I know definitely manually deleting is not
suggestedso thought to know your suggestions.  

Kind Regards,
Rahul Saha



Re: [Admin] Deleting Orphan Relfilenode

From
Tom Lane
Date:
Rahul Saha <rahul.blooming@gmail.com> writes:
> We have a scenario where we ran Vacuum Full (2 TB Table)but due to some reason Vacuum Full failed.
> These have let almost 1 TB orphan Relfilenodes inside base directory under the concern database which does not map
withpg_class.  

Hm, by "fail" do you mean a database crash?  Ordinary errors should have
rolled back the file creation successfully.

> For example - Select * from pg_class where relfilenode = 123456. It does not return any row but those relfilenode
existinside base.  

I would not trust that query if I were you --- it will not find mapped
system catalogs.  Maybe you are certain that this orphaned file wasn't
for a system catalog, but I'd still recommend using

select * from pg_class where pg_relation_filenode(oid) = 123456;

to be sure.  (See also contrib/oid2name.)

> It would be great if you can suggest how to remove those orphan files. I know definitely manually deleting is not
suggestedso thought to know your suggestions.  

If they're really orphaned, as proven by a pg_relation_filenode() check,
then manual "rm" is the thing to do.  Postgres doesn't know they are
there and will not remove them.

            regards, tom lane