summaryrefslogtreecommitdiffstats
path: root/health/guides/postgres/postgres_table_toast_cache_io_ratio.md
blob: c33a2373c53d0e71392ca4a6ea303c5618c0f4a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
### Understand the alert

This alert monitors the TOAST hit ratio (i.e., cached I/O efficiency) of a specific table in a PostgreSQL database. If the hit ratio is low, it indicates that the database is performing more disk I/O operations than needed for the table, which may cause performance issues.

### What is TOAST?

TOAST (The Oversized-Attribute Storage Technique) is a mechanism in PostgreSQL to efficiently store large data items. It allows you to store large values (such as text or binary data) in a separate table, improving the overall performance of the database.

### What does the hit ratio mean?

The hit ratio is the percentage of cache hits (successful reads from the cache) compared to total cache requests (hits + misses). A high hit ratio indicates that the data frequently needed is stored in the cache, resulting in fewer disk I/O operations and better performance.

### Troubleshoot the alert

1. Verify if the alert is accurate by checking the TOAST hit ratio in the affected PostgreSQL system. You can use the following query to retrieve the hit ratio of a specific table:

   ```sql
   SELECT CASE
       WHEN blks_hit + blks_read = 0 THEN 0
       ELSE 100 * blks_hit / (blks_hit + blks_read)
   END as cache_hit_ratio
   FROM pg_statio_user_tables
   WHERE schemaname = 'your_schema' AND relname = 'your_table';
   ```

   Replace `your_schema` and `your_table` with the appropriate values.

2. Examine the table's indexes, and consider creating new indexes to improve query performance. Be cautious when creating indexes, as too many can negatively impact performance.

3. Analyze the table's read and write patterns to determine if you need to adjust the cache settings, such as increasing the `shared_buffers` configuration value.

4. Inspect the application's queries to see if any can be optimized to improve performance. For example, use EXPLAIN ANALYZE to determine if the queries are using indexes effectively.

5. Monitor overall PostgreSQL performance with tools like pg_stat_statements or pg_stat_activity to identify potential bottlenecks and areas for improvement.

### Useful resources

1. [PostgreSQL TOAST Overview](https://www.postgresql.org/docs/current/storage-toast.html)
2. [Tuning Your PostgreSQL Server](https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server)