I read here that
You need buffer pool a bit (say 10%) larger than your data (total size of Innodb TableSpaces)
On the other hand I've read elswher that innodb_buffer_pool_size must be up to %80 of the memory. So I'm really confused how should I choose the best size for the pool. My database size is about 6GB and my total memory 64GB. Also I'm wondering if I increase the buffer pool size, I should shrink the number of maximum connections to make room for extra buffer, or these parameters are independent. Thanks
2 Answers 2
If you go strictly by that rule of accommodating an addition 10%, here is my suggestion:
SELECT CONCAT(CEILING(RIBPS/POWER(1024,pw)),SUBSTR(' KMGT',pw+1,1))
Recommended_InnoDB_Buffer_Pool_Size FROM
(
SELECT RIBPS,FLOOR(LOG(RIBPS)/LOG(1024)) pw
FROM
(
SELECT SUM(data_length+index_length)*1.1*growth RIBPS
FROM information_schema.tables AAA,
(SELECT 1 growth) BBB
WHERE ENGINE='InnoDB'
) AA
) A;
This will produce exactly what you need to set innodb_buffer_pool_size in /etc/my.cnf
. If you want to account for 25% increase in data and indexes over time, please change (SELECT 1 growth) BBB
to (SELECT 1.25 growth) BBB
Recently, I answered another question like this in the DBA StackExchange.
-
So, are you suggesting that having a small margin over the overal database size is the way to go? ThanksShirko– Shirko2012年10月23日 00:30:25 +00:00Commented Oct 23, 2012 at 0:30
-
If you want a bigger margin to adjust for growth, just set
growth
to whatever value needed.RolandoMySQLDBA– RolandoMySQLDBA2012年10月23日 02:48:42 +00:00Commented Oct 23, 2012 at 2:48 -
1Error Code: 1140. In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'BBB.growth'; this is incompatible with sql_mode=only_full_group_bythe_nuts– the_nuts2017年01月17日 15:47:17 +00:00Commented Jan 17, 2017 at 15:47
-
I think you should add GROUP BY growththe_nuts– the_nuts2017年01月17日 15:47:41 +00:00Commented Jan 17, 2017 at 15:47
-
That
SELECT
may give a desired size for the buffer_pool, but it must be capped by some percentage of RAM.Rick James– Rick James2020年10月29日 21:45:03 +00:00Commented Oct 29, 2020 at 21:45
I don't like the sound of that advice at all. If anything, the general rule of thumb should be active data set + a little something to spare, certainly not the entire database. Keep in mind that, at least in a sense, caching is a trade-off between I/O and CPU resources.
SHOW ENGINE INNODB STATUS
will give you some essential information about the buffer pool(s), including free buffers and more importantly the buffer pool hit rate. In my opinion, you generally want to keep the hit ratio close to 99%.
If you are interested in learning the fundamentals of MySQL performance, I recommend the book High Performance MySQL by Baron Schwartz, Peter Zaitsev and Vadim Tkachenko. You can read it online on Safaribooks, I do believe they still offer a free trial. The 2012 edition is very much up to date.
max_connections
is probably not necessary. 80% (51G) is a reasonable value for 64GB of RAM. 80% is too big for, say, 4GB of RAM; even 70% is tight.