dataiotech Labs
Back to Performance Guide
[MySQL]RUNBOOKMySQL 8.4 LTS / 8.024 minSenior DBA / SRE

[MySQL] RUNBOOK: InnoDB Buffer Pool and Redo Log Tuning

What shared_buffers is in PostgreSQL, InnoDB Buffer Pool is in MySQL. If the Buffer Pool is small, every query goes to disk. If the Redo Log is small, write operations constantly suffer checkpoint pressure, and the system stutters. In this guide you will learn how to size the Buffer Pool correctly, how to tune the Redo Log for your write load, how to control flush behavior, and how to apply changes safely in production.

Production Incident Scenario

There is a server. 32 GB RAM, 8 CPUs. MySQL installed with default settings. The application team says the system is slow. The DBA looks: `innodb_buffer_pool_size` is 128 MB. So only 128 MB of a 32 GB server is allocated for data cache. Every query goes to disk. Cache hit ratio is 84%. There is also a write problem: Redo Log is 48 MB. During write-heavy hours checkpoint pressure occurs, the system slows down for 30 seconds every 10 minutes. The team suggests scaling up the server. But the problem is not the server, it is the settings. First we need to allocate memory correctly.

Summary

What shared_buffers is in PostgreSQL, InnoDB Buffer Pool is in MySQL. If the Buffer Pool is small, every query goes to disk. If the Redo Log is small, write operations constantly suffer checkpoint pressure, and the system stutters. In this guide you will learn how to size the Buffer Pool correctly, how to tune the Redo Log for your write load, how to control flush behavior, and how to apply changes safely in production.

Scenario

There is a server. 32 GB RAM, 8 CPUs. MySQL installed with default settings. The application team says the system is slow. The DBA looks: innodb_buffer_pool_size is 128 MB. So only 128 MB of a 32 GB server is allocated for data cache. Every query goes to disk. Cache hit ratio is 84%. There is also a write problem: Redo Log is 48 MB. During write-heavy hours checkpoint pressure occurs, the system slows down for 30 seconds every 10 minutes. The team suggests scaling up the server. But the problem is not the server, it is the settings. First we need to allocate memory correctly.

Concept: What Is the Buffer Pool?

The Buffer Pool is InnoDB's data and index cache. When you first read a table, it reads from disk and puts it into the Buffer Pool. When you read the same table a second time, it reads from memory instead of disk. Reading from memory is 100 times faster than reading from disk.

The difference from PostgreSQL is this: In PostgreSQL, OS cache also plays an important role. In MySQL, the Buffer Pool is the main cache. That is why the Buffer Pool ratio in MySQL is higher than the shared_buffers ratio in PostgreSQL. We recommend 25% in PostgreSQL, 70-80% in MySQL.

The Buffer Pool holds 3 things:

  • •Data pages: The actual data of tables.
  • •Index pages: Indexes themselves. Indexes are also stored on disk, cached in memory.
  • •Adaptive Hash Index: A hash structure MySQL automatically builds for frequently accessed index pages.

Step 0: Learn Current Settings and the Server

Before changing anything, note the current state.

sql
SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; SHOW VARIABLES LIKE 'innodb_buffer_pool_instances'; SHOW VARIABLES LIKE 'innodb_redo_log_capacity'; SHOW VARIABLES LIKE 'innodb_flush_method'; SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit'; SHOW VARIABLES LIKE 'innodb_log_buffer_size';

Also learn server info:

bash
free -h nproc

Write these two side by side. For example:

  • •Total RAM: 32 GB
  • •CPU: 8 cores
  • •innodb_buffer_pool_size: 128 MB
  • •innodb_redo_log_capacity: 48 MB
  • •innodb_flush_log_at_trx_commit: 1

If you change settings without this table, you will not know what you fixed.

Step 1: Buffer Pool Size — The Most Important Setting

▸Starting Formula

text
innodb_buffer_pool_size = Total RAM * 70% to 80%

Examples:

Total RAMBuffer Pool
8 GB6 GB
16 GB12 GB
32 GB24 GB
64 GB48 GB
128 GB96 GB

▸Why 70-80%? Why Not 100%?

Because OS, MySQL process, per-connection memory, Redo Log Buffer, and other processes also need memory. If you make the Buffer Pool 100%, no room remains for the OS. The system starts using swap. MySQL using swap runs slower than memory. 70-80% is a safe and efficient balance.

Special case: If the server is dedicated only to MySQL, use 80%. If other applications also run on the server, drop to 70%.

▸Diagnosis: Is the Buffer Pool Enough?

Look at cache hit ratio:

sql
SELECT (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Innodb_buffer_pool_read_requests') AS read_requests, (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Innodb_buffer_pool_reads') AS disk_reads;

Hit ratio formula:

text
Hit Ratio = 1 - (Disk Reads / Total Read Requests)

Easier way, use the sys schema:

sql
SELECT pool_size, hit_rate, pages_total, pages_free FROM sys.innodb_buffer_stats_by_schema;

