{"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-07-17T22:17:54","modified_gmt":"2026-07-17T22:17:54","slug":"postgresql-performance-tuning-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/postgresql-performance-tuning-vps\/","title":{"rendered":"PostgreSQL Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">PostgreSQL is the go-to open-source relational database for applications requiring advanced concurrency, data integrity, and analytical capabilities. However, on a VPS with limited resources, PostgreSQL&#8217;s conservative defaults can waste memory and produce sluggish queries. This guide covers practical PostgreSQL tuning for VPS environments \u2014 memory allocation, query optimization, connection pooling, and maintenance routines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Memory Configuration: The postgresql.conf Foundation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL&#8217;s memory settings in <code>postgresql.conf<\/code> have the single biggest impact on performance. On a VPS, RAM is your scarcest resource \u2014 allocate it carefully.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">shared_buffers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the in-memory cache for database pages. Set it to <strong>25% of total VPS RAM<\/strong>. For a 2GB VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shared_buffers = 512MB<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Going above 25% leaves insufficient memory for OS cache, connections, and query operations. Below 15% forces excessive disk reads.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">effective_cache_size<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Tell PostgreSQL how much memory the OS and filesystem cache can provide. Set this to <strong>75% of total RAM<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>effective_cache_size = 1536MB<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This value doesn&#8217;t allocate memory \u2014 it helps the query planner estimate whether index scans or sequential scans are cheaper. Underestimating leads to unnecessary sequential scans.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">work_mem<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Controls memory per sort, hash join, or aggregation operation. Set conservatively because each concurrent query can use multiple work_mem slots:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>work_mem = 16MB   # 2GB VPS\nwork_mem = 32MB   # 4GB VPS\nwork_mem = 64MB   # 8GB VPS<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you see temporary files written to disk during <code>EXPLAIN ANALYZE<\/code>, increase work_mem gradually. Watch for &#8220;work_mem: N bytes wanted&#8221; in logs to detect disk spills.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connection Pooling with PgBouncer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each PostgreSQL connection consumes about 5-10MB of RAM. A web application with 100 concurrent connections uses 500MB-1GB before any queries run. PgBouncer solves this by multiplexing connections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install and configure PgBouncer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install pgbouncer\n\n# \/etc\/pgbouncer\/pgbouncer.ini\n[databases]\nmydb = host=127.0.0.1 port=5432 dbname=mydb\n\n[pgbouncer]\nlisten_addr = 127.0.0.1\nlisten_port = 6432\nauth_type = scram-sha-256\nauth_file = \/etc\/pgbouncer\/userlist.txt\npool_mode = transaction\ndefault_pool_size = 25\nmax_client_conn = 200<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>pool_mode = transaction<\/code>, PgBouncer reuses connections between transactions \u2014 perfect for web applications. This cuts PostgreSQL&#8217;s active connections from 100+ to just 25, saving hundreds of megabytes of RAM. <a href=\"https:\/\/virtualserversvps.com\/\">Check our VPS comparison table<\/a> for providers with enough RAM to run PostgreSQL efficiently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Query Optimization Techniques<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Identify Slow Queries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enable query logging in postgresql.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>log_min_duration_statement = 200  # Log queries taking 200ms+\nlog_connections = on\nlog_disconnections = on<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then analyze with pgBadger for formatted reports:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install pgbadger\npgbadger \/var\/log\/postgresql\/postgresql-16-main.log -o report.html<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Index Strategy<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>B-tree indexes<\/strong> for equality and range queries on high-cardinality columns.<\/li>\n\n\n<li><strong>BRIN indexes<\/strong> for large tables where data is physically ordered (time-series data). BRIN indexes use 100x less space than B-tree on append-only tables.<\/li>\n\n\n<li><strong>GIN indexes<\/strong> for full-text search and JSONB queries.<\/li>\n\n\n<li>Remove unused indexes \u2014 they slow down writes and consume disk. Use <code>pg_stat_user_indexes<\/code> to find them.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Maintenance and Vacuuming<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL&#8217;s MVCC creates dead tuples that must be reclaimed. Configure autovacuum aggressively on a VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>autovacuum_max_workers = 3\nautovacuum_naptime = 30s\nautovacuum_vacuum_scale_factor = 0.01\nautovacuum_vacuum_threshold = 50<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Monitor vacuum activity:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT schemaname, relname, n_dead_tup, last_autovacuum\nFROM pg_stat_user_tables\nWHERE n_dead_tup &gt; 1000;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Quick-Reference Tuning Cheat Sheet<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>1GB VPS<\/th><th>2GB VPS<\/th><th>4GB VPS<\/th><\/tr><\/thead><tbody><tr><td>shared_buffers<\/td><td>256MB<\/td><td>512MB<\/td><td>1GB<\/td><\/tr><tr><td>effective_cache_size<\/td><td>768MB<\/td><td>1536MB<\/td><td>3GB<\/td><\/tr><tr><td>work_mem<\/td><td>8MB<\/td><td>16MB<\/td><td>32MB<\/td><\/tr><tr><td>maintenance_work_mem<\/td><td>64MB<\/td><td>128MB<\/td><td>256MB<\/td><\/tr><tr><td>random_page_cost<\/td><td>1.1 (SSD)<\/td><td>1.1 (SSD)<\/td><td>1.1 (SSD)<\/td><\/tr><tr><td>effective_io_concurrency<\/td><td>200<\/td><td>200<\/td><td>200<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Adjust <code>random_page_cost<\/code> to 1.1 if your VPS uses NVMe or SSD storage (default 4.0 is for HDDs). This tells the planner that random I\/O is fast and encourages index usage. For more PostgreSQL-friendly VPS plans, <a href=\"https:\/\/virtualserversvps.com\/\">compare storage types and RAM configurations on our site<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL is the go-to open-source relational database for applications requiring advanced concurrency, data integrity, and analytical capabilities. However, on a VPS with limited resources, PostgreSQL&#8217;s conservative defaults can waste memory&#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":0,"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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling - 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\/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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling\" \/>\n<meta property=\"og:description\" content=\"PostgreSQL Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling\" \/>\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 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=\"3 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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-17T22:17:54+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling\"}]},{\"@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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling - 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\/postgresql-performance-tuning-vps\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling","og_description":"PostgreSQL Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling","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","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"3 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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-17T22:17:54+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"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 Performance Tuning on a VPS: Memory, Query Optimization, and Connection Pooling"}]},{"@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":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/631\/revisions"}],"predecessor-version":[{"id":655,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/631\/revisions\/655"}],"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}]}}