MySQL 8.4 innodb_buffer_pool_size and innodb_redo_log_capacity
Resize MySQL 8.4 innodb_buffer_pool_size (128MB) and redo capacity online. Check disk reads, change with SET PERSIST, roll back with RESET PERSIST.
MySQL 8.4 defaults to a 128MB buffer pool and 100MB of redo log, which is usually small for a dedicated server. Both can be changed while the server runs. First check Innodb_buffer_pool_reads (reads that went to disk) and Innodb_buffer_pool_wait_free to see whether the pool is short, then size it from the official starting point (up to about 80% of RAM on a dedicated server) minus what other processes need. Read step 5 before using innodb_dedicated_server in a container.
[1] Check the current values.
$ mysql -uroot -e "SELECT @@innodb_buffer_pool_size, @@innodb_buffer_pool_chunk_size, @@innodb_buffer_pool_instances, @@innodb_redo_log_capacity, @@innodb_dedicated_server\G"*************************** 1. row *************************** @@innodb_buffer_pool_size: 134217728@@innodb_buffer_pool_chunk_size: 134217728 @@innodb_buffer_pool_instances: 1 @@innodb_redo_log_capacity: 104857600 @@innodb_dedicated_server: 0| Variable | 8.4 default | Change at runtime |
|---|---|---|
innodb_buffer_pool_size | 134217728 (128MB) | Yes |
innodb_buffer_pool_chunk_size | 128MB | No (startup only) |
innodb_buffer_pool_instances | 1 when the pool is 1GiB or less | No |
innodb_redo_log_capacity | 104857600 (100MB) | Yes |
innodb_dedicated_server | OFF | No |
[2] Check whether the pool is short. read_requests counts logical reads; reads counts reads that missed the pool and went to disk.
$ mysql -uroot -e "SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_buffer_pool_read_requests','Innodb_buffer_pool_reads','Innodb_buffer_pool_pages_free','Innodb_buffer_pool_pages_total','Innodb_buffer_pool_wait_free')"Variable_name ValueInnodb_buffer_pool_pages_free 6197Innodb_buffer_pool_pages_total 8192Innodb_buffer_pool_read_requests 409151Innodb_buffer_pool_reads 1051Innodb_buffer_pool_wait_free 0| Watch | Sign the pool is short |
|---|---|
Innodb_buffer_pool_reads ÷ read_requests | The ratio rises above normal, even after warm-up |
Innodb_buffer_pool_pages_free | Stays near 0 |
Innodb_buffer_pool_wait_free | Not 0: queries waited for a free page |
These counters accumulate from startup, so sample twice at an interval and compare. The test server above has 6197 of 8192 pages free, so there is no reason to grow it. The same data is in the BUFFER POOL AND MEMORY section of SHOW ENGINE INNODB STATUS:
$ mysql -uroot -e 'SHOW ENGINE INNODB STATUS\G' | sed -n '/^BUFFER POOL AND MEMORY/,/^LRU len/p'BUFFER POOL AND MEMORY----------------------…Buffer pool size 8192Free buffers 6197Database pages 1995…Buffer pool hit rate 998 / 1000, young-making rate 0 / 1000 not 0 / 1000…[3] Resize it online. The value is rounded to a multiple of chunk_size × instances, so 200MB becomes 256MB.
$ mysql -uroot -e 'SET GLOBAL innodb_buffer_pool_size = 200*1024*1024; SHOW WARNINGS;'Level Code MessageWarning 1292 Truncated incorrect innodb_buffer_pool_size value: '209715200'$ mysql -uroot -e "SELECT @@innodb_buffer_pool_size; SHOW STATUS WHERE Variable_name LIKE 'Innodb_buffer_pool_resize_status%'"@@innodb_buffer_pool_size268435456Variable_name ValueInnodb_buffer_pool_resize_status Completed resizing buffer pool at 261027 11:00:47.Innodb_buffer_pool_resize_status_code 0Innodb_buffer_pool_resize_status_progress 100The Truncated incorrect warning is not an error; the rounded value was applied. Resizing proceeds in chunks, and shrinking goes through a page-withdrawal stage (Withdrawing Blocks). Track it with …_resize_status_code (0 = no resize in progress, 7 = failed). The docs list a global-lock stage during resizing, so avoid busy hours.
[4] To keep it across restarts use SET PERSIST. To roll back, remove it with RESET PERSIST and set the old value again; RESET PERSIST alone does not change the running value.
$ mysql -uroot -e 'SET PERSIST innodb_buffer_pool_size = 256*1024*1024'$ mysql -uroot -e "SELECT VARIABLE_NAME, VARIABLE_VALUE FROM performance_schema.persisted_variables WHERE VARIABLE_NAME = 'innodb_buffer_pool_size'"VARIABLE_NAME VARIABLE_VALUEinnodb_buffer_pool_size 268435456$ mysql -uroot -e 'RESET PERSIST innodb_buffer_pool_size; SET GLOBAL innodb_buffer_pool_size = 134217728;'$ mysql -uroot -e "SELECT @@innodb_buffer_pool_size; SELECT COUNT(*) AS persisted FROM performance_schema.persisted_variables WHERE VARIABLE_NAME = 'innodb_buffer_pool_size'"@@innodb_buffer_pool_size134217728persisted0SET PERSIST writes mysqld-auto.cnf in the data directory, which is read after all other option files. If an edit to my.cnf does not take effect, check for a leftover value there first.
[5] Be careful with innodb_dedicated_server in containers. In 8.4 it sets the buffer pool (50% of detected memory for 1–4GB, 75% above 4GB) and redo capacity (logical CPUs ÷ 2 GB, max 16GB). On 8.4.13 the bare --innodb-dedicated-server form shown in the docs did not start:
[ERROR] [MY-000071] [Server] /usr/sbin/mysqld: option '--innodb-dedicated-server' requires an argument.With --innodb-dedicated-server=ON in a container limited to 1GB, it sized from the whole machine's memory, not the container limit:
$ mysql -uroot -e 'SELECT @@innodb_dedicated_server, @@innodb_buffer_pool_size, @@innodb_redo_log_capacity\G'*************************** 1. row *************************** @@innodb_dedicated_server: 1 @@innodb_buffer_pool_size: 5637144576@@innodb_redo_log_capacity: 2147483648$ nproc; grep MemTotal /proc/meminfo; cat /sys/fs/cgroup/memory.max4MemTotal: 8003512 kB1073741824A 5.25GB buffer pool in a 1GB container, and 2GB of redo from 4 visible CPUs rather than --cpus 1. Right after startup the container already used 836.7MiB of 1GiB; as data fills the pool it will hit the memory limit. In containers set both values explicitly instead. Explicit values win over this option (the startup log warns that the option was ignored for them).
[6] Size the redo log from how far checkpoints lag. current_lsn − checkpoint_lsn is the checkpoint age; if it gets close to innodb_redo_log_capacity at peak, grow the capacity.
$ mysql -uroot -e "SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_redo_log_capacity_resized','Innodb_redo_log_resize_status','Innodb_redo_log_current_lsn','Innodb_redo_log_checkpoint_lsn','Innodb_redo_log_logical_size')"Variable_name ValueInnodb_redo_log_capacity_resized 104857600Innodb_redo_log_checkpoint_lsn 43256493Innodb_redo_log_current_lsn 43256493Innodb_redo_log_logical_size 512Innodb_redo_log_resize_status OK$ mysql -uroot -e 'SET GLOBAL innodb_redo_log_capacity = 200*1024*1024'$ mysql -uroot -e "SELECT @@innodb_redo_log_capacity; SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_redo_log_capacity_resized','Innodb_redo_log_resize_status')"@@innodb_redo_log_capacity209715200Variable_name ValueInnodb_redo_log_capacity_resized 209715200Innodb_redo_log_resize_status OKRedo files live in #innodb_redo under the data directory as #ib_redoN, and InnoDB tries to keep 32 of them. The new limit can take a while to apply fully, so watch until Innodb_redo_log_capacity_resized shows the new value. Roll back with SET GLOBAL innodb_redo_log_capacity = 104857600, plus RESET PERSIST innodb_redo_log_capacity if you persisted it. innodb_redo_log_capacity replaces innodb_log_file_size and innodb_log_files_in_group; remove those from old my.cnf files.
Official references: Configuring InnoDB Buffer Pool Size · Buffer Pool — 80%, SHOW ENGINE INNODB STATUS · Automatic Configuration for a Dedicated MySQL Server · Redo Log · InnoDB Startup Options and System Variables · Persisted System Variables
Analyze your MySQL slow log log in the browser ↗ — nothing is uploaded.