Interpretation:

  • •Over 99%: Excellent.
  • •97% - 99%: Good.
  • •95% - 97%: Warning, improvement area.
  • •Below 95%: Problem. Either Buffer Pool is small, or queries read unnecessary data.

But do not decide by hit ratio alone. Because hit ratio can be high but queries may still read unnecessary data. Evaluate together with Performance Schema.

Also check Buffer Pool fullness:

sql
SHOW STATUS LIKE 'Innodb_buffer_pool_pages_total'; SHOW STATUS LIKE 'Innodb_buffer_pool_pages_free'; SHOW STATUS LIKE 'Innodb_buffer_pool_pages_dirty';

If pages_free is constantly close to zero, the Buffer Pool is full. Old data must be evicted for new data. Consider increasing size.

▸Change Step — Online Growth Is Possible in MySQL 8.0

Unlike PostgreSQL, in MySQL 8.0 you can grow the Buffer Pool without restart. But shrinking requires restart.

sql
-- Online growth SET GLOBAL innodb_buffer_pool_size = 25769803776;

To make it permanent, write to my.cnf:

ini
[mysqld] innodb_buffer_pool_size = 24G

During online growth the system may slow briefly. Do it in a maintenance window. Unannounced change during daytime is a production incident.

Step 2: Buffer Pool Instances — For Parallelism

If the Buffer Pool is one piece, lock contention occurs on multi-core systems. So the Buffer Pool must be split into pieces.

ini
[mysqld] innodb_buffer_pool_size = 24G innodb_buffer_pool_instances = 8

Rule:

  • •If Buffer Pool is under 1 GB, instances = 1 is enough.
  • •If Buffer Pool is over 8 GB, instances = 8 is recommended.
  • •Each instance must be at least 1 GB. 24 GB / 8 = 3 GB, suitable.

If instance count is too high, each instance stays small and hit ratio drops. If instance count is too low, lock contention increases. 8 is a safe starting point for most systems.

Step 3: Redo Log — The Heart of Write Performance

▸What Is Redo Log?

Redo Log is the log file where write operations are first written. When you do an INSERT or UPDATE, MySQL first writes to Redo Log, then updates the page in the Buffer Pool. If the system crashes, data is recovered from Redo Log. So Redo Log is critical for data safety.

▸What Happens If Redo Log Is Small?

If Redo Log is small, the log constantly fills up. When it fills, MySQL must write dirty pages in the Buffer Pool to disk. This is called checkpoint. During checkpoint the system slows down. During write-heavy hours this repeats constantly. The system stutters.

▸Starting Formula

For MySQL 8.0.30 and above:

text
innodb_redo_log_capacity = 2 GB to 4 GB to start, based on write load

Examples:

Write LoadRedo Log Capacity
Low (mostly read)1 GB
Medium (mixed read + write)2 GB
High (write-heavy)4 GB
Very high (bulk import, heavy write)8 GB

In older MySQL versions innodb_log_file_size and innodb_log_files_in_group were used. In MySQL 8.0.30 and above innodb_redo_log_capacity is used. Do not use the old setting.

▸Diagnosis: Is Redo Log Enough?

Check checkpoint age:

sql
SHOW ENGINE INNODB STATUS\G

Look at the LOG section in the output. The difference between Log sequence number and Last checkpoint is checkpoint age. If the difference is very close to Redo Log capacity, Redo Log is small.

More practical method, measure write amount:

sql
SELECT VARIABLE_VALUE AS value FROM performance_schema.global_status WHERE VARIABLE_NAME IN ('Innodb_os_log_written', 'Innodb_log_waits', 'Innodb_log_write_requests');

If Innodb_log_waits is greater than zero and increasing, there is Redo Log waiting. Grow Redo Log.

▸Change Step

sql
SET GLOBAL innodb_redo_log_capacity = 4294967296;

To make it permanent:

ini
[mysqld] innodb_redo_log_capacity = 4G

Redo Log change can be done online. But during large increases the system may slow briefly. Do it in a maintenance window.

Step 4: Flush Settings — Durability vs Speed Balance

▸innodb_flush_log_at_trx_commit

This setting determines when a write is written to disk. It has 3 values.

Value 1 — Safest, Default:

ini
innodb_flush_log_at_trx_commit = 1

On every transaction commit, Redo Log is written to disk. Even if the system crashes, data is not lost. Mandatory for finance, payment, order systems.

Value 2 — Balanced:

ini
innodb_flush_log_at_trx_commit = 2

On every transaction commit, Redo Log is written to OS cache. Disk write happens once per second. If MySQL crashes data is not lost, but if OS crashes last 1 second of data may be lost. Faster.

Value 0 — Fastest, Riskiest:

ini
innodb_flush_log_at_trx_commit = 0

Redo Log is written once per second. If MySQL crashes, last 1 second of data may be lost. Used only for log, analytics, temporary data where loss is acceptable. Do not use in production order systems.

