|
1 | 1 | <!--
|
2 |
| -$Header: /cvsroot/pgsql/doc/src/sgml/maintenance.sgml,v 1.12 2002/03/06 06:44:31 momjian Exp $ |
| 2 | +$Header: /cvsroot/pgsql/doc/src/sgml/maintenance.sgml,v 1.13 2002/06/13 04:36:50 momjian Exp $ |
3 | 3 | -->
|
4 | 4 |
|
5 | 5 | <chapter id="maintenance">
|
@@ -366,6 +366,92 @@ VACUUM
|
366 | 366 | </sect2>
|
367 | 367 | </sect1>
|
368 | 368 |
|
| 369 | + <sect1 id="diskspace-maintenance"> |
| 370 | + <title>Disk Space Maintenance</title> |
| 371 | + |
| 372 | + <indexterm zone="diskspace-maintenance"> |
| 373 | + <primary>disk space</primary> |
| 374 | + </indexterm> |
| 375 | + |
| 376 | + <para> |
| 377 | + Each table has a primary heap disk file where most of the data is |
| 378 | + stored. To store long column values, there is also a |
| 379 | + <acronym>TOAST</> file associated with the table, named based on the |
| 380 | + table's oid (actually pg_class.relfilenode), and an index on the |
| 381 | + <acronym>TOAST</> table. There also may be indexes associated with |
| 382 | + the base table. |
| 383 | + </para> |
| 384 | + |
| 385 | + <para> |
| 386 | + You can monitor disk space from two places; from inside |
| 387 | + <application>psql</> and from the command line using |
| 388 | + <application>contrib/oid2name</>. Using <application>psql</> you can |
| 389 | + issue queries to see the disk usage for any table: |
| 390 | +<programlisting> |
| 391 | +play=# SELECT relfilenode, relpages |
| 392 | +play-# FROM pg_class |
| 393 | +play-# WHERE relname = 'customer'; |
| 394 | + relfilenode | relpages |
| 395 | +-------------+---------- |
| 396 | + 16806 | 60 |
| 397 | +(1 row) |
| 398 | +</programlisting> |
| 399 | + </para> |
| 400 | + |
| 401 | + <para> |
| 402 | + Each page is typically 8 kilobytes. <literal>relpages</> is only |
| 403 | + updated by <command>VACUUM</> and <command>ANALYZE</>. To show the |
| 404 | + space used by <acronym>TOAST</> tables, use a query based on the heap |
| 405 | + relfilenode: |
| 406 | +<programlisting> |
| 407 | +play=# SELECT relname, relpages |
| 408 | +play-# FROM pg_class |
| 409 | +play-# WHERE relname = 'pg_toast_16806' or |
| 410 | +play-# relname = 'pg_toast_16806_index' |
| 411 | +play-# ORDER BY relname; |
| 412 | + relname | relpages |
| 413 | +----------------------+---------- |
| 414 | + pg_toast_16806 | 0 |
| 415 | + pg_toast_16806_index | 1 |
| 416 | +</programlisting> |
| 417 | + </para> |
| 418 | + |
| 419 | + <para> |
| 420 | + You can easily display index usage too: |
| 421 | +<programlisting> |
| 422 | +play=# SELECT c2.relname, c2.relpages |
| 423 | +play-# FROM pg_class c, pg_class c2, pg_index i |
| 424 | +play-# WHERE c.relname = 'customer' AND |
| 425 | +play-# c.oid = i.indrelid AND |
| 426 | +play-# c2.oid = i.indexrelid |
| 427 | +play-# ORDER BY c2.relname; |
| 428 | + relname | relpages |
| 429 | +----------------------+---------- |
| 430 | + customer_id_indexdex | 26 |
| 431 | +</programlisting> |
| 432 | + </para> |
| 433 | + |
| 434 | + <para> |
| 435 | + It is easy to find your largest files using <application>psql</>: |
| 436 | +<programlisting> |
| 437 | +play=# SELECT relname, relpages |
| 438 | +play-# FROM pg_class |
| 439 | +play-# ORDER BY relpages DESC; |
| 440 | + relname | relpages |
| 441 | +----------------------+---------- |
| 442 | + bigtable | 3290 |
| 443 | + customer | 3144 |
| 444 | +</programlisting> |
| 445 | + </para> |
| 446 | + |
| 447 | + <para> |
| 448 | + You can also use <application>oid2name</> to show disk usage. See |
| 449 | + <filename>README.oid2name</> for examples. It includes a script |
| 450 | + shows disk usage for each database. |
| 451 | + </para> |
| 452 | + </sect1> |
| 453 | + |
| 454 | + |
369 | 455 | <sect1 id="logfile-maintenance">
|
370 | 456 | <title>Log File Maintenance</title>
|
371 | 457 |
|
|
0 commit comments