{"id":631,"date":"2026-07-17T22:17:54","date_gmt":"2026-07-17T22:17:54","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=631"},"modified":"2026-10-07T22:03:10","modified_gmt":"2026-10-07T22:03:10","slug":"postgresql-performance-tuning-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/","title":{"rendered":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM"},"content":{"rendered":"<div style=\"padding:20px\">\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014 they misallocate memory in both directions at once, over-reserving shared memory while starving per-query work areas. This guide replaces guesswork with arithmetic: measure available RAM, subtract known consumers, and assign the remainder by function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Start by Measuring, Not Guessing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before touching <code>postgresql.conf<\/code>, record the real numbers. <code>free -m<\/code> reports total and available memory; the &#8220;available&#8221; column is what matters because it accounts for reclaimable page cache. Then determine how much memory other services already hold:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free -m\nps -eo rss,comm --sort=-rss | head\nsudo -u postgres psql -c \"SHOW shared_buffers; SHOW work_mem; SHOW max_connections;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A 2 GB VPS running nginx, PHP-FPM and a systemd journal might leave 1.6 GB genuinely free. That figure \u2014 not the 2048 MB sticker on the plan \u2014 is your budget.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">shared_buffers: Cap at 25% of Usable RAM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>shared_buffers<\/code> is PostgreSQL&#8217;s own page cache. Allocate roughly 25% of the RAM available <em>to the database<\/em>, not to the whole machine. Going past ~40% starts crowding out the OS page cache, which PostgreSQL relies on for double-buffering of hot data. Below 15% forces excessive kernel-level reads.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>VPS RAM<\/th><th>RAM after services<\/th><th>shared_buffers<\/th><th>effective_cache_size<\/th><\/tr><\/thead><tbody><tr><td>1 GB<\/td><td>~700 MB<\/td><td>192 MB<\/td><td>512 MB<\/td><\/tr><tr><td>2 GB<\/td><td>~1.5 GB<\/td><td>384 MB<\/td><td>1 GB<\/td><\/tr><tr><td>4 GB<\/td><td>~3.2 GB<\/td><td>768 MB<\/td><td>2 GB<\/td><\/tr><tr><td>8 GB<\/td><td>~6.5 GB<\/td><td>1536 MB<\/td><td>4 GB<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>effective_cache_size<\/code> allocates nothing \u2014 it only informs the planner how much data the OS will likely keep cached. Set it to roughly 50\u201375% of total RAM so the planner correctly prefers index scans over sequential reads on hot tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">work_mem: The Multiplication That Bites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>work_mem<\/code> is not a global cap. Each sort, hash join, or bitmap operation can claim one <code>work_mem<\/code> slot, and a single complex query can hold several. With <code>max_connections = 100<\/code> and <code>work_mem = 64MB<\/code>, worst-case resident memory is measured in gigabytes. Size it from the bottom up:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep <code>work_mem<\/code> at 4\u201316 MB on a small VPS.<\/li>\n<li>Lower <code>max_connections<\/code> to 20\u201340 and put PgBouncer in front for application concurrency.<\/li>\n<li>Reserve larger work areas per-session for reporting queries with <code>SET LOCAL work_mem<\/code>, not in the global config.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Reducing connection count is usually a bigger win than inflating memory: every idle connection holds per-process overhead (roughly 5\u201310 MB with TLS) that never returns to the cache.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">maintenance_work_mem and autovacuum<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Set <code>maintenance_work_mem<\/code> to 64\u2013128 MB so VACUUM and index builds finish without repeated passes. Then tune autovacuum to act before tables bloat rather than after:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>autovacuum_vacuum_scale_factor = 0.05   # default 0.2 is far too lazy on small tables\nautovacuum_analyze_scale_factor = 0.02\nautovacuum_vacuum_cost_limit = 1000     # let vacuum finish quickly<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Connection Pooling: The Cheapest Concurrency Win<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL forks a process per connection, so every client socket costs memory that scales with <code>max_connections<\/code>, not with actual query load. A PHP or Node application that opens hundreds of short-lived connections wastes most of its RAM on idle backends. Put a pooler in front and keep the backend count small:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># pgbouncer.ini\n[databases]\napp = host=127.0.0.1 port=5432 dbname=app\n[pgbouncer]\npool_mode = transaction\nmax_client_conn = 500\ndefault_pool_size = 25\nserver_idle_timeout = 60<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Transaction pooling routes each client to a backend only for the duration of a transaction, so 500 application connections can share 25 backends. The caveat: session-level features such as advisory locks, <code>SET<\/code> outside a transaction, and prepared statements tied to a session must be handled carefully. If you rely on those, use session pooling for that database and keep <code>max_connections<\/code> modest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify with Real Measurements<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After every change, reload and confirm the settings took effect, then measure. Use <code>pg_stat_statements<\/code> to find the queries responsible for the most shared-buffer reads and total time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT calls, mean_exec_time, shared_blks_read, query\nFROM pg_stat_statements\nORDER BY shared_blks_read DESC LIMIT 10;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">High <code>shared_blks_read<\/code> means the working set does not fit in memory \u2014 increase <code>shared_buffers<\/code> before adding indexes. High <code>mean_exec_time<\/code> with low block reads points to CPU-bound sorting, where a targeted <code>work_mem<\/code> for that query class helps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check Memory Pressure, Not Just Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL&#8217;s <code>shared_buffers<\/code> is shared memory, but work areas and connections are private and can trigger the OOM killer. Read PSI pressure and the OOM log to confirm the box is not thrashing:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cat \/proc\/pressure\/memory<\/code> \u2014 rising &#8220;full&#8221; averages precede swap storms.<\/li>\n<li><code>dmesg | grep -i \"killed process\"<\/code> \u2014 any PostgreSQL PID here means you over-committed.<\/li>\n<li><code>vm.swappiness = 10<\/code> on a database VPS keeps the kernel from paging out hot buffers prematurely.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you are still choosing hardware and want instances where the RAM actually delivers the IOPS a database needs, review the <a href=\"https:\/\/virtualserversvps.com\/#providers\">provider comparison<\/a> before you commit. Resource sizing is cheap to change on paper and expensive to change after migration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Order of Operations<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Measure available RAM after services.<\/li>\n<li>Set <code>shared_buffers<\/code> to 25% of that, <code>effective_cache_size<\/code> to ~60% of total.<\/li>\n<li>Cut <code>max_connections<\/code> and add a pooler.<\/li>\n<li>Keep <code>work_mem<\/code> small globally; raise it per-session for analytics.<\/li>\n<li>Make autovacuum more aggressive than default.<\/li>\n<li>Validate with <code>pg_stat_statements<\/code> and PSI, then iterate.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Every one of these settings can be verified empirically. Change one variable at a time and keep the measurement before and after \u2014 that discipline is what separates a tuned database from a merely reconfigured one. When you outgrow the arithmetic, a larger instance from a <a href=\"https:\/\/virtualserversvps.com\/\">reliable VPS host<\/a> is the cleanest path.<\/p>\n\n\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014 they misallocate&#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":1,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-631","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>PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014\" \/>\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\/postgresql-performance-tuning-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM\" \/>\n<meta property=\"og:description\" content=\"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-17T22:17:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-07T22:03:10+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\/postgresql-performance-tuning-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/\",\"name\":\"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-17T22:17:54+00:00\",\"dateModified\":\"2026-10-07T22:03:10+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM\"}]},{\"@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":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM - Virtual Servers VPS Blog","description":"PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014","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\/postgresql-performance-tuning-vps\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM","og_description":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM","og_url":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-07-17T22:17:54+00:00","article_modified_time":"2026-10-07T22:03:10+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\/postgresql-performance-tuning-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/","name":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-17T22:17:54+00:00","dateModified":"2026-10-07T22:03:10+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"PostgreSQL ships with defaults tuned for a machine with far more RAM than a typical VPS. On a 1\u20134 GB instance those defaults are not merely suboptimal \u2014","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL on a Small VPS: Sizing shared_buffers, work_mem and Connections from Real RAM"}]},{"@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\/631","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=631"}],"version-history":[{"count":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/631\/revisions"}],"predecessor-version":[{"id":1327,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/631\/revisions\/1327"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}