Practical advice: Stay at default 1. If you have a performance problem, first fix the query, then grow the Buffer Pool. Dropping flush_log_at_trx_commit to 0 hides the problem but increases data loss risk.

▸innodb_flush_method

Recommended value on Linux:

ini
[mysqld] innodb_flush_method = O_DIRECT

O_DIRECT skips OS cache and writes directly to disk. It prevents double caching. Because data is already cached in the Buffer Pool. No need to keep it a second time in OS cache.

▸innodb_log_buffer_size

Redo Log Buffer is the memory area where data waits before being written to Redo Log.

ini
[mysqld] innodb_log_buffer_size = 64M

For small systems 16 MB, for large systems 64 MB is enough. No need to make it very large. Because Redo Log Buffer is written to disk once per second. Large buffer means large loss risk.

Step 5: Full Example — For a 32 GB Server

ini
[mysqld] # Memory innodb_buffer_pool_size = 24G innodb_buffer_pool_instances = 8 # Redo Log innodb_redo_log_capacity = 4G innodb_log_buffer_size = 64M # Flush innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT # Other innodb_flush_neighbors = 0

▸For a 16 GB Server

ini
innodb_buffer_pool_size = 12G innodb_buffer_pool_instances = 8 innodb_redo_log_capacity = 2G innodb_log_buffer_size = 32M innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT

▸For a 64 GB Server

ini
innodb_buffer_pool_size = 48G innodb_buffer_pool_instances = 16 innodb_redo_log_capacity = 8G innodb_log_buffer_size = 64M innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT

Verification: Did the Change Work?

Compare these 4 metrics before and after the change:

▸1. Cache Hit Ratio

sql
SELECT VARIABLE_NAME, VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME LIKE 'Innodb_buffer_pool_read%';

Target: Over 97%, ideal over 99%.

▸2. Redo Log Waits

sql
SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Innodb_log_waits';

Target: 0 or not increasing.

▸3. Most Expensive Queries

sql
SELECT LEFT(DIGEST_TEXT, 120), COUNT_STAR, ROUND(SUM_TIMER_WAIT / 1000000000000, 2) AS total_time FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DESC LIMIT 10;

Target: Average and total time should drop.

▸4. Disk I/O and Checkpoint

sql
SHOW ENGINE INNODB STATUS\G

Target: Did checkpoint pressure decrease, is disk write regular?

▸Verification Schedule

  • •1 hour after change: Hit ratio and log waits check
  • •24 hours after change: Most expensive queries and Buffer Pool fullness check
  • •7 days after change: Weekly trend comparison

A change is not accepted as permanent without 7 days of monitoring.

7 Common Mistakes

First mistake: Making the Buffer Pool 100%. No room remains for the OS, the system uses swap.

Second mistake: Applying the PostgreSQL formula to MySQL. In PostgreSQL 25%, in MySQL 70-80%. The two engines have different memory models.

Third mistake: Leaving Redo Log small. Checkpoint pressure makes the system stutter.

Fourth mistake: Hiding a bad query by setting flush_log_at_trx_commit to 0. Data loss risk increases.

Fifth mistake: Changing all settings at once. One change, one measurement.

Sixth mistake: Leaving innodb_flush_method at default. On Linux it must be O_DIRECT.

Seventh mistake: Doing online growth without a maintenance window. Even if online, large changes are done in a maintenance window.

Checklist

  • Total RAM, CPU, and write load noted
  • Current Buffer Pool and Redo Log values recorded
  • Cache hit ratio measured
  • Redo Log waits measured
  • Buffer Pool set to RAM * 70-80%
  • Buffer Pool Instances set to 8
  • Redo Log Capacity set by write load
  • flush_log_at_trx_commit = 1 verified
  • flush_method = O_DIRECT verified
  • my.cnf made permanent
  • Hit ratio measured again after 1 hour
  • Most expensive queries measured again after 24 hours
  • Log waits checked to be zero
  • Useless change reverted

Conclusion

In MySQL, memory tuning is cheaper and more effective than scaling up the server. A correctly allocated 32 GB runs faster than a wrongly configured 64 GB. First measure, then change one setting, then measure again. If you do not break this loop, your memory settings will always fit your system's real load.

Next cluster: InnoDB Purge and Undo Tuning. Because after solving the Buffer Pool problem, next is to understand the Purge mechanism, the MySQL counterpart of Vacuum in PostgreSQL.

Related Articles

  • •Pillar: Performance Guide — Performance & Query Optimization
  • •Cluster: [MySQL] Finding the 20 Most Expensive Queries with Performance Schema
  • •Cluster: [PostgreSQL] Memory Tuning — shared_buffers, work_mem, effective_cache_size
  • •Cluster: [PostgreSQL] Vacuum / Analyze — Autovacuum Tuning
  • •Next: [MySQL] InnoDB Purge and Undo Tuning
Operational Checklist

Verify each operational safety check before completing the task: