]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/oid2name.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / oid2name.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>oid2name</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="contrib-prog-client.html" title="G.1. Client Applications" /><link rel="next" href="vacuumlo.html" title="vacuumlo" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">oid2name</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-prog-client.html" title="G.1. Client Applications">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib-prog-client.html" title="G.1. Client Applications">Up</a></td><th width="60%" align="center">G.1. Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="vacuumlo.html" title="vacuumlo">Next</a></td></tr></table><hr /></div><div class="refentry" id="OID2NAME"><div class="titlepage"></div><a id="id-1.11.8.4.3.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">oid2name</span></h2><p>oid2name — resolve OIDs and file nodes in a <span class="productname">PostgreSQL</span> data directory</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.11.8.4.3.4.1"><code class="command">oid2name</code> [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="id-1.11.8.4.3.5"><h2>Description</h2><p>
3   <span class="application">oid2name</span> is a utility program that helps administrators to
4   examine the file structure used by PostgreSQL.  To make use of it, you need
5   to be familiar with the database file structure, which is described in
6   <a class="xref" href="storage.html" title="Chapter 66. Database Physical Storage">Chapter 66</a>.
7  </p><div class="note"><h3 class="title">Note</h3><p>
8    The name <span class="quote">“<span class="quote">oid2name</span>”</span> is historical, and is actually rather
9    misleading, since most of the time when you use it, you will really
10    be concerned with tables' filenode numbers (which are the file names
11    visible in the database directories).  Be sure you understand the
12    difference between table OIDs and table filenodes!
13   </p></div><p>
14    <span class="application">oid2name</span> connects to a target database and
15    extracts OID, filenode, and/or table name information.  You can also have
16    it show database OIDs or tablespace OIDs.
17   </p></div><div class="refsect1" id="id-1.11.8.4.3.6"><h2>Options</h2><p>
18    <span class="application">oid2name</span> accepts the following command-line arguments:
19
20    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-f <em class="replaceable"><code>filenode</code></em></code><br /></span><span class="term"><code class="option">--filenode=<em class="replaceable"><code>filenode</code></em></code></span></dt><dd><p>show info for table with filenode <em class="replaceable"><code>filenode</code></em>.</p></dd><dt><span class="term"><code class="option">-i</code><br /></span><span class="term"><code class="option">--indexes</code></span></dt><dd><p>include indexes and sequences in the listing.</p></dd><dt><span class="term"><code class="option">-o <em class="replaceable"><code>oid</code></em></code><br /></span><span class="term"><code class="option">--oid=<em class="replaceable"><code>oid</code></em></code></span></dt><dd><p>show info for table with OID <em class="replaceable"><code>oid</code></em>.</p></dd><dt><span class="term"><code class="option">-q</code><br /></span><span class="term"><code class="option">--quiet</code></span></dt><dd><p>omit headers (useful for scripting).</p></dd><dt><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--tablespaces</code></span></dt><dd><p>show tablespace OIDs.</p></dd><dt><span class="term"><code class="option">-S</code><br /></span><span class="term"><code class="option">--system-objects</code></span></dt><dd><p>include system objects (those in
21       <code class="option">information_schema</code>, <code class="option">pg_toast</code>
22       and <code class="option">pg_catalog</code> schemas).
23      </p></dd><dt><span class="term"><code class="option">-t <em class="replaceable"><code>tablename_pattern</code></em></code><br /></span><span class="term"><code class="option">--table=<em class="replaceable"><code>tablename_pattern</code></em></code></span></dt><dd><p>show info for table(s) matching <em class="replaceable"><code>tablename_pattern</code></em>.</p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
24        Print the <span class="application">oid2name</span> version and exit.
25       </p></dd><dt><span class="term"><code class="option">-x</code><br /></span><span class="term"><code class="option">--extended</code></span></dt><dd><p>display more information about each object shown: tablespace name,
26       schema name, and OID.
27      </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
28        Show help about <span class="application">oid2name</span> command line
29        arguments, and exit.
30       </p></dd></dl></div><p>
31   </p><p>
32    <span class="application">oid2name</span> also accepts the following command-line
33    arguments for connection parameters:
34
35    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-d <em class="replaceable"><code>database</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>database</code></em></code></span></dt><dd><p>database to connect to.</p></dd><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>database server's host.</p></dd><dt><span class="term"><code class="option">-H <em class="replaceable"><code>host</code></em></code></span></dt><dd><p>database server's host.  Use of this parameter is
36      <span class="emphasis"><em>deprecated</em></span> as of
37      <span class="productname">PostgreSQL</span> 12.</p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>database server's port.</p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>user name to connect as.</p></dd></dl></div><p>
38   </p><p>
39    To display specific tables, select which tables to show by
40    using <code class="option">-o</code>, <code class="option">-f</code> and/or <code class="option">-t</code>.
41    <code class="option">-o</code> takes an OID,
42    <code class="option">-f</code> takes a filenode,
43    and <code class="option">-t</code> takes a table name (actually, it's a <code class="literal">LIKE</code>
44    pattern, so you can use things like <code class="literal">foo%</code>).
45    You can use as many
46    of these options as you like, and the listing will include all objects
47    matched by any of the options.  But note that these options can only
48    show objects in the database given by <code class="option">-d</code>.
49   </p><p>
50    If you don't give any of <code class="option">-o</code>, <code class="option">-f</code> or <code class="option">-t</code>,
51    but do give <code class="option">-d</code>, it will list all tables in the database
52    named by <code class="option">-d</code>.  In this mode, the <code class="option">-S</code> and
53    <code class="option">-i</code> options control what gets listed.
54   </p><p>
55    If you don't give <code class="option">-d</code> either, it will show a listing of database
56    OIDs.  Alternatively you can give <code class="option">-s</code> to get a tablespace
57    listing.
58   </p></div><div class="refsect1" id="id-1.11.8.4.3.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
59       Default connection parameters.
60      </p></dd></dl></div><p>
61    This utility, like most other <span class="productname">PostgreSQL</span>
62    utilities, also uses the environment variables supported by
63    <span class="application">libpq</span> (see <a class="xref" href="libpq-envars.html" title="32.15. Environment Variables">Section 32.15</a>).
64   </p><p>
65    The environment variable <code class="envar">PG_COLOR</code> specifies whether to use
66    color in diagnostic messages. Possible values are
67    <code class="literal">always</code>, <code class="literal">auto</code> and
68    <code class="literal">never</code>.
69   </p></div><div class="refsect1" id="id-1.11.8.4.3.8"><h2>Notes</h2><p>
70    <span class="application">oid2name</span> requires a running database server with
71    non-corrupt system catalogs.  It is therefore of only limited use
72    for recovering from catastrophic database corruption situations.
73   </p></div><div class="refsect1" id="id-1.11.8.4.3.9"><h2>Examples</h2><pre class="screen">
74 $ # what's in this database server, anyway?
75 $ oid2name
76 All databases:
77     Oid  Database Name  Tablespace
78 ----------------------------------
79   17228       alvherre  pg_default
80   17255     regression  pg_default
81   17227      template0  pg_default
82       1      template1  pg_default
83
84 $ oid2name -s
85 All tablespaces:
86      Oid  Tablespace Name
87 -------------------------
88     1663       pg_default
89     1664        pg_global
90   155151         fastdisk
91   155152          bigdisk
92
93 $ # OK, let's look into database alvherre
94 $ cd $PGDATA/base/17228
95
96 $ # get top 10 db objects in the default tablespace, ordered by size
97 $ ls -lS * | head -10
98 -rw-------  1 alvherre alvherre 136536064 sep 14 09:51 155173
99 -rw-------  1 alvherre alvherre  17965056 sep 14 09:51 1155291
100 -rw-------  1 alvherre alvherre   1204224 sep 14 09:51 16717
101 -rw-------  1 alvherre alvherre    581632 sep  6 17:51 1255
102 -rw-------  1 alvherre alvherre    237568 sep 14 09:50 16674
103 -rw-------  1 alvherre alvherre    212992 sep 14 09:51 1249
104 -rw-------  1 alvherre alvherre    204800 sep 14 09:51 16684
105 -rw-------  1 alvherre alvherre    196608 sep 14 09:50 16700
106 -rw-------  1 alvherre alvherre    163840 sep 14 09:50 16699
107 -rw-------  1 alvherre alvherre    122880 sep  6 17:51 16751
108
109 $ # What file is 155173?
110 $ oid2name -d alvherre -f 155173
111 From database "alvherre":
112   Filenode  Table Name
113 ----------------------
114     155173    accounts
115
116 $ # you can ask for more than one object
117 $ oid2name -d alvherre -f 155173 -f 1155291
118 From database "alvherre":
119   Filenode     Table Name
120 -------------------------
121     155173       accounts
122    1155291  accounts_pkey
123
124 $ # you can mix the options, and get more details with -x
125 $ oid2name -d alvherre -t accounts -f 1155291 -x
126 From database "alvherre":
127   Filenode     Table Name      Oid  Schema  Tablespace
128 ------------------------------------------------------
129     155173       accounts   155173  public  pg_default
130    1155291  accounts_pkey  1155291  public  pg_default
131
132 $ # show disk space for every db object
133 $ du [0-9]* |
134 &gt; while read SIZE FILENODE
135 &gt; do
136 &gt;   echo "$SIZE       `oid2name -q -d alvherre -i -f $FILENODE`"
137 &gt; done
138 16            1155287  branches_pkey
139 16            1155289  tellers_pkey
140 17561            1155291  accounts_pkey
141 ...
142
143 $ # same, but sort by size
144 $ du [0-9]* | sort -rn | while read SIZE FN
145 &gt; do
146 &gt;   echo "$SIZE   `oid2name -q -d alvherre -f $FN`"
147 &gt; done
148 133466             155173    accounts
149 17561            1155291  accounts_pkey
150 1177              16717  pg_proc_proname_args_nsp_index
151 ...
152
153 $ # If you want to see what's in tablespaces, use the pg_tblspc directory
154 $ cd $PGDATA/pg_tblspc
155 $ oid2name -s
156 All tablespaces:
157      Oid  Tablespace Name
158 -------------------------
159     1663       pg_default
160     1664        pg_global
161   155151         fastdisk
162   155152          bigdisk
163
164 $ # what databases have objects in tablespace "fastdisk"?
165 $ ls -d 155151/*
166 155151/17228/  155151/PG_VERSION
167
168 $ # Oh, what was database 17228 again?
169 $ oid2name
170 All databases:
171     Oid  Database Name  Tablespace
172 ----------------------------------
173   17228       alvherre  pg_default
174   17255     regression  pg_default
175   17227      template0  pg_default
176       1      template1  pg_default
177
178 $ # Let's see what objects does this database have in the tablespace.
179 $ cd 155151/17228
180 $ ls -l
181 total 0
182 -rw-------  1 postgres postgres 0 sep 13 23:20 155156
183
184 $ # OK, this is a pretty small table ... but which one is it?
185 $ oid2name -d alvherre -f 155156
186 From database "alvherre":
187   Filenode  Table Name
188 ----------------------
189     155156         foo
190 </pre></div><div class="refsect1" id="id-1.11.8.4.3.10"><h2>Author</h2><p>
191    B. Palmer <code class="email">&lt;<a class="email" href="mailto:bpalmer@crimelabs.net">bpalmer@crimelabs.net</a>&gt;</code>
192   </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="contrib-prog-client.html" title="G.1. Client Applications">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib-prog-client.html" title="G.1. Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="vacuumlo.html" title="vacuumlo">Next</a></td></tr><tr><td width="40%" align="left" valign="top">G.1. Client Applications </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">vacuumlo</span></td></tr></table></div></body></html>