Re: [HACKERS] reverse file descriptor to a file name... - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] reverse file descriptor to a file name...
Date
Msg-id 199804102107.RAA05034@candle.pha.pa.us
Whole thread Raw
In response to reverse file descriptor to a file name...  (The Hermit Hacker <scrappy@hub.org>)
Responses Re: [HACKERS] reverse file descriptor to a file name...
Re: [HACKERS] reverse file descriptor to a file name...
List pgsql-hackers
>
>
> Hi...
>
>     I want to add the filename (index) to the error message:
>
> FATAL 1:  btree: BTP_CHAIN flag was expected (access = 0)
>
>     At least then I can figure out which index to drop and rebuild,
> instead of having to do them all :)
>
>     Now, looking at _bt_moveright(), it passes Relation, which, as
> part of its structure, has 'rd_fd', which I'm assuming is the open file
> descriptor for the index file its doing its search on...
>
>     Is there a method of taking rd_fd and figuring out the file name
> it is associated with?  I looked at fstat(), but that only appears to
> return everything but the filename :(

You can't get a file name from a descriptor, because there can be more
than one.  The system just returns information about the inode, not
about the directory entries pointing to the inode.

For your purpose, you want:

    Relation->rd_rel->relname

Works like champ.

This is not a trivial question, because the structures in PostgreSQL are
very complicated until you get used to them.

--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] subselect and optimizer
Next
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] reverse file descriptor to a file name...