{"id":443,"date":"2026-06-17T07:00:58","date_gmt":"2026-06-17T07:00:58","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=443"},"modified":"2026-09-21T22:04:38","modified_gmt":"2026-09-21T22:04:38","slug":"vps-swap-space-configure-optimize-linux-2","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/","title":{"rendered":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">MySQL&#8217;s default configuration is written for a machine with several gigabytes of headroom. On a 1 GB VPS that assumption is fatal: the server starts happily, then dies hours later when real connections arrive and the per-connection buffers multiply. This is not a general tuning guide \u2014 it is a memory ledger. Every setting below is chosen against a fixed budget, and the arithmetic is shown so you can redo it when your workload changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Start with the ledger, not the config file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL memory splits into two kinds. Global buffers are allocated once at startup and never grow. Per-connection buffers are allocated per session, and \u2014 this is the part that surprises people \u2014 some of them are allocated <em>per query execution<\/em>, and <code>max_connections<\/code> is a ceiling on how many can exist at once. Budget the globals first, then divide the remainder by a realistic connection count.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n  @@innodb_buffer_pool_size\/1024\/1024      AS buffer_pool_mb,\n  @@innodb_log_buffer_size\/1024\/1024       AS log_buffer_mb,\n  @@key_buffer_size\/1024\/1024              AS key_buffer_mb,\n  @@tmp_table_size\/1024\/1024               AS tmp_table_mb,\n  @@max_connections,\n  (@@sort_buffer_size + @@read_buffer_size + @@read_rnd_buffer_size\n   + @@join_buffer_size + @@binlog_cache_size)\/1024\/1024 AS per_conn_mb\n\\G<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The most useful derived number is the worst case: globals plus <code>per_conn_mb * max_connections<\/code>. On a default 8.0 install that lands around 4 GB on a machine with 1 GB. The server is not over-committed \u2014 it is running a plan that only works if few users connect at once. <a href=\"https:\/\/virtualserversvps.com\/\">Our VPS comparison page<\/a> shows how much RAM each tier actually guarantees, which is the input to this calculation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A 1 GB budget you can defend<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Assume Nginx and PHP-FPM take 300 MB, the OS and page cache want at least 150 MB, and MySQL gets the rest \u2014 about 550 MB. Here is how to spend it.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Setting<\/th><th>Default<\/th><th>1 GB target<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td><code>innodb_buffer_pool_size<\/code><\/td><td>128M<\/td><td>256M<\/td><td>The only setting that reliably improves reads; 256M at 4\u20138 instances is the sweet spot<\/td><\/tr><tr><td><code>innodb_log_file_size<\/code><\/td><td>48M<\/td><td>64M<\/td><td>Larger files reduce checkpoint pressure without much memory cost<\/td><\/tr><tr><td><code>innodb_log_buffer_size<\/code><\/td><td>16M<\/td><td>8M<\/td><td>Flushed on every commit for transactional workloads<\/td><\/tr><tr><td><code>key_buffer_size<\/code><\/td><td>8M<\/td><td>16M<\/td><td>Only if MyISAM tables remain; otherwise leave small<\/td><\/tr><tr><td><code>tmp_table_size<\/code> \/ <code>max_heap_table_size<\/code><\/td><td>16M<\/td><td>32M<\/td><td>Must match each other or the smaller wins silently<\/td><\/tr><tr><td><code>max_connections<\/code><\/td><td>151<\/td><td>30<\/td><td>Divide the remainder by per-connection cost<\/td><\/tr><tr><td><code>sort_buffer_size<\/code><\/td><td>256K<\/td><td>512K<\/td><td>Per connection, per sort operation<\/td><\/tr><tr><td><code>join_buffer_size<\/code><\/td><td>256K<\/td><td>256K<\/td><td>Do not raise; fix the query or the index<\/td><\/tr><tr><td><code>read_buffer_size<\/code><\/td><td>128K<\/td><td>256K<\/td><td>Sequential scan buffer, per connection<\/td><\/tr><tr><td><code>performance_schema<\/code><\/td><td>ON<\/td><td>OFF<\/td><td>Frees 100\u2013200 MB immediately; turn on only while measuring<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">At those values the per-connection cost is roughly 1.6 MB, so 30 connections cost about 48 MB in the worst case and the total sits near 430 MB. That leaves real headroom for the page cache, which matters more than people expect: without free memory the kernel cannot cache InnoDB data files, and every read becomes a physical read.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The config file<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>[mysqld]\ninnodb_buffer_pool_size          = 256M\ninnodb_buffer_pool_instances     = 4\ninnodb_log_file_size             = 64M\ninnodb_log_buffer_size           = 8M\ninnodb_flush_method              = O_DIRECT\ninnodb_flush_log_at_trx_commit   = 2\n\nkey_buffer_size                  = 16M\ntmp_table_size                   = 32M\nmax_heap_table_size              = 32M\n\nmax_connections                  = 30\nthread_cache_size                = 8\nsort_buffer_size                 = 512K\njoin_buffer_size                 = 256K\nread_buffer_size                 = 256K\nread_rnd_buffer_size             = 256K\n\nperformance_schema               = OFF\n\n[mysqldump]\nquick\nsingle-transaction<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One warning: <code>innodb_flush_log_at_trx_commit = 2<\/code> trades durability for speed \u2014 you can lose the last second of committed transactions in a crash. It is appropriate when the box is also doing regular backups and the schema can tolerate it. If it cannot, use <code>1<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verifying the result, not assuming it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After a restart, give it five minutes of real traffic, then check that resident memory actually settled where you planned.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Actual RSS of the mysqld process\nps -o rss= -C mysqld | awk '{printf \"mysqld RSS: %.0f MB\\n\", $1\/1024}'\n\n# Is it swapping? Any sustained non-zero si\/so means the budget is wrong\nvmstat 1 5\n\n# Buffer pool efficiency: hit ratio should stay above 99% for OLTP\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Calculate the hit ratio as <code>1 - (reads \/ read_requests)<\/code>. Below 99% the buffer pool is too small for the working set, and at that point the disk is doing work the RAM should have absorbed \u2014 but before raising it, check whether the working set is simply larger than 1 GB allows, which is a plan-size question rather than a configuration one. Constant swapping or an OOM kill in <code>dmesg<\/code> after these changes means the globals are still too generous; a small swapfile is a safety net, not a substitute for the arithmetic above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When the ledger stops balancing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once the buffer pool hit ratio is solid and the box is stable, the remaining lever is not a setting \u2014 it is more memory. Cutting <code>max_connections<\/code> is a real tradeoff: it prevents collapse under load, but the 31st concurrent request gets an error rather than a slow answer. That trade is only acceptable for so long. <a href=\"https:\/\/virtualserversvps.com\/\">See the full specs and pricing<\/a> when the arithmetic tells you the workload has outgrown the plan.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL&#8217;s default configuration is written for a machine with several gigabytes of headroom. On a 1 GB VPS that assumption is fatal: the server starts happily, then dies hours later&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":14,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-443","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting\" \/>\n<meta property=\"og:description\" content=\"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-17T07:00:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-21T22:04:38+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/\",\"name\":\"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-06-17T07:00:58+00:00\",\"dateModified\":\"2026-09-21T22:04:38+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/","og_locale":"en_US","og_type":"article","og_title":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting","og_description":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-06-17T07:00:58+00:00","article_modified_time":"2026-09-21T22:04:38+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/","name":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-06-17T07:00:58+00:00","dateModified":"2026-09-21T22:04:38+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Capping the MySQL my.cnf Memory Budget on a 1 GB VPS, Setting by Setting"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=443"}],"version-history":[{"count":3,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":1194,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions\/1194"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}