From 976c65e750fe9a31f48ceca0a792ab5e6e079ebf Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 2 Feb 2016 21:09:55 -0600 Subject: [PATCH] Add Get The Size Of A Table as a postgres til --- README.md | 1 + postgres/get-the-size-of-a-table.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 postgres/get-the-size-of-a-table.md diff --git a/README.md b/README.md index 31f2f2a..f5797cc 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ _319 TILs and counting..._ - [Generate A UUID](postgres/generate-a-uuid.md) - [Generate Series Of Numbers](postgres/generate-series-of-numbers.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) - [Getting A Slice Of An Array](postgres/getting-a-slice-of-an-array.md) - [Insert Just The Defaults](postgres/insert-just-the-defaults.md) - [Integers In Postgres](postgres/integers-in-postgres.md) diff --git a/postgres/get-the-size-of-a-table.md b/postgres/get-the-size-of-a-table.md new file mode 100644 index 0000000..7ebb138 --- /dev/null +++ b/postgres/get-the-size-of-a-table.md @@ -0,0 +1,20 @@ +# Get The Size Of A Table + +In [Get The Size Of A Database](get-the-size-of-a-database.md), I showed a +PostgreSQL administrative function, `pg_database_size()`, that gets the size +of a given database. With the `pg_relation_size()` function, we can get the +size of a given table. For instance, if we'd like to see the size of the +`reservations` table, we can executing the following query: + +```sql +> select pg_relation_size('reservations'); + pg_relation_size +------------------ + 1531904 +``` + +This gives us the size of the `reservations` table in bytes. As you might +expect, the referenced table needs to be part of the connected database and +on the search path. + +See [the Postgres docs](http://www.postgresql.org/docs/current/static/functions-admin.html) for more details.