File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
1212
13- _ 1188 TILs and counting..._
13+ _ 1189 TILs and counting..._
1414
1515---
1616
@@ -592,6 +592,7 @@ _1188 TILs and counting..._
592592- [ Generate Series Of Numbers] ( postgres/generate-series-of-numbers.md )
593593- [ Generating UUIDs With pgcrypto] ( postgres/generating-uuids-with-pgcrypto.md )
594594- [ Get A Quick Approximate Count Of A Table] ( postgres/get-a-quick-approximate-count-of-a-table.md )
595+ - [ Get The Size On Disk of An Index] ( postgres/get-the-size-on-disk-of-an-index.md )
595596- [ Get The Size Of A Database] ( postgres/get-the-size-of-a-database.md )
596597- [ Get The Size Of A Table] ( postgres/get-the-size-of-a-table.md )
597598- [ Get The Size Of An Index] ( postgres/get-the-size-of-an-index.md )
Original file line number Diff line number Diff line change 1+ # Get The Size On Disk Of An Index
2+
3+ Indexes, when added to the right columns, can provide massive performance gains
4+ for certain queries. Indexes aren't free though. It is worth noting that they
5+ take up disk space. The amount of disk space they take is generally irrelevant,
6+ but it is at least worth being aware of. Especially if you're deal with a
7+ massive table.
8+
9+ You can check the current size of an index on disk with [ PostgreSQL's
10+ ` pg_relation_size `
11+ function] ( https://www.postgresql.org/docs/current/functions-admin.html ) .
12+
13+ First, you'll want to look up the name of the index you're curious about.
14+ Running ` \d table_name ` (replacing ` table_name ` with the name of the table the
15+ index is on) will show you everything about the table including its indexes and
16+ their names.
17+
18+ Then run the following query:
19+
20+ ``` sql
21+ select pg_size_pretty(pg_relation_size(' index_users_on_email' ));
22+ pg_size_pretty
23+ -- --------------
24+ 41 MB
25+ (1 row)
26+ ```
27+
28+ This one is pretty small. They can get pretty big though. I've seen some that
29+ take up over 1GB on disk.
You can’t perform that action at this time.
0 commit comments