mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Get The Size On Disk Of An Index as a Postgres til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1188 TILs and counting..._
|
||||
_1189 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -592,6 +592,7 @@ _1188 TILs and counting..._
|
||||
- [Generate Series Of Numbers](postgres/generate-series-of-numbers.md)
|
||||
- [Generating UUIDs With pgcrypto](postgres/generating-uuids-with-pgcrypto.md)
|
||||
- [Get A Quick Approximate Count Of A Table](postgres/get-a-quick-approximate-count-of-a-table.md)
|
||||
- [Get The Size On Disk of An Index](postgres/get-the-size-on-disk-of-an-index.md)
|
||||
- [Get The Size Of A Database](postgres/get-the-size-of-a-database.md)
|
||||
- [Get The Size Of A Table](postgres/get-the-size-of-a-table.md)
|
||||
- [Get The Size Of An Index](postgres/get-the-size-of-an-index.md)
|
||||
|
||||
29
postgres/get-the-size-on-disk-of-an-index.md
Normal file
29
postgres/get-the-size-on-disk-of-an-index.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Get The Size On Disk Of An Index
|
||||
|
||||
Indexes, when added to the right columns, can provide massive performance gains
|
||||
for certain queries. Indexes aren't free though. It is worth noting that they
|
||||
take up disk space. The amount of disk space they take is generally irrelevant,
|
||||
but it is at least worth being aware of. Especially if you're deal with a
|
||||
massive table.
|
||||
|
||||
You can check the current size of an index on disk with [PostgreSQL's
|
||||
`pg_relation_size`
|
||||
function](https://www.postgresql.org/docs/current/functions-admin.html).
|
||||
|
||||
First, you'll want to look up the name of the index you're curious about.
|
||||
Running `\d table_name` (replacing `table_name` with the name of the table the
|
||||
index is on) will show you everything about the table including its indexes and
|
||||
their names.
|
||||
|
||||
Then run the following query:
|
||||
|
||||
```sql
|
||||
select pg_size_pretty(pg_relation_size('index_users_on_email'));
|
||||
pg_size_pretty
|
||||
----------------
|
||||
41 MB
|
||||
(1 row)
|
||||
```
|
||||
|
||||
This one is pretty small. They can get pretty big though. I've seen some that
|
||||
take up over 1GB on disk.
|
||||
Reference in New Issue
Block a user