File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ _321 TILs and counting..._
164164- [ List Database Users] ( postgres/list-database-users.md )
165165- [ Max Identifier Length Is 63 Bytes] ( postgres/max-identifier-length-is-63-bytes.md )
166166- [ pg Prefix Is Reserved For System Schemas] ( postgres/pg-prefix-is-reserved-for-system-schemas.md )
167+ - [ Pretty Print Data Sizes] ( postgres/pretty-print-data-sizes.md )
167168- [ Restart A Sequence] ( postgres/restart-a-sequence.md )
168169- [ Restarting Sequences When Truncating Tables] ( postgres/restarting-sequences-when-truncating-tables.md )
169170- [ Send A Command To psql] ( postgres/send-a-command-to-psql.md )
Original file line number Diff line number Diff line change 1+ # Pretty Print Data Sizes
2+
3+ Use the ` pg_size_pretty() ` function to pretty print the sizes of data. Given
4+ a ` bigint ` , it will determine the most human-readable format with which to
5+ print the value:
6+
7+ ``` sql
8+ > select pg_size_pretty(1234 ::bigint );
9+ pg_size_pretty
10+ -- --------------
11+ 1234 bytes
12+
13+ > select pg_size_pretty(123456 ::bigint );
14+ pg_size_pretty
15+ -- --------------
16+ 121 kB
17+
18+ > select pg_size_pretty(1234567899 ::bigint );
19+ pg_size_pretty
20+ -- --------------
21+ 1177 MB
22+
23+ > select pg_size_pretty(12345678999 ::bigint );
24+ pg_size_pretty
25+ -- --------------
26+ 11 GB
27+ ```
28+
29+ This function is particularly useful when used with the
30+ [ ` pg_database_size() ` ] ( get-the-size-of-a-database.md ) and
31+ [ ` pg_relation_size() ` ] ( get-the-size-of-a-table.md ) functions.
32+
33+ ``` sql
34+ > select pg_size_pretty(pg_database_size(' hr_hotels' ));
35+ pg_size_pretty
36+ -- --------------
37+ 12 MB
38+ ```
You can’t perform that action at this time.
0 commit comments