Back to articles
Cloud VPS HostingAvertHostNovember 23, 20269 min read

Cloud Hosting Database: Self-Managed PostgreSQL or MySQL vs Managed in India

How to choose between a managed database service and running PostgreSQL or MySQL on a cloud VPS, with sizing, install, security, tuning, backup and DPDP guidance for Indian teams.

For a cloud hosting database, you have two real options: run PostgreSQL or MySQL yourself on a cloud VPS, or pay for a managed database service that runs it for you. Self-managing is cheaper and gives full control, but you own backups, patching, tuning and failover. A managed service removes that work at a higher, usage-linked price. This guide shows how to decide, and how to set up a safe self-managed database on a Linux VPS if you choose that route.

Self-managed vs managed database: what actually differs

The database engine is the same software either way. The difference is who does the operations work around it.

TaskSelf-managed on a VPSManaged database service
Install and version upgradesYouProvider, usually on a schedule you can defer
OS and security patchesYouProvider
Backups and point-in-time recoveryYou configure and testUsually built in, still worth testing
Replication and failoverYou build itOften a checkbox
Tuning (memory, connections, indexes)You, with full access to every settingLimited to the settings the provider exposes
Extensions and custom buildsAnything you can installOnly the supported list
Cost modelFlat VPS pricePremium over the same compute, often plus storage and I/O charges
Data locationYou choose the VPS locationDepends on the provider's regions

Neither is "better". Managed services pay off when nobody on your team wants to be on call for the database. Self-managed pays off when you have the skills, want predictable monthly cost, or need extensions and settings a managed service does not allow.

When a self-managed database on a VPS is the right call

Self-managing is a sensible default in these situations:

  • One application, one database. A typical web app, WordPress, Odoo or an internal tool does not need a database cluster. A single well-sized VPS with good backups is enough.
  • Predictable cost matters. A flat monthly VPS plan is easier to budget than a bill that grows with storage, I/O and connections.
  • You need control. Custom extensions, specific postgresql.conf settings, or a particular MySQL version are all possible on your own server.
  • Data residency is a requirement. You know exactly which server and which data centre holds the data.

It is the wrong call when downtime of even a few minutes is costly and you have no one who can handle a failed disk or a corrupted replica at 2 a.m. In that case, pay for managed, or at least for a second node and a tested failover plan.

Size the VPS for a database, not for a web server

Databases are limited by memory and disk speed far more often than by CPU. Use these starting points and then measure:

  • RAM: the working set (the data and indexes you touch regularly) should fit in memory. If your hot data is 6 GB, a 4 GB server will spend its life reading from disk.
  • Storage: use SSD or NVMe-backed storage. Random read and write latency matters more than raw capacity. Leave at least 30 to 40 percent free space for growth, vacuuming and temporary files.
  • CPU: 2 vCPUs are enough for most small and mid-sized applications. Add cores when you see sustained high CPU from concurrent queries, not just because the data is large.
  • Separate server or same server: on a small app, the web server and database can share one VPS. Once the database needs more than about half of the RAM, move it to its own VPS and connect over a private or firewalled link.

If you are comparing plans, how to choose a Linux VPS plan covers CPU, RAM and storage trade-offs in more detail.

Install PostgreSQL on an Ubuntu VPS

These steps assume a fresh Ubuntu LTS server that you have already secured with a non-root user, SSH keys and a firewall (see setting up a VPS in the first 30 minutes).

  1. Install the server:
    sudo apt update
    sudo apt install postgresql postgresql-contrib
  2. Check that it is running and note the version:
    sudo systemctl status postgresql
    sudo -u postgres psql -c "SELECT version();"
  3. Create an application role and database with its own password:
    sudo -u postgres psql
    CREATE ROLE appuser WITH LOGIN PASSWORD 'use-a-long-random-password';
    CREATE DATABASE appdb OWNER appuser;
  4. Keep PostgreSQL listening on localhost only if the app runs on the same server. This is the default (listen_addresses = 'localhost'). Only change it when a separate application server must connect.

The MySQL or MariaDB equivalent is sudo apt install mysql-server (or mariadb-server), followed by sudo mysql_secure_installation to remove anonymous users and the test database, then CREATE DATABASE and CREATE USER for the application.

Lock the database down

A database exposed to the internet is found and attacked quickly. Apply these controls before the first real data goes in:

  • Do not expose the port publicly. Port 5432 (PostgreSQL) and 3306 (MySQL) should be reachable only from your application server's IP. Use the firewall to enforce that, for example sudo ufw allow from 203.0.113.10 to any port 5432 proto tcp (replace the example address with your own).
  • Restrict by role and host. In PostgreSQL, edit pg_hba.conf so appuser can connect to appdb only from the expected address, using scram-sha-256 authentication.
  • Use least privilege. The application account should not be a superuser. Give it rights on its own database only, and use a separate account for migrations and admin work.
  • Encrypt connections if the app and database are on different servers. Enable TLS in the database and require it from the client.
  • Keep secrets out of code. Store the password in an environment file readable only by the service user, not in a repository.
  • Patch regularly. Apply minor version updates and OS security updates on a schedule. A monthly routine such as the one in the cloud server management checklist works well.

