~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>oid2name</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.3 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Additional Supplied Modules"
HREF="contrib.html"><LINK
REL="PREVIOUS"
TITLE="ltree"
HREF="ltree.html"><LINK
REL="NEXT"
TITLE="pageinspect"
HREF="pageinspect.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2012-02-23T23:09:00"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.3 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="ltree"
HREF="ltree.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="contrib.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Appendix F. Additional Supplied Modules</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="pageinspect"
HREF="pageinspect.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="OID2NAME"
>F.22. oid2name</A
></H1
><P
>  <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> 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
  <A
HREF="storage.html"
>Chapter 55</A
>.
 </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>   The name <SPAN
CLASS="QUOTE"
>"oid2name"</SPAN
> is historical, and is actually rather
   misleading, since most of the time when you use it, you will really
   be concerned with tables' filenode numbers (which are the file names
   visible in the database directories).  Be sure you understand the
   difference between table OIDs and table filenodes!
  </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN134227"
>F.22.1. Overview</A
></H2
><P
>   <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> 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.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN134231"
>F.22.2. <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> Options</A
></H2
><P
>   <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> accepts the following command-line arguments:

   <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="OPTION"
>-o</TT
> <TT
CLASS="REPLACEABLE"
><I
>oid</I
></TT
></DT
><DD
><P
>show info for table with OID <TT
CLASS="REPLACEABLE"
><I
>oid</I
></TT
></P
></DD
><DT
><TT
CLASS="OPTION"
>-f</TT
> <TT
CLASS="REPLACEABLE"
><I
>filenode</I
></TT
></DT
><DD
><P
>show info for table with filenode <TT
CLASS="REPLACEABLE"
><I
>filenode</I
></TT
></P
></DD
><DT
><TT
CLASS="OPTION"
>-t</TT
> <TT
CLASS="REPLACEABLE"
><I
>tablename_pattern</I
></TT
></DT
><DD
><P
>show info for table(s) matching <TT
CLASS="REPLACEABLE"
><I
>tablename_pattern</I
></TT
></P
></DD
><DT
><TT
CLASS="OPTION"
>-s</TT
></DT
><DD
><P
>show tablespace OIDs</P
></DD
><DT
><TT
CLASS="OPTION"
>-S</TT
></DT
><DD
><P
>include system objects (those in
      <TT
CLASS="OPTION"
>information_schema</TT
>, <TT
CLASS="OPTION"
>pg_toast</TT
>
      and <TT
CLASS="OPTION"
>pg_catalog</TT
> schemas)
     </P
></DD
><DT
><TT
CLASS="OPTION"
>-i</TT
></DT
><DD
><P
>include indexes and sequences in the listing</P
></DD
><DT
><TT
CLASS="OPTION"
>-x</TT
></DT
><DD
><P
>display more information about each object shown: tablespace name,
      schema name, and OID
     </P
></DD
><DT
><TT
CLASS="OPTION"
>-q</TT
></DT
><DD
><P
>omit headers (useful for scripting)</P
></DD
><DT
><TT
CLASS="OPTION"
>-d</TT
> <TT
CLASS="REPLACEABLE"
><I
>database</I
></TT
></DT
><DD
><P
>database to connect to</P
></DD
><DT
><TT
CLASS="OPTION"
>-H</TT
> <TT
CLASS="REPLACEABLE"
><I
>host</I
></TT
></DT
><DD
><P
>database server's host</P
></DD
><DT
><TT
CLASS="OPTION"
>-p</TT
> <TT
CLASS="REPLACEABLE"
><I
>port</I
></TT
></DT
><DD
><P
>database server's port</P
></DD
><DT
><TT
CLASS="OPTION"
>-U</TT
> <TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></DT
><DD
><P
>user name to connect as</P
></DD
><DT
><TT
CLASS="OPTION"
>-P</TT
> <TT
CLASS="REPLACEABLE"
><I
>password</I
></TT
></DT
><DD
><P
>password (deprecated &mdash; putting this on the command line
      is a security hazard)</P
></DD
></DL
></DIV
><P>
  </P
><P
>   To display specific tables, select which tables to show by
   using <TT
CLASS="OPTION"
>-o</TT
>, <TT
CLASS="OPTION"
>-f</TT
> and/or <TT
CLASS="OPTION"
>-t</TT
>.
   <TT
CLASS="OPTION"
>-o</TT
> takes an OID,
   <TT
CLASS="OPTION"
>-f</TT
> takes a filenode,
   and <TT
CLASS="OPTION"
>-t</TT
> takes a table name (actually, it's a <TT
CLASS="LITERAL"
>LIKE</TT
>
   pattern, so you can use things like <TT
CLASS="LITERAL"
>foo%</TT
>).
   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 <TT
CLASS="OPTION"
>-d</TT
>.
  </P
><P
>   If you don't give any of <TT
CLASS="OPTION"
>-o</TT
>, <TT
CLASS="OPTION"
>-f</TT
> or <TT
CLASS="OPTION"
>-t</TT
>,
   but do give <TT
CLASS="OPTION"
>-d</TT
>, it will list all tables in the database
   named by <TT
CLASS="OPTION"
>-d</TT
>.  In this mode, the <TT
CLASS="OPTION"
>-S</TT
> and
   <TT
CLASS="OPTION"
>-i</TT
> options control what gets listed.
  </P
><P
>   If you don't give <TT
CLASS="OPTION"
>-d</TT
> either, it will show a listing of database
   OIDs.  Alternatively you can give <TT
CLASS="OPTION"
>-s</TT
> to get a tablespace
   listing.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN134337"
>F.22.3. Examples</A
></H2
><PRE
CLASS="SCREEN"
>$ # what's 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's 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]* |
&#62; while read SIZE FILENODE
&#62; do
&#62;   echo "$SIZE       `oid2name -q -d alvherre -i -f $FILENODE`"
&#62; 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
&#62; do
&#62;   echo "$SIZE   `oid2name -q -d alvherre -f $FN`"
&#62; done
133466             155173    accounts
17561            1155291  accounts_pkey
1177              16717  pg_proc_proname_args_nsp_index
...

$ # If you want to see what's 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's 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</PRE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN134340"
>F.22.4. Limitations</A
></H2
><P
>   <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> requires a running database server with
   non-corrupt system catalogs.  It is therefore of only limited use
   for recovering from catastrophic database corruption situations.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN134344"
>F.22.5. Author</A
></H2
><P
>   B. Palmer <CODE
CLASS="EMAIL"
>&#60;<A
HREF="mailto:bpalmer@crimelabs.net"
>bpalmer@crimelabs.net</A
>&#62;</CODE
>
  </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="ltree.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="pageinspect.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ltree</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="contrib.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>pageinspect</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>