gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

187 lines
14KB

  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 V1.79.1" /><link rel="prev" href="contrib-prog-client.html" title="G.1. Client Applications" /><link rel="next" href="vacuumlo.html" title="vacuumlo" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="vacuumlo.html" title="vacuumlo">Next</a></td></tr></table><hr></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 68. Database Physical Storage">Chapter 68</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. </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
  20. <code class="option">information_schema</code>, <code class="option">pg_toast</code>
  21. and <code class="option">pg_catalog</code> schemas).
  22. </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>
  23. Print the <span class="application">oid2name</span> version and exit.
  24. </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,
  25. schema name, and OID.
  26. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  27. Show help about <span class="application">oid2name</span> command line
  28. arguments, and exit.
  29. </p></dd></dl></div><p>
  30. </p><p>
  31. <span class="application">oid2name</span> also accepts the following command-line
  32. arguments for connection parameters:
  33. </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
  34. <span class="emphasis"><em>deprecated</em></span> as of
  35. <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>
  36. </p><p>
  37. To display specific tables, select which tables to show by
  38. using <code class="option">-o</code>, <code class="option">-f</code> and/or <code class="option">-t</code>.
  39. <code class="option">-o</code> takes an OID,
  40. <code class="option">-f</code> takes a filenode,
  41. and <code class="option">-t</code> takes a table name (actually, it's a <code class="literal">LIKE</code>
  42. pattern, so you can use things like <code class="literal">foo%</code>).
  43. You can use as many
  44. of these options as you like, and the listing will include all objects
  45. matched by any of the options. But note that these options can only
  46. show objects in the database given by <code class="option">-d</code>.
  47. </p><p>
  48. If you don't give any of <code class="option">-o</code>, <code class="option">-f</code> or <code class="option">-t</code>,
  49. but do give <code class="option">-d</code>, it will list all tables in the database
  50. named by <code class="option">-d</code>. In this mode, the <code class="option">-S</code> and
  51. <code class="option">-i</code> options control what gets listed.
  52. </p><p>
  53. If you don't give <code class="option">-d</code> either, it will show a listing of database
  54. OIDs. Alternatively you can give <code class="option">-s</code> to get a tablespace
  55. listing.
  56. </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>
  57. Default connection parameters.
  58. </p></dd></dl></div><p>
  59. This utility, like most other <span class="productname">PostgreSQL</span>
  60. utilities, also uses the environment variables supported by
  61. <span class="application">libpq</span> (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  62. </p></div><div class="refsect1" id="id-1.11.8.4.3.8"><h2>Notes</h2><p>
  63. <span class="application">oid2name</span> requires a running database server with
  64. non-corrupt system catalogs. It is therefore of only limited use
  65. for recovering from catastrophic database corruption situations.
  66. </p></div><div class="refsect1" id="id-1.11.8.4.3.9"><h2>Examples</h2><pre class="screen">
  67. $ # what's in this database server, anyway?
  68. $ oid2name
  69. All databases:
  70. Oid Database Name Tablespace
  71. ----------------------------------
  72. 17228 alvherre pg_default
  73. 17255 regression pg_default
  74. 17227 template0 pg_default
  75. 1 template1 pg_default
  76. $ oid2name -s
  77. All tablespaces:
  78. Oid Tablespace Name
  79. -------------------------
  80. 1663 pg_default
  81. 1664 pg_global
  82. 155151 fastdisk
  83. 155152 bigdisk
  84. $ # OK, let's look into database alvherre
  85. $ cd $PGDATA/base/17228
  86. $ # get top 10 db objects in the default tablespace, ordered by size
  87. $ ls -lS * | head -10
  88. -rw------- 1 alvherre alvherre 136536064 sep 14 09:51 155173
  89. -rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291
  90. -rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717
  91. -rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255
  92. -rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674
  93. -rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249
  94. -rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684
  95. -rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700
  96. -rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699
  97. -rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751
  98. $ # I wonder what file 155173 is ...
  99. $ oid2name -d alvherre -f 155173
  100. From database "alvherre":
  101. Filenode Table Name
  102. ----------------------
  103. 155173 accounts
  104. $ # you can ask for more than one object
  105. $ oid2name -d alvherre -f 155173 -f 1155291
  106. From database "alvherre":
  107. Filenode Table Name
  108. -------------------------
  109. 155173 accounts
  110. 1155291 accounts_pkey
  111. $ # you can mix the options, and get more details with -x
  112. $ oid2name -d alvherre -t accounts -f 1155291 -x
  113. From database "alvherre":
  114. Filenode Table Name Oid Schema Tablespace
  115. ------------------------------------------------------
  116. 155173 accounts 155173 public pg_default
  117. 1155291 accounts_pkey 1155291 public pg_default
  118. $ # show disk space for every db object
  119. $ du [0-9]* |
  120. &gt; while read SIZE FILENODE
  121. &gt; do
  122. &gt; echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"
  123. &gt; done
  124. 16 1155287 branches_pkey
  125. 16 1155289 tellers_pkey
  126. 17561 1155291 accounts_pkey
  127. ...
  128. $ # same, but sort by size
  129. $ du [0-9]* | sort -rn | while read SIZE FN
  130. &gt; do
  131. &gt; echo "$SIZE `oid2name -q -d alvherre -f $FN`"
  132. &gt; done
  133. 133466 155173 accounts
  134. 17561 1155291 accounts_pkey
  135. 1177 16717 pg_proc_proname_args_nsp_index
  136. ...
  137. $ # If you want to see what's in tablespaces, use the pg_tblspc directory
  138. $ cd $PGDATA/pg_tblspc
  139. $ oid2name -s
  140. All tablespaces:
  141. Oid Tablespace Name
  142. -------------------------
  143. 1663 pg_default
  144. 1664 pg_global
  145. 155151 fastdisk
  146. 155152 bigdisk
  147. $ # what databases have objects in tablespace "fastdisk"?
  148. $ ls -d 155151/*
  149. 155151/17228/ 155151/PG_VERSION
  150. $ # Oh, what was database 17228 again?
  151. $ oid2name
  152. All databases:
  153. Oid Database Name Tablespace
  154. ----------------------------------
  155. 17228 alvherre pg_default
  156. 17255 regression pg_default
  157. 17227 template0 pg_default
  158. 1 template1 pg_default
  159. $ # Let's see what objects does this database have in the tablespace.
  160. $ cd 155151/17228
  161. $ ls -l
  162. total 0
  163. -rw------- 1 postgres postgres 0 sep 13 23:20 155156
  164. $ # OK, this is a pretty small table ... but which one is it?
  165. $ oid2name -d alvherre -f 155156
  166. From database "alvherre":
  167. Filenode Table Name
  168. ----------------------
  169. 155156 foo
  170. </pre></div><div class="refsect1" id="id-1.11.8.4.3.10"><h2>Author</h2><p>
  171. B. Palmer <code class="email">&lt;<a class="email" href="mailto:bpalmer@crimelabs.net">bpalmer@crimelabs.net</a>&gt;</code>
  172. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib-prog-client.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="vacuumlo.html">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">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">vacuumlo</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1