Skip to content
COL0

Production database: security, backups and best practices

Your code can be redeployed; your data cannot. An unprotected or unbacked-up database is the most expensive mistake you can make in production.

Written by Victor Barrera

The golden rules

  • Do not expose it. The MySQL (3306) or PostgreSQL (5432) port must not be open to the whole internet. Have it listen on localhost or a private network.
  • One user per application with only the permissions it needs, never the administrator user.
  • Long, unique passwords, kept in environment variables.
  • Automatic backups kept off the server, and a restore test.

The steps, in short

  1. Install or subscribe to the database and create your app’s database and user.
  2. Restrict access: closed firewall for the database port and connections over localhost, a private network or a VPN.
  3. Automate backups with mysqldump or pg_dump in a scheduled task, compressed and with the date in the file name.
  4. Send a copy off the server (a storage bucket, for example).
  5. Test restoring in another environment. A backup you never restored is a hope, not a backup.
  6. Monitor disk space and connections so you find out before it fills up.
  7. Apply migrations carefully: a backup first, then the change.

Common mistakes

  • Leaving the database open to the internet with a weak password.
  • Backing up onto the server’s own disk: if the disk fails, you lose everything.
  • Using the database root user from the application.
  • Running destructive migrations in production without testing first.

How we help

We leave your database private, with least-privilege users, automatic backups off the server and a tested restore.

Frequently asked questions

Should I install the database myself or use a managed one?

A managed database (from your cloud provider) gives you backups, updates and monitoring, for a higher monthly cost. Installing it yourself is cheaper, but backups and security become your responsibility.

How often should I take backups?

It depends on how much data you can afford to lose. For most projects, a daily backup and a copy off the server is the reasonable minimum.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session