Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > bab02a23fa9f3df8d66a9a3231b50245 > files > 386

postgresql8.3-docs-8.3.6-2mdv2008.1.x86_64.rpm

<!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 8.3.6 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="2009-02-03T04:34:16"></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"
>PostgreSQL 8.3.6 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="ltree.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="contrib.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Appendix F. Additional Supplied Modules</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="contrib.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
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.16. oid2name</A
></H1
><A
NAME="AEN101807"
></A
><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 53</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="AEN101815"
>F.16.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.  The program is controlled by
   a large number of command-line switches, as shown in
   <A
HREF="oid2name.html#OID2NAME-SWITCHES"
>Table F-13</A
>.
  </P
><DIV
CLASS="TABLE"
><A
NAME="OID2NAME-SWITCHES"
></A
><P
><B
>Table F-13. <SPAN
CLASS="APPLICATION"
>oid2name</SPAN
> switches</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Switch</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>-o</TT
> <TT
CLASS="REPLACEABLE"
><I
>oid</I
></TT
></TD
><TD
>show info for table with OID <TT
CLASS="REPLACEABLE"
><I
>oid</I
></TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-f</TT
> <TT
CLASS="REPLACEABLE"
><I
>filenode</I
></TT
></TD
><TD
>show info for table with filenode <TT
CLASS="REPLACEABLE"
><I
>filenode</I
></TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-t</TT
> <TT
CLASS="REPLACEABLE"
><I
>tablename_pattern</I
></TT
></TD
><TD
>show info for table(s) matching <TT
CLASS="REPLACEABLE"
><I
>tablename_pattern</I
></TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-s</TT
></TD
><TD
>show tablespace OIDs</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-S</TT
></TD
><TD
>include system objects (those in
       <TT
CLASS="LITERAL"
>information_schema</TT
>, <TT
CLASS="LITERAL"
>pg_toast</TT
>
       and <TT
CLASS="LITERAL"
>pg_catalog</TT
> schemas)
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-i</TT
></TD
><TD
>include indexes and sequences in the listing</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-x</TT
></TD
><TD
>display more information about each object shown: tablespace name,
       schema name, and OID
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-q</TT
></TD
><TD
>omit headers (useful for scripting)</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-d</TT
> <TT
CLASS="REPLACEABLE"
><I
>database</I
></TT
></TD
><TD
>database to connect to</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-H</TT
> <TT
CLASS="REPLACEABLE"
><I
>host</I
></TT
></TD
><TD
>database server's host</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-p</TT
> <TT
CLASS="REPLACEABLE"
><I
>port</I
></TT
></TD
><TD
>database server's port</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-U</TT
> <TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></TD
><TD
>username to connect as</TD
></TR
></TBODY
></TABLE
></DIV
><P
>   To display specific tables, select which tables to show by
   using <TT
CLASS="LITERAL"
>-o</TT
>, <TT
CLASS="LITERAL"
>-f</TT
> and/or <TT
CLASS="LITERAL"
>-t</TT
>.
   <TT
CLASS="LITERAL"
>-o</TT
> takes an OID,
   <TT
CLASS="LITERAL"
>-f</TT
> takes a filenode,
   and <TT
CLASS="LITERAL"
>-t</TT
> takes a tablename (actually, it's a LIKE
   pattern, so you can use things like <TT
CLASS="LITERAL"
>foo%</TT
>).
   You can use as many
   of these switches as you like, and the listing will include all objects
   matched by any of the switches.  But note that these switches can only
   show objects in the database given by <TT
CLASS="LITERAL"
>-d</TT
>.
  </P
><P
>   If you don't give any of <TT
CLASS="LITERAL"
>-o</TT
>, <TT
CLASS="LITERAL"
>-f</TT
> or <TT
CLASS="LITERAL"
>-t</TT
>,
   but do give <TT
CLASS="LITERAL"
>-d</TT
>, it will list all tables in the database
   named by <TT
CLASS="LITERAL"
>-d</TT
>.  In this mode, the <TT
CLASS="LITERAL"
>-S</TT
> and
   <TT
CLASS="LITERAL"
>-i</TT
> switches control what gets listed.
  </P
><P
>   If you don't give <TT
CLASS="LITERAL"
>-d</TT
> either, it will show a listing of database
   OIDs.  Alternatively you can give <TT
CLASS="LITERAL"
>-s</TT
> to get a tablespace
   listing.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN101910"
>F.16.2. Examples</A
></H2
><PRE
CLASS="PROGRAMLISTING"
>$ # 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="AEN101913"
>F.16.3. 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="AEN101917"
>F.16.4. 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
>