Skip to content

Commit 976c65e

Browse files
committed
Add Get The Size Of A Table as a postgres til
1 parent d1a295a commit 976c65e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ _319 TILs and counting..._
152152
- [Generate A UUID](postgres/generate-a-uuid.md)
153153
- [Generate Series Of Numbers](postgres/generate-series-of-numbers.md)
154154
- [Get The Size Of A Database](postgres/get-the-size-of-a-database.md)
155+
- [Get The Size Of A Table](postgres/get-the-size-of-a-table.md)
155156
- [Getting A Slice Of An Array](postgres/getting-a-slice-of-an-array.md)
156157
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
157158
- [Integers In Postgres](postgres/integers-in-postgres.md)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Get The Size Of A Table
2+
3+
In [Get The Size Of A Database](get-the-size-of-a-database.md), I showed a
4+
PostgreSQL administrative function, `pg_database_size()`, that gets the size
5+
of a given database. With the `pg_relation_size()` function, we can get the
6+
size of a given table. For instance, if we'd like to see the size of the
7+
`reservations` table, we can executing the following query:
8+
9+
```sql
10+
> select pg_relation_size('reservations');
11+
pg_relation_size
12+
------------------
13+
1531904
14+
```
15+
16+
This gives us the size of the `reservations` table in bytes. As you might
17+
expect, the referenced table needs to be part of the connected database and
18+
on the search path.
19+
20+
See [the Postgres docs](http://www.postgresql.org/docs/current/static/functions-admin.html) for more details.

0 commit comments

Comments
 (0)