1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
'\" t
.\" Title: oid2name
.\" Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 2023
.\" Manual: PostgreSQL 15.4 Documentation
.\" Source: PostgreSQL 15.4
.\" Language: English
.\"
.TH "OID2NAME" "1" "2023" "PostgreSQL 15.4" "PostgreSQL 15.4 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
oid2name \- resolve OIDs and file nodes in a PostgreSQL data directory
.SH "SYNOPSIS"
.HP \w'\fBoid2name\fR\ 'u
\fBoid2name\fR [\fIoption\fR...]
.SH "DESCRIPTION"
.PP
oid2name
is a utility program that helps administrators to examine the file structure used by PostgreSQL\&. To make use of it, you need to be familiar with the database file structure, which is described in
Chapter\ \&73\&.
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBNote\fR
.ps -1
.br
.PP
The name
\(lqoid2name\(rq
is historical, and is actually rather misleading, since most of the time when you use it, you will really be concerned with tables\*(Aq filenode numbers (which are the file names visible in the database directories)\&. Be sure you understand the difference between table OIDs and table filenodes!
.sp .5v
.RE
.PP
oid2name
connects to a target database and extracts OID, filenode, and/or table name information\&. You can also have it show database OIDs or tablespace OIDs\&.
.SH "OPTIONS"
.PP
oid2name
accepts the following command\-line arguments:
.PP
\fB\-f \fR\fB\fIfilenode\fR\fR
.br
\fB\-\-filenode=\fR\fB\fIfilenode\fR\fR
.RS 4
show info for table with filenode
\fIfilenode\fR\&.
.RE
.PP
\fB\-i\fR
.br
\fB\-\-indexes\fR
.RS 4
include indexes and sequences in the listing\&.
.RE
.PP
\fB\-o \fR\fB\fIoid\fR\fR
.br
\fB\-\-oid=\fR\fB\fIoid\fR\fR
.RS 4
show info for table with OID
\fIoid\fR\&.
.RE
.PP
\fB\-q\fR
.br
\fB\-\-quiet\fR
.RS 4
omit headers (useful for scripting)\&.
.RE
.PP
\fB\-s\fR
.br
\fB\-\-tablespaces\fR
.RS 4
show tablespace OIDs\&.
.RE
.PP
\fB\-S\fR
.br
\fB\-\-system\-objects\fR
.RS 4
include system objects (those in
\fBinformation_schema\fR,
\fBpg_toast\fR
and
\fBpg_catalog\fR
schemas)\&.
.RE
.PP
\fB\-t \fR\fB\fItablename_pattern\fR\fR
.br
\fB\-\-table=\fR\fB\fItablename_pattern\fR\fR
.RS 4
show info for table(s) matching
\fItablename_pattern\fR\&.
.RE
.PP
\fB\-V\fR
.br
\fB\-\-version\fR
.RS 4
Print the
oid2name
version and exit\&.
.RE
.PP
\fB\-x\fR
.br
\fB\-\-extended\fR
.RS 4
display more information about each object shown: tablespace name, schema name, and OID\&.
.RE
.PP
\fB\-?\fR
.br
\fB\-\-help\fR
.RS 4
Show help about
oid2name
command line arguments, and exit\&.
.RE
.PP
oid2name
also accepts the following command\-line arguments for connection parameters:
.PP
\fB\-d \fR\fB\fIdatabase\fR\fR
.br
\fB\-\-dbname=\fR\fB\fIdatabase\fR\fR
.RS 4
database to connect to\&.
.RE
.PP
\fB\-h \fR\fB\fIhost\fR\fR
.br
\fB\-\-host=\fR\fB\fIhost\fR\fR
.RS 4
database server\*(Aqs host\&.
.RE
.PP
\fB\-H \fR\fB\fIhost\fR\fR
.RS 4
database server\*(Aqs host\&. Use of this parameter is
\fIdeprecated\fR
as of
PostgreSQL
12\&.
.RE
.PP
\fB\-p \fR\fB\fIport\fR\fR
.br
\fB\-\-port=\fR\fB\fIport\fR\fR
.RS 4
database server\*(Aqs port\&.
.RE
.PP
\fB\-U \fR\fB\fIusername\fR\fR
.br
\fB\-\-username=\fR\fB\fIusername\fR\fR
.RS 4
user name to connect as\&.
.RE
.PP
To display specific tables, select which tables to show by using
\fB\-o\fR,
\fB\-f\fR
and/or
\fB\-t\fR\&.
\fB\-o\fR
takes an OID,
\fB\-f\fR
takes a filenode, and
\fB\-t\fR
takes a table name (actually, it\*(Aqs a
LIKE
pattern, so you can use things like
foo%)\&. You can use as many of these options as you like, and the listing will include all objects matched by any of the options\&. But note that these options can only show objects in the database given by
\fB\-d\fR\&.
.PP
If you don\*(Aqt give any of
\fB\-o\fR,
\fB\-f\fR
or
\fB\-t\fR, but do give
\fB\-d\fR, it will list all tables in the database named by
\fB\-d\fR\&. In this mode, the
\fB\-S\fR
and
\fB\-i\fR
options control what gets listed\&.
.PP
If you don\*(Aqt give
\fB\-d\fR
either, it will show a listing of database OIDs\&. Alternatively you can give
\fB\-s\fR
to get a tablespace listing\&.
.SH "ENVIRONMENT"
.PP
\fBPGHOST\fR
.br
\fBPGPORT\fR
.br
\fBPGUSER\fR
.RS 4
Default connection parameters\&.
.RE
.PP
This utility, like most other
PostgreSQL
utilities, also uses the environment variables supported by
libpq
(see
Section\ \&34.15)\&.
.PP
The environment variable
\fBPG_COLOR\fR
specifies whether to use color in diagnostic messages\&. Possible values are
always,
auto
and
never\&.
.SH "NOTES"
.PP
oid2name
requires a running database server with non\-corrupt system catalogs\&. It is therefore of only limited use for recovering from catastrophic database corruption situations\&.
.SH "EXAMPLES"
.sp
.if n \{\
.RS 4
.\}
.nf
$ # what\*(Aqs in this database server, anyway?
$ oid2name
All databases:
Oid Database Name Tablespace
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
17228 alvherre pg_default
17255 regression pg_default
17227 template0 pg_default
1 template1 pg_default
$ oid2name \-s
All tablespaces:
Oid Tablespace Name
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
1663 pg_default
1664 pg_global
155151 fastdisk
155152 bigdisk
$ # OK, let\*(Aqs look into database alvherre
$ cd $PGDATA/base/17228
$ # get top 10 db objects in the default tablespace, ordered by size
$ ls \-lS * | head \-10
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 136536064 sep 14 09:51 155173
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 17965056 sep 14 09:51 1155291
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 1204224 sep 14 09:51 16717
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 581632 sep 6 17:51 1255
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 237568 sep 14 09:50 16674
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 212992 sep 14 09:51 1249
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 204800 sep 14 09:51 16684
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 196608 sep 14 09:50 16700
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 163840 sep 14 09:50 16699
\-rw\-\-\-\-\-\-\- 1 alvherre alvherre 122880 sep 6 17:51 16751
$ # I wonder what file 155173 is \&.\&.\&.
$ oid2name \-d alvherre \-f 155173
From database "alvherre":
Filenode Table Name
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
155173 accounts
$ # you can ask for more than one object
$ oid2name \-d alvherre \-f 155173 \-f 1155291
From database "alvherre":
Filenode Table Name
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
155173 accounts
1155291 accounts_pkey
$ # you can mix the options, and get more details with \-x
$ oid2name \-d alvherre \-t accounts \-f 1155291 \-x
From database "alvherre":
Filenode Table Name Oid Schema Tablespace
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
155173 accounts 155173 public pg_default
1155291 accounts_pkey 1155291 public pg_default
$ # show disk space for every db object
$ du [0\-9]* |
> while read SIZE FILENODE
> do
> echo "$SIZE `oid2name \-q \-d alvherre \-i \-f $FILENODE`"
> done
16 1155287 branches_pkey
16 1155289 tellers_pkey
17561 1155291 accounts_pkey
\&.\&.\&.
$ # same, but sort by size
$ du [0\-9]* | sort \-rn | while read SIZE FN
> do
> echo "$SIZE `oid2name \-q \-d alvherre \-f $FN`"
> done
133466 155173 accounts
17561 1155291 accounts_pkey
1177 16717 pg_proc_proname_args_nsp_index
\&.\&.\&.
$ # If you want to see what\*(Aqs in tablespaces, use the pg_tblspc directory
$ cd $PGDATA/pg_tblspc
$ oid2name \-s
All tablespaces:
Oid Tablespace Name
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
1663 pg_default
1664 pg_global
155151 fastdisk
155152 bigdisk
$ # what databases have objects in tablespace "fastdisk"?
$ ls \-d 155151/*
155151/17228/ 155151/PG_VERSION
$ # Oh, what was database 17228 again?
$ oid2name
All databases:
Oid Database Name Tablespace
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
17228 alvherre pg_default
17255 regression pg_default
17227 template0 pg_default
1 template1 pg_default
$ # Let\*(Aqs see what objects does this database have in the tablespace\&.
$ cd 155151/17228
$ ls \-l
total 0
\-rw\-\-\-\-\-\-\- 1 postgres postgres 0 sep 13 23:20 155156
$ # OK, this is a pretty small table \&.\&.\&. but which one is it?
$ oid2name \-d alvherre \-f 155156
From database "alvherre":
Filenode Table Name
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
155156 foo
.fi
.if n \{\
.RE
.\}
.SH "AUTHOR"
.PP
B\&. Palmer
<bpalmer@crimelabs\&.net>
|