Back to articles
DevOps & Systems

Optimizing VPS as a Dedicated Database Server

Optimizing a Virtual Private Server (VPS) for dedicated database operations is a practical solution for small and medium enterprises seeking high performance, cost efficiency, and...

DPTCloud Engineering4 min read
Optimizing VPS as a Dedicated Database Server

Image credit: ColossusCloud · Pixabay Content License

Optimizing a Virtual Private Server (VPS) for dedicated database operations is a practical solution for small and medium enterprises seeking high performance, cost efficiency, and scalable infrastructure. With NVMe Cloud VPS supporting Docker, Nginx, and databases, you can configure a VPS to function as an efficient dedicated database server. This guide provides step-by-step configuration, optimization, and monitoring for database environments on VPS platforms.

1. Selecting the Right VPS and Configuring the Operating System

To optimize a VPS as a database server, start by choosing a suitable platform. NVMe-based VPS offers high read/write speeds, ideal for databases with frequent I/O operations. Opt for stable operating systems such as Ubuntu Server 22.04 LTS or CentOS Stream, which provide long-term support and large communities.

Run the following command to update the system:

sudo apt update && sudo apt upgrade -y

Ensure the system is fully updated before installing database software.

2. Installing and Configuring the Database

Depending on your needs, you can choose database management systems like MySQL, PostgreSQL, or MongoDB. The following instructions apply to MySQL, but similar steps apply to others.

Install MySQL:

sudo apt install mysql-server -y

After installation, check the status:

sudo systemctl status mysql

To optimize performance, edit the configuration file /etc/mysql/mysql.conf.d/mysqld.cnf:

[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
max_connections = 500

These settings improve data read/write efficiency, especially on VPS with 4GB RAM or more.

3. Performance and Resource Optimization

To ensure stable operation as a database server, optimize system resources:

  • RAM: Allocate sufficient memory to the database buffer pool. For a 4GB VPS, set innodb_buffer_pool_size to 70–80% of available RAM.
  • Storage: Use NVMe storage to reduce I/O latency. Verify with lsblk or df -h.
  • Swap: Enable swap if RAM is limited, but keep it small (256MB–512MB) to avoid severe performance degradation.
  • Kernel parameters: Adjust vm.swappiness and vm.dirty_ratio to prioritize memory for the database.

Edit /etc/sysctl.conf:

vm.swappiness = 10
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5

Apply changes:

sudo sysctl -p

4. Security and Monitoring

Security is critical when running a database server. Follow these steps:

  • Change the MySQL root password.
  • Restrict port 3306 access to specific IPs only.
  • Use ufw to limit access:
sudo ufw allow from 192.168.1.0/24 to any port 3306
sudo ufw enable

For monitoring, install htop, iotop, and mysqltuner:

sudo apt install htop iotop -y
wget https://mysqltuner.pl/ -O mysqltuner.pl
chmod +x mysqltuner.pl
./mysqltuner.pl

mysqltuner.pl provides detailed configuration recommendations based on actual load.

5. Testing and Maintenance

Regularly test and maintain the system:

  • Run mysqladmin ping to verify database connectivity.
  • Monitor logs using sudo tail -f /var/log/mysql/error.log.
  • Periodically optimize databases with OPTIMIZE TABLE or ANALYZE TABLE.
  • Back up data regularly using mysqldump.

For larger deployments, refer to the database performance on VPS guide to compare MySQL, PostgreSQL, and MongoDB.

6. Advanced Optimization for Real-World Use

To further improve performance:

Caution: Avoid using VPS for large databases without a backup and disaster recovery plan (DRP).

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478