4 oid2name — resolve OIDs and file nodes in a PostgreSQL data directory
12 oid2name is a utility program that helps administrators to examine the
13 file structure used by PostgreSQL. To make use of it, you need to be
14 familiar with the database file structure, which is described in
19 The name “oid2name” is historical, and is actually rather misleading,
20 since most of the time when you use it, you will really be concerned
21 with tables' filenode numbers (which are the file names visible in the
22 database directories). Be sure you understand the difference between
23 table OIDs and table filenodes!
25 oid2name connects to a target database and extracts OID, filenode,
26 and/or table name information. You can also have it show database OIDs
31 oid2name accepts the following command-line arguments:
35 show info for table with filenode filenode.
39 include indexes and sequences in the listing.
43 show info for table with OID oid.
47 omit headers (useful for scripting).
55 include system objects (those in information_schema, pg_toast
56 and pg_catalog schemas).
59 --table=tablename_pattern
60 show info for table(s) matching tablename_pattern.
64 Print the oid2name version and exit.
68 display more information about each object shown: tablespace
69 name, schema name, and OID.
73 Show help about oid2name command line arguments, and exit.
75 oid2name also accepts the following command-line arguments for
76 connection parameters:
80 database to connect to.
84 database server's host.
87 database server's host. Use of this parameter is deprecated as
92 database server's port.
96 user name to connect as.
98 To display specific tables, select which tables to show by using -o, -f
99 and/or -t. -o takes an OID, -f takes a filenode, and -t takes a table
100 name (actually, it's a LIKE pattern, so you can use things like foo%).
101 You can use as many of these options as you like, and the listing will
102 include all objects matched by any of the options. But note that these
103 options can only show objects in the database given by -d.
105 If you don't give any of -o, -f or -t, but do give -d, it will list all
106 tables in the database named by -d. In this mode, the -S and -i options
107 control what gets listed.
109 If you don't give -d either, it will show a listing of database OIDs.
110 Alternatively you can give -s to get a tablespace listing.
117 Default connection parameters.
119 This utility, like most other PostgreSQL utilities, also uses the
120 environment variables supported by libpq (see Section 32.15).
122 The environment variable PG_COLOR specifies whether to use color in
123 diagnostic messages. Possible values are always, auto and never.
127 oid2name requires a running database server with non-corrupt system
128 catalogs. It is therefore of only limited use for recovering from
129 catastrophic database corruption situations.
133 $ # what's in this database server, anyway?
136 Oid Database Name Tablespace
137 ----------------------------------
138 17228 alvherre pg_default
139 17255 regression pg_default
140 17227 template0 pg_default
141 1 template1 pg_default
146 -------------------------
152 $ # OK, let's look into database alvherre
153 $ cd $PGDATA/base/17228
155 $ # get top 10 db objects in the default tablespace, ordered by size
156 $ ls -lS * | head -10
157 -rw------- 1 alvherre alvherre 136536064 sep 14 09:51 155173
158 -rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291
159 -rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717
160 -rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255
161 -rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674
162 -rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249
163 -rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684
164 -rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700
165 -rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699
166 -rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751
168 $ # What file is 155173?
169 $ oid2name -d alvherre -f 155173
170 From database "alvherre":
172 ----------------------
175 $ # you can ask for more than one object
176 $ oid2name -d alvherre -f 155173 -f 1155291
177 From database "alvherre":
179 -------------------------
181 1155291 accounts_pkey
183 $ # you can mix the options, and get more details with -x
184 $ oid2name -d alvherre -t accounts -f 1155291 -x
185 From database "alvherre":
186 Filenode Table Name Oid Schema Tablespace
187 ------------------------------------------------------
188 155173 accounts 155173 public pg_default
189 1155291 accounts_pkey 1155291 public pg_default
191 $ # show disk space for every db object
193 > while read SIZE FILENODE
195 > echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"
197 16 1155287 branches_pkey
198 16 1155289 tellers_pkey
199 17561 1155291 accounts_pkey
202 $ # same, but sort by size
203 $ du [0-9]* | sort -rn | while read SIZE FN
205 > echo "$SIZE `oid2name -q -d alvherre -f $FN`"
207 133466 155173 accounts
208 17561 1155291 accounts_pkey
209 1177 16717 pg_proc_proname_args_nsp_index
212 $ # If you want to see what's in tablespaces, use the pg_tblspc directory
213 $ cd $PGDATA/pg_tblspc
217 -------------------------
223 $ # what databases have objects in tablespace "fastdisk"?
225 155151/17228/ 155151/PG_VERSION
227 $ # Oh, what was database 17228 again?
230 Oid Database Name Tablespace
231 ----------------------------------
232 17228 alvherre pg_default
233 17255 regression pg_default
234 17227 template0 pg_default
235 1 template1 pg_default
237 $ # Let's see what objects does this database have in the tablespace.
241 -rw------- 1 postgres postgres 0 sep 13 23:20 155156
243 $ # OK, this is a pretty small table ... but which one is it?
244 $ oid2name -d alvherre -f 155156
245 From database "alvherre":
247 ----------------------
252 B. Palmer <bpalmer@crimelabs.net>