gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

83 linhas
5.7KB

  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>28.1. Determining Disk Usage</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="diskusage.html" title="Chapter 28. Monitoring Disk Usage" /><link rel="next" href="disk-full.html" title="28.2. Disk Full Failure" /></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">28.1. Determining Disk Usage</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="diskusage.html" title="Chapter 28. Monitoring Disk Usage">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="diskusage.html" title="Chapter 28. Monitoring Disk Usage">Up</a></td><th width="60%" align="center">Chapter 28. Monitoring Disk Usage</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="disk-full.html" title="28.2. Disk Full Failure">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="DISK-USAGE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">28.1. Determining Disk Usage</h2></div></div></div><a id="id-1.6.15.3.2" class="indexterm"></a><p>
  3. Each table has a primary heap disk file where most of the data is
  4. stored. If the table has any columns with potentially-wide values,
  5. there also might be a <acronym class="acronym">TOAST</acronym> file associated with the table,
  6. which is used to store values too wide to fit comfortably in the main
  7. table (see <a class="xref" href="storage-toast.html" title="68.2. TOAST">Section 68.2</a>). There will be one valid index
  8. on the <acronym class="acronym">TOAST</acronym> table, if present. There also might be indexes
  9. associated with the base table. Each table and index is stored in a
  10. separate disk file — possibly more than one file, if the file would
  11. exceed one gigabyte. Naming conventions for these files are described
  12. in <a class="xref" href="storage-file-layout.html" title="68.1. Database File Layout">Section 68.1</a>.
  13. </p><p>
  14. You can monitor disk space in three ways:
  15. using the SQL functions listed in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBSIZE" title="Table 9.89. Database Object Size Functions">Table 9.89</a>,
  16. using the <a class="xref" href="oid2name.html" title="oid2name"><span class="refentrytitle">oid2name</span></a> module, or
  17. using manual inspection of the system catalogs.
  18. The SQL functions are the easiest to use and are generally recommended.
  19. The remainder of this section shows how to do it by inspection of the
  20. system catalogs.
  21. </p><p>
  22. Using <span class="application">psql</span> on a recently vacuumed or analyzed database,
  23. you can issue queries to see the disk usage of any table:
  24. </p><pre class="programlisting">
  25. SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';
  26. pg_relation_filepath | relpages
  27. ----------------------+----------
  28. base/16384/16806 | 60
  29. (1 row)
  30. </pre><p>
  31. Each page is typically 8 kilobytes. (Remember, <code class="structfield">relpages</code>
  32. is only updated by <code class="command">VACUUM</code>, <code class="command">ANALYZE</code>, and
  33. a few DDL commands such as <code class="command">CREATE INDEX</code>.) The file path name
  34. is of interest if you want to examine the table's disk file directly.
  35. </p><p>
  36. To show the space used by <acronym class="acronym">TOAST</acronym> tables, use a query
  37. like the following:
  38. </p><pre class="programlisting">
  39. SELECT relname, relpages
  40. FROM pg_class,
  41. (SELECT reltoastrelid
  42. FROM pg_class
  43. WHERE relname = 'customer') AS ss
  44. WHERE oid = ss.reltoastrelid OR
  45. oid = (SELECT indexrelid
  46. FROM pg_index
  47. WHERE indrelid = ss.reltoastrelid)
  48. ORDER BY relname;
  49. relname | relpages
  50. ----------------------+----------
  51. pg_toast_16806 | 0
  52. pg_toast_16806_index | 1
  53. </pre><p>
  54. </p><p>
  55. You can easily display index sizes, too:
  56. </p><pre class="programlisting">
  57. SELECT c2.relname, c2.relpages
  58. FROM pg_class c, pg_class c2, pg_index i
  59. WHERE c.relname = 'customer' AND
  60. c.oid = i.indrelid AND
  61. c2.oid = i.indexrelid
  62. ORDER BY c2.relname;
  63. relname | relpages
  64. -------------------+----------
  65. customer_id_index | 26
  66. </pre><p>
  67. </p><p>
  68. It is easy to find your largest tables and indexes using this
  69. information:
  70. </p><pre class="programlisting">
  71. SELECT relname, relpages
  72. FROM pg_class
  73. ORDER BY relpages DESC;
  74. relname | relpages
  75. ----------------------+----------
  76. bigtable | 3290
  77. customer | 3144
  78. </pre><p>
  79. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="diskusage.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="diskusage.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="disk-full.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 28. Monitoring Disk Usage </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 28.2. Disk Full Failure</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1