Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcef30c6

Browse files
committed
Improve README with mention of new functions.
1 parent6bb0d54 commitcef30c6

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

‎contrib/dbsize/README.dbsize

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
1-
This module containstwo functions that report the size of a given
2-
databaseor relation. E.g.,
1+
This module containsseveral functions that report the size of a given
2+
databaseobject:
33

4-
SELECT database_size('template1');
5-
SELECT relation_size('pg_class');
4+
int8 database_size(name)
5+
int8 relation_size(text)
66

7-
These functions report the actual file system space. Thus, users can
8-
avoid digging through the details of the database directories.
7+
int8 pg_database_size(oid)
8+
int8 pg_tablespace_size(oid)
9+
int8 pg_relation_size(oid)
910

10-
Copy this directory to contrib/dbsize in your PostgreSQL source tree.
11-
Then just run make; make install. Finally, load the functions into any
12-
database using dbsize.sql.
11+
text pg_size_pretty(int8)
12+
13+
The first two functions:
14+
15+
SELECT database_size('template1');
16+
SELECT relation_size('pg_class');
17+
18+
take the name of the object, and support databases and tables. Please
19+
note that relation_size() only reports table file usage and not the
20+
space used by indexes and toast tables.
21+
22+
Functions using oids are:
23+
24+
SELECT pg_database_size(1); -- template1 database
25+
SELECT pg_tablespace_size(1663); -- pg_default tablespace
26+
SELECT pg_relation_size(1259); -- pg_class table size
27+
28+
pg_relation_size() will report the size of the table, index and toast
29+
table OIDs, but they must be requested individually. To obtain the total
30+
size of a table including all helper files you'd have to do something
31+
like:
32+
33+
XXX This query does not work, syntax error XXX
34+
35+
SELECT pg_relation_size(cl.oid) AS tablesize,
36+
CASE WHEN reltoastrelid=0 THEN 0
37+
ELSE pg_relation_size(reltoastrelid) END AS toastsize,
38+
SUM(pg_relation_size(indexrelid)) AS indexsize,
39+
pg_size_pretty(pg_relation_size(cl.oid)
40+
+ pg_relation_size(reltoastrelid)
41+
+ SUM(pg_relation_size(indexrelid))::int8)
42+
AS totalsize
43+
FROM pg_class cl
44+
JOIN pg_index ON cl.oid=indrelid
45+
WHERE relname = 'pg_rewrite'
46+
GROUP BY 1,2
47+
48+
This sample query utilizes the helper function pg_size_pretty(int8),
49+
which formats the number of bytes into a convenient string using KB, MB,
50+
GB. It is also contained in this module.
51+
52+
To install, just run make; make install. Finally, load the functions
53+
into any database using dbsize.sql.
1354

14-
When computing the size of a table, it does not include TOAST or index
15-
disk space.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp