Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Adds TOAST size script #6

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,65 @@ with the Postgres client of your choice.
## Scripts

#### [`active_autovacuums.sql`](sql/active_autovacuums.sql) (admin permission)
* **Returns all running autovacuums operations**
* **Returns all running autovacuums operations.**

#### [`analyze_stats.sql`](sql/analyze_stats.sql) (read permission)
* **Returns autovacuum analyze stats for each table**
* **Returns autovacuum analyze stats for each table.**

#### [`bloat.sql`](sql/bloat.sql) (read permission)
* **Returns the approximate bloat from dead tuples for each table**
* This bloat can also be index bloat
* **Returns the approximate bloat from dead tuples for each table.**
* This bloat can also be index bloat.

#### [`buffer_cache_usage.sql`](sql/buffer_cache_usage.sql) (admin permission)
* **Returns the distribution of shared buffers used for each table**
* *Requires the [pg_buffercache](https://www.postgresql.org/docs/current/pgbuffercache.html) extension*
* **Returns the distribution of shared buffers used for each table.**
* *Requires the [pg_buffercache](https://www.postgresql.org/docs/current/pgbuffercache.html) extension.*
* Includes the total bytes of a table in shared buffers, the percentage of
shared buffers a table is using, and the percentage of a table the exists
in shared buffers
in shared buffers.

#### [`cache_hit_rate.sql`](sql/cache_hit_rate.sql) (read permission)
* **Returns the cache hit rate for indices and tables**
* **Returns the cache hit rate for indices and tables.**
* This is the rate of queries that only hit in-memory shared buffers rather
than having to fetch from disk
than having to fetch from disk.
* Note that a queries that are cache misses in Postgres's shared buffers may
still hit the in-memory OS page cache, so a miss not technically go all the
way to the disk
* Both of these rates should be 99+% ideally
way to the disk.
* Both of these rates should be 99+% ideally.

#### [`index_hit_rate.sql`](sql/index_hit_rate.sql) (read permission)
* **Returns the index hit rate for each table**
* **Returns the index hit rate for each table.**
* This rate represents the percentage of queries that utilize 1 or more indices
when querying a table
* These rates should be 99+% ideally
when querying a table.
* These rates should be 99+% ideally.

#### [`index_size.sql`](sql/index_size.sql) (read permission)
* **Returns the size of each index in bytes**
* **Returns the size of each index in bytes.**

#### [`reset_stats.sql`](sql/reset_stats.sql) (admin permission)
* **Resets pg_stats statistics tables**
* **Resets pg_stats statistics tables.**

#### [`table_settings.sql`](sql/table_settings.sql) (read permission)
* **Returns the table-specific settings of each table.**

#### [`table_size.sql`](sql/table_size.sql) (read permission)
* **Returns the size of each table in bytes**
* Does not include size of the tables' indices
* **Returns the size of each table in bytes.**
* Does not include size of the tables' indices.

#### [`table_size_with_indices.sql`](sql/table_size_with_indices.sql) (read permission)
* **Returns size of each table in bytes including all indices**
* **Returns size of each table in bytes including all indices.**

#### [`toast_size.sql`](sql/toast_size.sql) (read permission)
* **Returns total size of all
[TOAST](https://www.postgresql.org/docs/current/storage-toast.html) data in
each table in bytes.**

#### [`unused_indices.sql`](sql/unused_indices.sql) (read permission)
* **Returns indices that are rarely used**
* **Returns indices that are rarely used.**
* Note that sometimes the query optimizer will elect to avoid using indices for
tables with a very small number of rows because it can be more efficient
tables with a very small number of rows because it can be more efficient.

#### [`vacuum_stats.sql`](sql/vacuum_stats.sql) (read permission)
* **Returns autovacuum stats for each table**
* **Returns autovacuum stats for each table.**

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion sql/table_size.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT c.relname AS name,
pg_size_pretty(pg_table_size(c.oid)) AS size
FROM pg_class c
LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
AND n.nspname !~ '^pg_toast'
AND c.relkind='r'
Expand Down
8 changes: 8 additions & 0 deletions sql/toast_size.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT c.relname AS name,
pg_size_pretty(pg_total_relation_size(reltoastrelid)) as toast_size
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
AND n.nspname !~ '^pg_toast'
AND c.relkind = 'r'
ORDER BY pg_total_relation_size(reltoastrelid) DESC NULLS LAST;