codekingpro/portable-devtools
115k
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 16.3 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 to4 examine the file structure used by PostgreSQL. To make use of it, you need5 to be familiar with the database file structure, which is described in6 <a class="xref" href="storage.html" title="Chapter 73. Database Physical Storage">Chapter 73</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 rather9 misleading, since most of the time when you use it, you will really10 be concerned with tables' filenode numbers (which are the file names11 visible in the database directories). Be sure you understand the12 difference between table OIDs and table filenodes!13 </p></div><p>14 <span class="application">oid2name</span> connects to a target database and15 extracts OID, filenode, and/or table name information. You can also have16 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 in21 <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 line29 arguments, and exit.30 </p></dd></dl></div><p>31 </p><p>32 <span class="application">oid2name</span> also accepts the following command-line33 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 is36 <span class="emphasis"><em>deprecated</em></span> as of37 <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 by40 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 many46 of these options as you like, and the listing will include all objects47 matched by any of the options. But note that these options can only48 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 database52 named by <code class="option">-d</code>. In this mode, the <code class="option">-S</code> and53 <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 database56 OIDs. Alternatively you can give <code class="option">-s</code> to get a tablespace57 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 by63 <span class="application">libpq</span> (see <a class="xref" href="libpq-envars.html" title="34.15. Environment Variables">Section 34.15</a>).64 </p><p>65 The environment variable <code class="envar">PG_COLOR</code> specifies whether to use66 color in diagnostic messages. Possible values are67 <code class="literal">always</code>, <code class="literal">auto</code> and68 <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 with71 non-corrupt system catalogs. It is therefore of only limited use72 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$ oid2name76All databases:77 Oid Database Name Tablespace78----------------------------------79 17228 alvherre pg_default80 17255 regression pg_default81 17227 template0 pg_default82 1 template1 pg_default83 84$ oid2name -s85All tablespaces:86 Oid Tablespace Name87-------------------------88 1663 pg_default89 1664 pg_global90 155151 fastdisk91 155152 bigdisk92 93$ # OK, let's look into database alvherre94$ cd $PGDATA/base/1722895 96$ # get top 10 db objects in the default tablespace, ordered by size97$ ls -lS * | head -1098-rw------- 1 alvherre alvherre 136536064 sep 14 09:51 15517399-rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291100-rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717101-rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255102-rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674103-rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249104-rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684105-rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700106-rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699107-rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751108 109$ # I wonder what file 155173 is ...110$ oid2name -d alvherre -f 155173111From database "alvherre":112 Filenode Table Name113----------------------114 155173 accounts115 116$ # you can ask for more than one object117$ oid2name -d alvherre -f 155173 -f 1155291118From database "alvherre":119 Filenode Table Name120-------------------------121 155173 accounts122 1155291 accounts_pkey123 124$ # you can mix the options, and get more details with -x125$ oid2name -d alvherre -t accounts -f 1155291 -x126From database "alvherre":127 Filenode Table Name Oid Schema Tablespace128------------------------------------------------------129 155173 accounts 155173 public pg_default130 1155291 accounts_pkey 1155291 public pg_default131 132$ # show disk space for every db object133$ du [0-9]* |134> while read SIZE FILENODE135> do136> echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"137> done13816 1155287 branches_pkey13916 1155289 tellers_pkey14017561 1155291 accounts_pkey141...142 143$ # same, but sort by size144$ du [0-9]* | sort -rn | while read SIZE FN145> do146> echo "$SIZE `oid2name -q -d alvherre -f $FN`"147> done148133466 155173 accounts14917561 1155291 accounts_pkey1501177 16717 pg_proc_proname_args_nsp_index151...152 153$ # If you want to see what's in tablespaces, use the pg_tblspc directory154$ cd $PGDATA/pg_tblspc155$ oid2name -s156All tablespaces:157 Oid Tablespace Name158-------------------------159 1663 pg_default160 1664 pg_global161 155151 fastdisk162 155152 bigdisk163 164$ # what databases have objects in tablespace "fastdisk"?165$ ls -d 155151/*166155151/17228/ 155151/PG_VERSION167 168$ # Oh, what was database 17228 again?169$ oid2name170All databases:171 Oid Database Name Tablespace172----------------------------------173 17228 alvherre pg_default174 17255 regression pg_default175 17227 template0 pg_default176 1 template1 pg_default177 178$ # Let's see what objects does this database have in the tablespace.179$ cd 155151/17228180$ ls -l181total 0182-rw------- 1 postgres postgres 0 sep 13 23:20 155156183 184$ # OK, this is a pretty small table ... but which one is it?185$ oid2name -d alvherre -f 155156186From database "alvherre":187 Filenode Table Name188----------------------189 155156 foo190</pre></div><div class="refsect1" id="id-1.11.8.4.3.10"><h2>Author</h2><p>191 B. Palmer <code class="email"><<a class="email" href="mailto:bpalmer@crimelabs.net">bpalmer@crimelabs.net</a>></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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">vacuumlo</span></td></tr></table></div></body></html>