]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/diskusage.html
WIP: toc builder
[ai-pg] / full-docs / src / sgml / html / diskusage.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>27.6. Monitoring 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 Vsnapshot" /><link rel="prev" href="dynamic-trace.html" title="27.5. Dynamic Tracing" /><link rel="next" href="wal.html" title="Chapter 28. Reliability and the Write-Ahead Log" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">27.6. Monitoring Disk Usage</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="dynamic-trace.html" title="27.5. Dynamic Tracing">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="monitoring.html" title="Chapter 27. Monitoring Database Activity">Up</a></td><th width="60%" align="center">Chapter 27. Monitoring Database Activity</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="wal.html" title="Chapter 28. Reliability and the Write-Ahead Log">Next</a></td></tr></table><hr /></div><div class="sect1" id="DISKUSAGE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">27.6. Monitoring Disk Usage <a href="#DISKUSAGE" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="diskusage.html#DISK-USAGE">27.6.1. Determining Disk Usage</a></span></dt><dt><span class="sect2"><a href="diskusage.html#DISK-FULL">27.6.2. Disk Full Failure</a></span></dt></dl></div><p>
3    This section discusses how to monitor the disk usage of a
4    <span class="productname">PostgreSQL</span> database system.
5   </p><div class="sect2" id="DISK-USAGE"><div class="titlepage"><div><div><h3 class="title">27.6.1. Determining Disk Usage <a href="#DISK-USAGE" class="id_link">#</a></h3></div></div></div><a id="id-1.6.14.11.3.2" class="indexterm"></a><p>
6     Each table has a primary heap disk file where most of the data is
7     stored. If the table has any columns with potentially-wide values,
8     there also might be a <acronym class="acronym">TOAST</acronym> file associated with the table,
9     which is used to store values too wide to fit comfortably in the main
10     table (see <a class="xref" href="storage-toast.html" title="66.2. TOAST">Section 66.2</a>).  There will be one valid index
11     on the <acronym class="acronym">TOAST</acronym> table, if present. There also might be indexes
12     associated with the base table.  Each table and index is stored in a
13     separate disk file — possibly more than one file, if the file would
14     exceed one gigabyte.  Naming conventions for these files are described
15     in <a class="xref" href="storage-file-layout.html" title="66.1. Database File Layout">Section 66.1</a>.
16    </p><p>
17     You can monitor disk space in three ways:
18     using the SQL functions listed in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-DBSIZE" title="Table 9.102. Database Object Size Functions">Table 9.102</a>,
19     using the <a class="xref" href="oid2name.html" title="oid2name"><span class="refentrytitle">oid2name</span></a> module, or
20     using manual inspection of the system catalogs.
21     The SQL functions are the easiest to use and are generally recommended.
22     The remainder of this section shows how to do it by inspection of the
23     system catalogs.
24    </p><p>
25     Using <span class="application">psql</span> on a recently vacuumed or analyzed
26     database, you can issue queries to see the disk usage of any table:
27 </p><pre class="programlisting">
28 SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';
29
30  pg_relation_filepath | relpages
31 ----------------------+----------
32  base/16384/16806     |       60
33 (1 row)
34 </pre><p>
35     Each page is typically 8 kilobytes. (Remember, <code class="structfield">relpages</code>
36     is only updated by <code class="command">VACUUM</code>, <code class="command">ANALYZE</code>, and
37     a few DDL commands such as <code class="command">CREATE INDEX</code>.)  The file path name
38     is of interest if you want to examine the table's disk file directly.
39    </p><p>
40     To show the space used by <acronym class="acronym">TOAST</acronym> tables, use a query
41     like the following:
42 </p><pre class="programlisting">
43 SELECT relname, relpages
44 FROM pg_class,
45      (SELECT reltoastrelid
46       FROM pg_class
47       WHERE relname = 'customer') AS ss
48 WHERE oid = ss.reltoastrelid OR
49       oid = (SELECT indexrelid
50              FROM pg_index
51              WHERE indrelid = ss.reltoastrelid)
52 ORDER BY relname;
53
54        relname        | relpages
55 ----------------------+----------
56  pg_toast_16806       |        0
57  pg_toast_16806_index |        1
58 </pre><p>
59    </p><p>
60     You can easily display index sizes, too:
61 </p><pre class="programlisting">
62 SELECT c2.relname, c2.relpages
63 FROM pg_class c, pg_class c2, pg_index i
64 WHERE c.relname = 'customer' AND
65       c.oid = i.indrelid AND
66       c2.oid = i.indexrelid
67 ORDER BY c2.relname;
68
69       relname      | relpages
70 -------------------+----------
71  customer_id_index |       26
72 </pre><p>
73    </p><p>
74     It is easy to find your largest tables and indexes using this
75     information:
76 </p><pre class="programlisting">
77 SELECT relname, relpages
78 FROM pg_class
79 ORDER BY relpages DESC;
80
81        relname        | relpages
82 ----------------------+----------
83  bigtable             |     3290
84  customer             |     3144
85 </pre><p>
86    </p></div><div class="sect2" id="DISK-FULL"><div class="titlepage"><div><div><h3 class="title">27.6.2. Disk Full Failure <a href="#DISK-FULL" class="id_link">#</a></h3></div></div></div><p>
87     The most important disk monitoring task of a database administrator
88     is to make sure the disk doesn't become full.  A filled data disk will
89     not result in data corruption, but it might prevent useful activity
90     from occurring. If the disk holding the WAL files grows full, database
91     server panic and consequent shutdown might occur.
92    </p><p>
93     If you cannot free up additional space on the disk by deleting
94     other things, you can move some of the database files to other file
95     systems by making use of tablespaces. See <a class="xref" href="manage-ag-tablespaces.html" title="22.6. Tablespaces">Section 22.6</a> for more information about that.
96    </p><div class="tip"><h3 class="title">Tip</h3><p>
97      Some file systems perform badly when they are almost full, so do
98      not wait until the disk is completely full to take action.
99     </p></div><p>
100     If your system supports per-user disk quotas, then the database
101     will naturally be subject to whatever quota is placed on the user
102     the server runs as.  Exceeding the quota will have the same bad
103     effects as running out of disk space entirely.
104    </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="dynamic-trace.html" title="27.5. Dynamic Tracing">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="monitoring.html" title="Chapter 27. Monitoring Database Activity">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="wal.html" title="Chapter 28. Reliability and the Write-Ahead Log">Next</a></td></tr><tr><td width="40%" align="left" valign="top">27.5. Dynamic Tracing </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"> Chapter 28. Reliability and the Write-Ahead Log</td></tr></table></div></body></html>