Best VPS for Database (2025) — PostgreSQL & MySQL
Database performance depends on three hardware factors: storage I/O speed (IOPS), RAM for buffer pools, and CPU for query processing. For European hosting with low latency, see Germany VPS or Best NVMe VPS Europe. Of these, storage is often the most critical and most overlooked. A database on NVMe storage delivers 3-5x faster query performance compared to the same database on SATA SSD, because database workloads are dominated by random 4K reads and writes — exactly the pattern where NVMe excels.
This guide covers everything you need to host PostgreSQL, MySQL, or MongoDB on a VPS in 2025: database engine selection, hardware requirements, performance tuning, replication and backup strategies, and a comparison of the best VPS providers for database workloads.
PostgreSQL vs MySQL vs MongoDB
Choosing the right database engine depends on your application's requirements, data model, and query patterns. Each engine has distinct strengths and performance characteristics.
| Feature | PostgreSQL | MySQL (InnoDB) | MongoDB |
|---|---|---|---|
| Data Model | Relational (SQL) | Relational (SQL) | Document (NoSQL) |
| ACID Compliance | Full ACID | Full ACID (InnoDB) | Full ACID (since 4.0) |
| Complex Queries | Excellent (window functions, CTEs) | Good (basic window functions) | Basic (aggregation pipeline) |
| JSON Support | Excellent (JSONB with indexing) | Good (JSON with generated columns) | Native (document store) |
| Write Performance | Moderate (MVCC overhead) | Faster for simple writes | Fast (document-level locking) |
| Read Performance | Excellent (advanced query planner) | Good (simpler planner) | Good (index-based) |
| Replication | Logical and physical streaming | GTID-based replication | Replica sets |
| RAM Usage | Higher (work_mem per query) | Moderate (buffer pool focused) | Moderate (WiredTiger cache) |
| Best For | Complex queries, analytics, geospatial | Web apps, high write throughput | Flexible schemas, real-time apps |
PostgreSQL is the recommended choice for most applications in 2025. Its advanced query optimizer, JSONB support, extensions ecosystem (PostGIS for geospatial, pg_trgm for fuzzy search, TimescaleDB for time-series), and superior concurrency handling make it the most versatile database engine. For database hosting on VPS, see Best VPS for Web Hosting for combined web+database deployments.
MySQL excels in high-throughput, read-heavy web applications with simple query patterns. WordPress, for example, uses MySQL and benefits from its lower per-query memory overhead and faster simple writes. If your application primarily performs CRUD operations without complex joins or analytics, MySQL is a solid choice.
MongoDB is appropriate when your data model does not fit neatly into tables — real-time analytics, content management systems, IoT data, and applications with rapidly evolving schemas. MongoDB uses more storage than relational databases due to its document format and index overhead.
Why NVMe Storage Is Critical for Databases
Database workloads are characterized by small, random read and write operations (4-8 KB blocks). This is the exact pattern where NVMe storage provides the most dramatic performance improvement over SATA SSDs. Sequential throughput (the metric many VPS providers advertise) is largely irrelevant for databases.
| Storage Type | Sequential Read | Random 4K Read IOPS | Random 4K Write IOPS | Latency |
|---|---|---|---|---|
| HDD | 150 MB/s | 100-200 | 100-150 | 5-10 ms |
| SATA SSD | 550 MB/s | 10,000-30,000 | 10,000-20,000 | 0.1-0.5 ms |
| NVMe SSD (Dedicated) | 6,000+ MB/s | 300,000-500,000 | 200,000-400,000 | 0.01-0.03 ms |
| NVMe (Shared/Ceph) | 3,000-5,000 MB/s | 150,000-300,000 | 100,000-200,000 | 0.03-0.1 ms |
Dedicated NVMe allocation (like Inferno VPS provides) delivers 10-20x the random IOPS of SATA SSD. For PostgreSQL with a 50 GB database and 100 concurrent clients, this translates to 40-60% faster query response times. For MongoDB with a working set larger than available RAM, NVMe is the difference between acceptable and unusable performance.
RAM Requirements: Buffer Pool Sizing
RAM is the second most critical resource for database hosting. The buffer pool (PostgreSQL: shared_buffers, MySQL: innodb_buffer_pool_size, MongoDB: WiredTiger cache) holds frequently accessed data pages in memory, avoiding expensive disk reads. The general rule is to allocate 50-75% of available RAM to the buffer pool.
| Database Size | Concurrent Users | Recommended RAM | Buffer Pool Size | Inferno Plan |
|---|---|---|---|---|
| Under 5 GB | 1-50 | 4 GB | 2 GB | Professional ($6.99) |
| 5-50 GB | 50-200 | 8 GB | 5 GB | Enterprise ($14.99) |
| 50-200 GB | 200-500 | 16 GB | 10 GB | Elite ($29.99) |
| 200+ GB | 500+ | 32 GB | 22 GB | Elite+ ($49.99) |
Step-by-Step: PostgreSQL Installation and Tuning
Step 1: Install PostgreSQL 16
# Add PostgreSQL repository
sudo apt install -y wget gnupg2 lsb-release
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
# Install PostgreSQL 16
sudo apt install -y postgresql-16 postgresql-16-contrib
# Start and enable PostgreSQL
sudo systemctl enable postgresql
sudo systemctl start postgresql
Step 2: Performance Tuning
random_page_cost setting tells PostgreSQL's query planner how expensive random I/O is. The default value (4.0) assumes HDD storage. For NVMe, set this to 1.1, which is only slightly higher than sequential I/O cost (1.0). This causes the planner to favor index scans more aggressively, which is appropriate for NVMe's low random-read latency.
Step 3: Create Database and User
Replication and High Availability
For production databases, configure streaming replication to a standby server. If your primary server fails, the standby can be promoted to primary with minimal data loss.
# On the PRIMARY server:
# Edit postgresql.conf
sudo nano /etc/postgresql/16/main/conf.d/replication.conf
# Add:
# wal_level = replica
# max_wal_senders = 3
# wal_keep_size = 1GB
# listen_addresses = '*'
# Create replication user
sudo -u postgres psql
CREATE USER replicator WITH REPLICATION ENCRYPTED PASSWORD 'replication-password';
# Edit pg_hba.conf to allow replication connections
# host replication replicator STANDBY_IP/32 scram-sha-256
sudo systemctl restart postgresql
# On the STANDBY server:
# Use pg_basebackup to clone the primary
sudo -u postgres pg_basebackup -h PRIMARY_IP -U replicator -D /var/lib/postgresql/16/main -P -v -R -X stream -C -S replica1
# Start PostgreSQL on standby
sudo systemctl start postgresql
Backup Strategy
Automated backups are non-negotiable for database hosting. Use pg_dump for logical backups and pg_basebackup for physical backups.
/opt/backups/pg-backup.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/opt/backups/postgresql"
DATE=$(date +%Y%m%d_%H%M%S)
KEEP_DAYS=7
mkdir -p $BACKUP_DIR
# Dump all databases
pg_dumpall -U postgres | gzip > $BACKUP_DIR/all_databases_$DATE.sql.gz
# Delete backups older than 7 days
find $BACKUP_DIR -name "*.sql.gz" -mtime +$KEEP_DAYS -delete
# Optional: Upload to remote storage
# rsync -avz $BACKUP_DIR/ user@remote:/backups/postgresql/
EOF
chmod +x /opt/backups/pg-backup.sh
# Schedule daily backup at 3 AM
(crontab -l 2>/dev/null; echo "0 3 * * * /opt/backups/pg-backup.sh >> /var/log/pg-backup.log 2>&1") | crontab -
Provider Comparison for Database Hosting
| Provider | 4 GB RAM | 8 GB RAM | 16 GB RAM | Storage | 4K Random IOPS | Best For |
|---|---|---|---|---|---|---|
| Inferno VPS | $6.99/mo | $14.99/mo | $29.99/mo | Dedicated NVMe | 412K | Best overall |
| Hetzner | $8.86/mo | $17.73/mo | $35.46/mo | Ceph NVMe | 285K | Budget alternative |
| DigitalOcean | $24/mo | $48/mo | $96/mo | Managed NVMe | 243K | Managed DB add-on |
| Vultr | $24/mo | $48/mo | $96/mo | Bare NVMe | 368K | Global locations |
| Contabo | $7.99/mo | $15.99/mo | $31.99/mo | NVMe (throttled) | 82K | Not recommended for DB |
Inferno VPS delivers the highest random 4K IOPS (412,000 read, 298,000 write) at the lowest price point — making it the clear choice for database hosting. The dedicated NVMe allocation ensures consistent I/O performance without the variability of shared Ceph storage. At $14.99/month for 4 vCPU and 8 GB RAM, Inferno provides database performance that exceeds DigitalOcean at $48/month.
Pros and Cons: VPS for Database Hosting
Advantages
- Dedicated NVMe storage delivers 10-20x the IOPS of shared hosting
- Full control over PostgreSQL/MySQL configuration for query optimization
- Significantly cheaper than managed database services (RDS, Cloud SQL)
- No connection limits or query throttling imposed by the provider
- Can run multiple database instances on the same VPS
- Direct filesystem access enables efficient backup strategies
- Easy to scale — upgrade RAM/CPU without data migration
- Choice of any database engine version or fork
Disadvantages
- Requires database administration knowledge for tuning and maintenance
- You handle backups, replication, and failover manually
- No automated point-in-time recovery (PITR) like managed services
- No built-in monitoring dashboards (install your own with Grafana/Prometheus)
- Single point of failure unless you configure replication manually
- OS-level patches require database restarts (planned maintenance)
- No automated scaling — must manually upgrade for increased load
Frequently Asked Questions
Why is NVMe important for databases?
Database workloads are dominated by small, random read and write operations (4-8 KB blocks). NVMe storage delivers 300,000-500,000 random 4K IOPS compared to 10,000-30,000 for SATA SSD. This 10-20x improvement in random I/O directly translates to faster query response times, higher transaction throughput, and lower latency. Sequential throughput (often advertised by VPS providers) is largely irrelevant for databases.
How much RAM do I need for PostgreSQL?
Allocate 50-75% of total RAM to shared_buffers. For a 4 GB VPS, set shared_buffers to 1.5-2 GB. For an 8 GB VPS, set it to 3-4 GB. Leave the rest for the OS file system cache, query processing memory (work_mem), and background processes. Running PostgreSQL on a VPS with less than 2 GB RAM is not recommended for production use.
Can I run PostgreSQL and a web server on the same VPS?
Yes, for small to medium workloads. A 4 vCPU / 8 GB VPS can run both Nginx+PHP and PostgreSQL with good performance. Allocate 3 GB to shared_buffers and leave 5 GB for the OS, PHP-FPM workers, and file system cache. For high-traffic applications, separate the database onto its own VPS to eliminate resource contention and simplify scaling.
How do I monitor database performance?
Install pg_stat_statements extension for query tracking, and use Grafana with the PostgreSQL dashboard for visualization. Key metrics to monitor: transactions per second, query latency percentiles (p50, p95, p99), cache hit ratio (should be above 99%), replication lag, autovacuum status, and disk I/O utilization. Prometheus + Grafana provides a free, comprehensive monitoring stack.
Is self-hosted PostgreSQL cheaper than managed database services?
Significantly. Amazon RDS for PostgreSQL (4 vCPU, 8 GB RAM) costs approximately $160/month with moderate I/O credits. Google Cloud SQL for PostgreSQL (4 vCPU, 8 GB RAM) costs approximately $120/month. Inferno VPS delivers the same or better performance at $14.99/month — a savings of 85-90%. The trade-off is that you handle backups, patches, and monitoring yourself.
How often should I back up my database?
Daily full backups at minimum, with hourly incremental backups for high-write workloads. Use pg_dump for logical backups (portable, human-readable SQL) and pg_basebackup for physical backups (faster restore, supports point-in-time recovery with WAL archiving). Store backups off-site on a different VPS or cloud storage. Test restore procedures quarterly to ensure backups are valid.
What is the difference between shared and dedicated NVMe for databases?
Shared NVMe (like Hetzner's Ceph) distributes your I/O across a storage cluster with other tenants. Performance is generally good but can vary under load. Dedicated NVMe (like Inferno VPS) allocates storage exclusively to your VPS instance, ensuring consistent IOPS regardless of other tenants' activity. For databases where consistent latency is critical, dedicated NVMe is strongly recommended.