Tune the few settings that matter

Default configurations are conservative and assume a small machine. On a dedicated database VPS, a few changes give most of the benefit. These are starting points, not rules, so measure before and after.

  • PostgreSQL: set shared_buffers to roughly 25 percent of RAM, effective_cache_size to roughly 50 to 75 percent of RAM, and raise work_mem carefully, because it applies per sort or hash operation, per connection.
  • MySQL (InnoDB): set innodb_buffer_pool_size to roughly 50 to 70 percent of RAM on a database-only server, and keep innodb_flush_log_at_trx_commit at 1 unless you knowingly accept losing the last second of commits.
  • Connections: do not raise max_connections to hundreds. Use a connection pooler such as PgBouncer for PostgreSQL, or fix the application so it reuses connections.
  • Slow queries: turn on slow query logging (log_min_duration_statement in PostgreSQL, slow_query_log in MySQL) and add indexes for what shows up. Most "the database is slow" problems are missing indexes, not weak hardware.

The official PostgreSQL resource consumption documentation explains each memory setting and its trade-offs.

Backups: the part you cannot skip

A self-managed database without a tested backup is a risk to the business. Use more than one layer:

  1. Logical dumps for portability: pg_dump -Fc appdb > appdb.dump for PostgreSQL or mysqldump --single-transaction appdb > appdb.sql for MySQL. Schedule them with cron or a systemd timer, and compress them.
  2. Continuous archiving for point-in-time recovery: PostgreSQL WAL archiving or MySQL binary logs let you restore to a moment just before a bad deployment or an accidental delete, rather than to last night.
  3. Off-server copies. A backup on the same disk is not a backup. Send copies to separate storage, ideally in another location, and encrypt them.
  4. Restore tests. Restore into a scratch server at least monthly and check that row counts and recent records are present. Record how long it took, because that is your real recovery time.

A whole-server snapshot taken while the database is writing can be inconsistent. For snapshots, quiesce the database or rely on logical dumps and archived logs alongside them. The full pattern, including snapshots and restore drills, is in cloud server backup: snapshots, offsite copies and restore tests.

High availability: do you need it?

A single database server is a single point of failure. Before building replication, decide what failure you can tolerate.

  • Hours of downtime acceptable: one server, good backups, and a documented restore procedure. Most small businesses sit here.
  • Minutes of downtime acceptable: a streaming replica (PostgreSQL) or a replica using MySQL replication, with a manual or scripted promotion. Test the promotion before you need it.
  • Near-zero downtime required: automated failover with a tool such as Patroni, plus monitoring and a witness node. This is real engineering work. If you do not have the people for it, a managed service is often cheaper than the cost of getting it wrong.

A replica is not a backup. A bad DELETE replicates instantly to every copy.

India-specific points: latency, DPDP and billing

  • Latency: keep the database in the same location as the application. Every query that crosses between cities adds round-trip time, and apps often make dozens of queries per page. Hosting the pair in India also keeps response times low for Indian users.
  • Personal data: if the database holds customer data, the Digital Personal Data Protection Act, 2023 applies to how you collect, store and protect it. You need access controls, encryption where appropriate, breach procedures and a clear retention policy. Read the MeitY publications and take legal advice for your sector. Our overview of the DPDP Act and hosting in India covers the hosting angle.
  • Billing: a flat-rate VPS billed in INR with a GST invoice is simple to reconcile. Managed database bills that mix compute, storage, I/O and data transfer in foreign currency are harder to forecast, so check the pricing page for each line item.

How AvertHost can help

AvertHost runs Linux and Windows cloud VPS plans from a data centre in Delhi, in a Tier-IV facility operated by Yotta, with a 99.9% uptime SLA. That gives you a place to run PostgreSQL, MySQL or MariaDB yourself, with full root access to the server and your data held in India. You are responsible for the database software, backups and tuning, as described above. Compare current plans on the Linux VPS page, or see all cloud services. Check the live pricing pages for current plan specifications before you size a database server.

FAQ

Is it safe to run a database on a VPS?

Yes, if you keep the database port closed to the internet, use least-privilege accounts, patch regularly and test restores. Most database breaches come from exposed ports, weak passwords and missing updates, not from the VPS itself.

PostgreSQL or MySQL: which should I choose?

Choose what your application supports and your team knows. WordPress and many PHP applications use MySQL or MariaDB. PostgreSQL is popular for new applications that need advanced SQL features, JSON handling or extensions. Both run well on a Linux VPS.

How much RAM does a database VPS need?

Enough to hold your frequently used data and indexes in memory, plus room for the operating system and connections. For small applications, 4 GB is a common starting point. Watch cache hit ratios and swap use, and upgrade when the working set no longer fits.

Should the database share a server with the web app?

For small sites, yes, with the database bound to localhost. Move it to a separate VPS when the two compete for memory or when you need to scale and secure them independently.

Can I migrate from a managed database to a VPS later?

Usually yes. Take a logical dump (pg_dump or mysqldump), restore it on the new server, test the application against it and switch the connection string during a short maintenance window. Plan the cutover and keep the old database until you are sure.