4 <title>oid2name
</title>
6 <indexterm zone=
"oid2name">
7 <primary>oid2name
</primary>
11 <application>oid2name<
/> is a utility program that helps administrators to
12 examine the file structure used by PostgreSQL. To make use of it, you need
13 to be familiar with the database file structure, which is described in
14 <xref linkend=
"storage">.
19 The name
<quote>oid2name<
/> is historical, and is actually rather
20 misleading, since most of the time when you use it, you will really
21 be concerned with tables' filenode numbers (which are the file names
22 visible in the database directories). Be sure you understand the
23 difference between table OIDs and table filenodes!
28 <title>Overview
</title>
31 <application>oid2name
</application> connects to a target database and
32 extracts OID, filenode, and/or table name information. You can also have
33 it show database OIDs or tablespace OIDs. The program is controlled by
34 a large number of command-line switches, as shown in
35 <xref linkend=
"oid2name-switches">.
38 <table id=
"oid2name-switches">
39 <title><application>oid2name<
/> switches
</title>
44 <entry>Description
</entry>
50 <entry><literal>-o
</literal> <replaceable>oid<
/></entry>
51 <entry>show info for table with OID
<replaceable>oid<
/></entry>
55 <entry><literal>-f
</literal> <replaceable>filenode<
/></entry>
56 <entry>show info for table with filenode
<replaceable>filenode<
/></entry>
60 <entry><literal>-t
</literal> <replaceable>tablename_pattern<
/></entry>
61 <entry>show info for table(s) matching
<replaceable>tablename_pattern<
/></entry>
65 <entry><literal>-s
</literal></entry>
66 <entry>show tablespace OIDs
</entry>
70 <entry><literal>-S
</literal></entry>
71 <entry>include system objects (those in
72 <literal>information_schema
</literal>,
<literal>pg_toast
</literal>
73 and
<literal>pg_catalog
</literal> schemas)
78 <entry><literal>-i
</literal></entry>
79 <entry>include indexes and sequences in the listing
</entry>
83 <entry><literal>-x
</literal></entry>
84 <entry>display more information about each object shown: tablespace name,
90 <entry><literal>-q
</literal></entry>
91 <entry>omit headers (useful for scripting)
</entry>
95 <entry><literal>-d
</literal> <replaceable>database<
/></entry>
96 <entry>database to connect to
</entry>
100 <entry><literal>-H
</literal> <replaceable>host<
/></entry>
101 <entry>database server's host
</entry>
105 <entry><literal>-p
</literal> <replaceable>port<
/></entry>
106 <entry>database server's port
</entry>
110 <entry><literal>-U
</literal> <replaceable>username<
/></entry>
111 <entry>username to connect as
</entry>
118 To display specific tables, select which tables to show by
119 using
<literal>-o<
/>,
<literal>-f<
/> and/or
<literal>-t<
/>.
120 <literal>-o<
/> takes an OID,
121 <literal>-f<
/> takes a filenode,
122 and
<literal>-t<
/> takes a tablename (actually, it's a LIKE
123 pattern, so you can use things like
<literal>foo%<
/>).
125 of these switches as you like, and the listing will include all objects
126 matched by any of the switches. But note that these switches can only
127 show objects in the database given by
<literal>-d<
/>.
131 If you don't give any of
<literal>-o<
/>,
<literal>-f<
/> or
<literal>-t<
/>,
132 but do give
<literal>-d<
/>, it will list all tables in the database
133 named by
<literal>-d<
/>. In this mode, the
<literal>-S<
/> and
134 <literal>-i<
/> switches control what gets listed.
138 If you don't give
<literal>-d<
/> either, it will show a listing of database
139 OIDs. Alternatively you can give
<literal>-s<
/> to get a tablespace
145 <title>Examples
</title>
148 $ # what's in this database server, anyway?
151 Oid Database Name Tablespace
152 ----------------------------------
153 17228 alvherre pg_default
154 17255 regression pg_default
155 17227 template0 pg_default
156 1 template1 pg_default
161 -------------------------
167 $ # OK, let's look into database alvherre
168 $ cd $PGDATA/base/
17228
170 $ # get top
10 db objects in the default tablespace, ordered by size
171 $ ls -lS * | head -
10
172 -rw-------
1 alvherre alvherre
136536064 sep
14 09:
51 155173
173 -rw-------
1 alvherre alvherre
17965056 sep
14 09:
51 1155291
174 -rw-------
1 alvherre alvherre
1204224 sep
14 09:
51 16717
175 -rw-------
1 alvherre alvherre
581632 sep
6 17:
51 1255
176 -rw-------
1 alvherre alvherre
237568 sep
14 09:
50 16674
177 -rw-------
1 alvherre alvherre
212992 sep
14 09:
51 1249
178 -rw-------
1 alvherre alvherre
204800 sep
14 09:
51 16684
179 -rw-------
1 alvherre alvherre
196608 sep
14 09:
50 16700
180 -rw-------
1 alvherre alvherre
163840 sep
14 09:
50 16699
181 -rw-------
1 alvherre alvherre
122880 sep
6 17:
51 16751
183 $ # I wonder what file
155173 is ...
184 $ oid2name -d alvherre -f
155173
185 From database
"alvherre":
187 ----------------------
190 $ # you can ask for more than one object
191 $ oid2name -d alvherre -f
155173 -f
1155291
192 From database
"alvherre":
194 -------------------------
196 1155291 accounts_pkey
198 $ # you can mix the options, and get more details with -x
199 $ oid2name -d alvherre -t accounts -f
1155291 -x
200 From database
"alvherre":
201 Filenode Table Name Oid Schema Tablespace
202 ------------------------------------------------------
203 155173 accounts
155173 public pg_default
204 1155291 accounts_pkey
1155291 public pg_default
206 $ # show disk space for every db object
208 > while read SIZE FILENODE
210 > echo
"$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"
212 16 1155287 branches_pkey
213 16 1155289 tellers_pkey
214 17561 1155291 accounts_pkey
217 $ # same, but sort by size
218 $ du [
0-
9]* | sort -rn | while read SIZE FN
220 > echo
"$SIZE `oid2name -q -d alvherre -f $FN`"
222 133466 155173 accounts
223 17561 1155291 accounts_pkey
224 1177 16717 pg_proc_proname_args_nsp_index
227 $ # If you want to see what's in tablespaces, use the pg_tblspc directory
228 $ cd $PGDATA/pg_tblspc
232 -------------------------
238 $ # what databases have objects in tablespace
"fastdisk"?
240 155151/
17228/
155151/PG_VERSION
242 $ # Oh, what was database
17228 again?
245 Oid Database Name Tablespace
246 ----------------------------------
247 17228 alvherre pg_default
248 17255 regression pg_default
249 17227 template0 pg_default
250 1 template1 pg_default
252 $ # Let's see what objects does this database have in the tablespace.
256 -rw-------
1 postgres postgres
0 sep
13 23:
20 155156
258 $ # OK, this is a pretty small table ... but which one is it?
259 $ oid2name -d alvherre -f
155156
260 From database
"alvherre":
262 ----------------------
268 <title>Limitations
</title>
271 <application>oid2name<
/> requires a running database server with
272 non-corrupt system catalogs. It is therefore of only limited use
273 for recovering from catastrophic database corruption situations.
278 <title>Author
</title>
281 B. Palmer
<email>bpalmer@crimelabs.net
</email>