Back to Blog
DevOps1 min read

Managing PostgreSQL Clusters in Coolify

... Views
Managing PostgreSQL Clusters in Coolify

Relying on managed databases like Supabase or AWS RDS is great, but self-hosting PostgreSQL on Coolify provides unmatched control and cost efficiency for the Luxima ecosystem.

Deploying Postgres via Coolify

Coolify simplifies database orchestration. Within minutes, we provisioned a PostgreSQL 16 instance. But production requires more than just a running container.

1. Automated Backups

Coolify natively supports scheduled backups. We configured a cron job (0 3 * * *) to dump the database every night at 3 AM and push the encrypted snapshot to an off-site AWS S3 bucket.

2. Connection Pooling (PgBouncer)

Because Next.js applications (especially those using Prisma) can easily exhaust database connections during traffic spikes, we placed PgBouncer in front of our database.

// schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL") // Points to PgBouncer port 6432
  directUrl = env("DIRECT_URL")  // Points directly to Postgres 5432 for migrations
}

By separating the pooling URL from the direct URL, we ensure migrations run flawlessly while our application scales effortlessly across hundreds of concurrent user sessions.

Have thoughts on this protocol?

I'm always open to discussing new architectural patterns or ecosystem strategies. Let's start a technical conversation.

System_Online
Local_Timestamp