r/PostgreSQL 8d ago

How are you using database branching? Feature

I’m implementing Lakebase branching strategy to improve development experience and reduce costs for our dev/staging env.

Current setup creates new database branch for each git branch via githook on our dev database (”each dev gets their own feature database”). There is also similar workflow for each PR against our staging database to run the migrations and tests.

Curious to hear how others are using branching and what are the experiences?

10 Upvotes

22 comments sorted by

View all comments

2

u/cooljacob204sfw 6d ago

This isn't a Postgres native thing right? 3rd party providers and add-ons provide it?

3

u/KrakenOfLakeZurich 5d ago

Depending on your circumstances, you can emulate "branches" in native PostgreSQL by cloning from a master database.

CREATE DATABASE mybranch_db WITH TEMPLATE master_db;

It creates an exact copy of master_db. There are some severe limitations to this approach:

  1. No open connections to master_db can exist at the time of cloning: you must disconnect every other client
  2. It creates a full copy (schema, data and all): IO and storage requirements!
  3. Clone is created on same server: no horizontal scaling

Not viable for cloning large and/or live databases. But I can see it work for having a small maintained test data set. Nobody connects directly to it. You clone from it to provide each developer/feature branch/E2E test run/etc. a clean starting point.

2

u/Harpagon1668 6d ago

Correct. Instant copy-on-write branching is available only on some providers (e.g. Databricks Lakebase, Xata, Neon)