# Database-synced rollbacks

> Undo a broken release across both application code and managed PostgreSQL in one phased operation that preserves post-deploy writes in the original database.

Category: Data & releases · Maturity: GA · Plans: Hobby, Pro, Scale · Updated 2026-11-26

Rolling back an application container without reversing its schema migration often leaves production broken. Gregale coordinates code rollback and managed PostgreSQL point-in-time recovery as one tracked switch, staging and verifying credentials on the restored database copy before fencing traffic.

## Roll back code and database together, or restore data independently

```bash
gregale rollback my-api --to v41 --restore-databases

# Or restore only the database and switch the app without changing code
gregale postgres restore orders --name orders-0900 --point-in-time 2026-11-26T09:00:00Z --switch my-api
```

## Key capabilities

- **Undoes release migrations automatically:** Pass --restore-databases to restore each database migrated by undone releases back to the exact start timestamp of the earliest replaced release command.
- **Non-destructive copy semantics:** Restores into a new database (<name>-before-v<revision>) so writes recorded after the restore point stay intact in the original database.
- **Verified phased cutover:** Your current release keeps serving while Gregale restores the copy, stages credentials, and checks SQL connectivity before fencing and switching the app.
- **Data-only switch without code changes:** When code is healthy and data is not, restore a managed PostgreSQL database to any timestamp in its 7-day window and switch the app in place.

## Typical PaaS vs. Gregale

| Capability | Typical PaaS | Gregale |
|---|---|---|
| Coordinated code + DB rollback | Reverts image only; manual DB backup restore and rebind | One CLI command restores both to the migration boundary |
| Post-incident writes preservation | In-place restores risk overwriting recent rows | Creates a new restored copy and leaves original DB intact |
| Credential verification | App boots and discovers broken credentials live | Stages and verifies SQL credentials before fencing traffic |

## Documentation

- [Releases & rollbacks](https://gregale.dev/docs/releases.md)
- [Managed PostgreSQL](https://gregale.dev/docs/postgres.md)
- [Canary rollouts](https://gregale.dev/docs/rollouts.md)
- [Release controls](https://gregale.dev/docs/release-controls.md)

## Related guides

- [rollback-code-and-database](https://gregale.dev/articles/rollback-code-and-database.md)
- [canary-deploys](https://gregale.dev/articles/canary-deploys.md)
- [deploy-freezes-release-approvals-schedules](https://gregale.dev/articles/deploy-freezes-release-approvals-schedules.md)
- [atomic-multi-service-releases](https://gregale.dev/articles/atomic-multi-service-releases.md)

## Runnable starters on GitHub

- [Postgres Migration & Rollback Demo](https://github.com/gregale-dev/postgres-migration-rollback-demo) (Python 3.13 · FastAPI · Postgres 17): FastAPI + managed PostgreSQL 17 starter demonstrating release.command migrations (MIGRATION_DATABASE_URL) and coordinated code + database rollback via gregale rollback --restore-databases.
- [Next.js 16 + Postgres Starter](https://github.com/gregale-dev/nextjs-postgres-starter) (Node 24 · Next.js 16 · Postgres 17): Next.js App Router with output: "standalone", pre-traffic SQL migrations, separate /healthz readiness check, and scale-to-zero MicroVMs.
- [Bun + Hono + Postgres Starter](https://github.com/gregale-dev/bun-hono-postgres-starter) (Bun 1 · Hono · TypeScript · Postgres 17): TypeScript REST API using Bun, Hono, and postgres.js with release-command SQL migrations and managed PostgreSQL 17 suspension when idle.
- [setup-gregale GitHub Action](https://github.com/gregale-dev/setup-gregale) (GitHub Action · @v1): Composite GitHub Action that installs the Gregale CLI, masks optional bearer credentials, and pairs with edge-rule-trace and deploy verification workflows.

Browse all starters: https://gregale.dev/templates.md

## Frequently asked questions

### Does --restore-databases overwrite my existing PostgreSQL database?

No. Gregale restores a new database named <name>-before-v<revision> and rebinds the app to it. All writes that landed in the original database after the restore point remain untouched until you explicitly delete the old database.

### Can I restore a database and switch my app without rolling back application code?

Yes. Run gregale postgres restore <db> --name <new-name> --point-in-time <timestamp> --switch <app> to execute the same credential staging, fencing, drain, and switch flow while keeping the current code release.

### Is there brief downtime during a database-synced rollback?

While the database copy restores and SQL credentials are checked, the app continues serving. Gregale then fences traffic, drains active instances, switches the binding and release, and resumes the app (typically under a minute plus wake time).

Canonical URL: https://gregale.dev/features/database-rollbacks
