Skip to content
Menu

DocsFeatures

View as Markdown

Branching

Instant copy-on-write branches on Free and Launch, branches restored from backups on Dedicated, point-in-time branches, branches from snapshots, branch expiry, deletion protection, protected branches and a database per pull request.

A branch is a new, independent database created from another database's data. Use branches for preview environments, testing migrations on real data, debugging, and analytics without touching production.

How branches work

You choose where the data comes from:

SourceFree and Launch parentsDedicated parents
NowInstant: an online copy-on-write snapshot of the parent's volume. The parent stays online and the time doesn't depend on the size of the data. The parent writes a checkpoint first, which on a busy database is a short burst of disk writesRestored from backups to the latest moment: minutes to hours, about 1.5 hours per TB of data. The console shows the estimate before you confirm
A point in timeRestored from the parent's base backups and write-ahead log archive to the exact second you choose, within the parent's restore window. Takes longer the more data and log there is to replayThe same

Either way, the branch starts its own PostgreSQL instance, so poll its status until it is ready before connecting. If a backup of the parent is running when you create an instant branch (for example the daily backup, or the first backup right after the parent was created), the snapshot is taken once that backup has finished. A Dedicated database's production servers are never used to build a branch.

Once created, a branch is a full database:

  • Its own PostgreSQL instance, hostnames (<branch-id>.<region>.db.keeldb.com, -pooler, -ro) and password.
  • The same database name, user name, region and PostgreSQL version as its parent.
  • It copies the parent's pooler setting and IP allowlist at creation. Later changes on either side don't affect the other.
  • Its own metrics and settings. Writes on the branch never reach the parent, and the reverse.
  • An instant branch keeps no backups of its own while its parent's history restores it, as on Neon, and at most a day of them after that (see Backups of a branch). A point-in-time branch or a branch from a snapshot is a full copy with backups of its own.
  • A single copy: branches are never highly available, even when their parent is.
  • You can branch a branch.

Where a branch runs and what it costs

ParentBranch runs onBilling
FreeFree, next to its parentFree. Up to 5 branches per database and 20 per organization in all. Branches share their database's 1 GB and its 100 CU-hours a month, and don't count toward the organization's 10 Free databases. What counts toward the 1 GB: the database's data, for each instant branch the lesser of what it has written since it was made and its size (or its growth over its parent if that is more), and all the data of a point-in-time branch or a branch from a snapshot, which are full copies. A branch that would take the family past 1 GB is refused
LaunchLaunch, next to its parent10 child branches per database included, within your organization's allowance (5 plus 1 for each $1 of compute, storage and restore history above the $5 minimum, counted in branch-hours over the month), then $1.00 per branch-month. The branch's compute is billed in CU-hours. Its storage is, for an instant branch, the lesser of what it has written since it was made and its size (as on Neon: a new branch costs nothing for storage), or its growth over its parent if that is more (data that writes no log, such as unlogged tables, still takes disk), and all its data for a point-in-time branch or a branch from a snapshot (a full copy)
Dedicated, data up to 100 GBLaunchAs Launch
Dedicated, data above 100 GBOne Dedicated single node of the smallest size whose maximum storage holds the dataThat size's node-hours, and a disk sized for the data

If a Free database moves to a paid plan, its branches move with it.

A branch that needs a Dedicated node gets a server of its own; it never starts on reserved capacity. The console and the branch dialog show where the branch will run and what it costs before you create it. Delete branches when you are done, or give them an expiry time.

Requirements

  • The parent must be running (ready, or sleeping). A sleeping Free or Launch parent is woken up for an instant branch, since the branch starts from a snapshot of it, and stays awake until the branch is created. A branch restored from backups leaves a sleeping parent asleep.
  • A point-in-time branch needs a time within the parent's restore window (1 day on Free, up to 7 days on Launch, 7, 14 or 30 days on Dedicated), after the parent's first backup finished, and not in the future. Its parent is a database, not an instant branch: an instant branch has no restore window of its own. Neon also branches from a past moment of a child branch; KeelDB does not yet.
  • Branches count toward your organization's limits (see Limits). A branch on a paid plan needs a payment method.
  • A Free or Launch branch starts only when our shared servers have room for it, as a new database of its plan does (a Launch branch is not held to the room set aside for Free): an instant branch on the server its database runs on, a branch restored from backups on any of them. An instant branch is copied from the running database, so a database that is asleep wakes for it, and the branch starts only when there is room for both. When they are full right now, the request is refused with that reason (503 unavailable in the API) and nothing is created or billed; try again in a few minutes, since idle databases go to sleep and free their room. On Launch, a branch from a point in time or a snapshot is restored from backups and can start on another server with room.
  • A database can't be deleted while it has branches. Delete the branches first.

Backups of a branch

An instant branch on Free, Launch or Scale starts with no backups of its own, the way Neon's child branches work, and keeps some later; on Launch and Scale what it keeps is billed as its restore history:

  • Restored from its parent's history. When the branch is made, the parent's newest backup from before that moment is kept for it, with the parent's write-ahead log up to the branch's start; the branch's own changes are archived within 60 seconds (5 minutes on Free). From 12 hours after the branch is made, that log is copied into the branch's own backup storage; if the copy has not worked 20 hours after, the branch takes a backup of its own instead. If the branch's server is lost, the branch is restored from the parent's backup, the parent's log to the branch's start and its own log, like any database.
  • No point-in-time restore, snapshots or backup schedule of its own. Restoring in place, snapshots and schedules are a database's, as on Neon: make a new branch of the database, from any moment of its restore window, instead. Neon can also branch from a past moment of a child branch; KeelDB makes point-in-time branches from databases only for now.
  • Once it has written as much as its size, or its copy of the parent's log would weigh more than a backup of its own, or its parent's history is gone, the branch takes backups of its own and keeps them 1 day. Its storage is billed the same way either way.
  • Billing. The parent's backup kept for its branches is billed to the parent as restore history once it is older than the parent's restore window. What a branch's own backups keep (the copy of its parent's history it holds after 12 hours, and its own base backups once it has them) is the branch's restore history, with twice the storage it is billed for included, above that $0.05 per GB-month on Launch and Scale.

Create a branch

In the console, open the database, go to Branches and choose New branch. Pick Right now or A point in time, a name and, if you like, an expiry time.

With the REST API, a branch of the current data that deletes itself after 7 days:

curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/branches \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "migration-test", "expires_at": "2026-10-16T12:00:00Z"}'

A branch as of a past moment (ISO 8601 with a time zone offset or Z):

curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/branches \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "before-bad-deploy", "at": "2026-10-07T08:29:00Z"}'

Both return 201 with the new database object. parent_id is the parent's id and branch_point is the restore time (null for a branch of the current data). From an AI assistant, use the create_branch MCP tool.

Branch expiry

Give a branch an expiry time and KeelDB deletes it for you at that time, exactly as if you had deleted it. Useful for previews, tests and anything temporary.

  • Set expires_at when you create the branch, or later with PATCH /api/v1/databases/{branch-id}. Set it to null to keep the branch.
  • It must be at most 30 days ahead when you set it. Move it forward again to keep a branch longer.
  • Only branches can expire, and a branch with deletion protection can't have an expiry time.
curl -X PATCH https://keeldb.com/api/v1/databases/b4n8c2xq7mz3 \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expires_at": "2026-10-30T00:00:00Z"}'

Deletion protection

Turn on deletion protection for databases and branches that must not disappear by mistake. While it is on, the console, the REST API, the MCP server and KeelDB's AI operators all refuse to delete the database, and it can't have an expiry time. Turn it off first, as its own change, to delete the database.

curl -X PATCH https://keeldb.com/api/v1/databases/k7m2x9qa4pz1 \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"deletion_protection": true}'

Protected branches

On Launch and Dedicated, mark your production database, or any branch your app depends on, as protected. Writes work as usual. While it is protected:

  • it can't be deleted: deletion protection is turned on with it and can't be turned off;
  • it can't expire;
  • its compute stays on: scale to zero is off and can't be turned on, so a Launch database is billed at least its minimum size every hour, and it never pays a cold start;
  • at a hard spend limit, when one applies, it holds at its minimum size instead of suspending (only the limit's hard stop, when even the minimum size would pass the limit, stops it, as for every Launch database);
  • it can't be moved between the shared servers and Dedicated servers by a move (turn protection off first).

Turning protection off leaves those settings as they are, so you change them one by one afterwards. In the console it is the Protected switch under the database's Settings; only members who may delete databases can turn it off. With the API:

curl -X PATCH https://keeldb.com/api/v1/databases/k7m2x9qa4pz1 \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"protected": true}'

Branches of a protected database are not protected themselves, and each gets its own password, as every KeelDB branch does. KeelDB has no "reset from parent" for branches; restore a snapshot into a new branch instead.

Preview environments per pull request

This GitHub Actions workflow gives every pull request its own branch of a staging database, runs migrations on it, exposes its connection string to later steps, and deletes it when the pull request closes. Each branch also expires after 7 days, in case a cleanup run never happens.

Setup:

  1. Create an API key under API keys in the console and save it as the repository secret KEELDB_API_KEY. The workflow creates, reads and deletes branches and reads their connection strings, so the key needs db.read, db.write, db.credentials and db.delete: an owner or admin creates it with the owner or admin role. A developer's key cannot delete databases, so its cleanup job would fail with 403 forbidden and leave each branch running until it expires.
  2. Set PARENT_DB to the id of the database to branch from. A Free or Launch parent gives instant branches.
name: Preview database

on:
  pull_request:
    types: [opened, reopened, synchronize, closed]

concurrency:
  group: preview-db-${{ github.event.pull_request.number }}

env:
  KEELDB_API: https://keeldb.com/api/v1
  PARENT_DB: k7m2x9qa4pz1
  BRANCH_NAME: pr-${{ github.event.pull_request.number }}

jobs:
  preview:
    if: github.event.action != 'closed'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Create or reuse the branch
        env:
          KEELDB_API_KEY: ${{ secrets.KEELDB_API_KEY }}
        run: |
          set -euo pipefail
          auth="Authorization: Bearer $KEELDB_API_KEY"
          expires=$(date -u -d "+7 days" +%Y-%m-%dT%H:%M:%SZ)

          # Reuse the branch from an earlier push to this pull request, if any.
          id=$(curl -fsS -H "$auth" "$KEELDB_API/databases/$PARENT_DB/branches" \
            | jq -r --arg n "$BRANCH_NAME" '[.data[] | select(.name == $n and .status != "deleting")][0].id // empty')

          if [ -z "$id" ]; then
            id=$(curl -fsS -X POST -H "$auth" -H "Content-Type: application/json" \
              -d "{\"name\": \"$BRANCH_NAME\", \"expires_at\": \"$expires\"}" \
              "$KEELDB_API/databases/$PARENT_DB/branches" | jq -r '.data.id')
          else
            # Push the expiry forward on every push.
            curl -fsS -X PATCH -H "$auth" -H "Content-Type: application/json" \
              -d "{\"expires_at\": \"$expires\"}" "$KEELDB_API/databases/$id" > /dev/null
          fi

          # Wait up to 10 minutes for the branch to be ready.
          status=""
          for _ in $(seq 1 60); do
            status=$(curl -fsS -H "$auth" "$KEELDB_API/databases/$id" | jq -r '.data.status')
            if [ "$status" = "ready" ]; then break; fi
            if [ "$status" = "error" ]; then echo "Branch $id failed to start"; exit 1; fi
            sleep 10
          done
          if [ "$status" != "ready" ]; then echo "Timed out waiting for branch $id"; exit 1; fi

          conn=$(curl -fsS -H "$auth" "$KEELDB_API/databases/$id/connection")
          echo "::add-mask::$(jq -r '.data.password' <<< "$conn")"
          echo "DATABASE_URL=$(jq -r '.data.pooler_uri' <<< "$conn")" >> "$GITHUB_ENV"
          echo "DIRECT_URL=$(jq -r '.data.uri' <<< "$conn")" >> "$GITHUB_ENV"

      - name: Run migrations against the branch
        run: npm ci && npm run db:migrate   # your migration command, using DIRECT_URL

      # Deploy the preview here. DATABASE_URL (pooled) and DIRECT_URL are set for every later step.

  cleanup:
    if: github.event.action == 'closed'
    runs-on: ubuntu-latest
    steps:
      - name: Delete the branch
        env:
          KEELDB_API_KEY: ${{ secrets.KEELDB_API_KEY }}
        run: |
          set -euo pipefail
          auth="Authorization: Bearer $KEELDB_API_KEY"
          ids=$(curl -fsS -H "$auth" "$KEELDB_API/databases/$PARENT_DB/branches" \
            | jq -r --arg n "$BRANCH_NAME" '.data[] | select(.name == $n and .status != "deleting") | .id')
          for id in $ids; do
            curl -fsS -X DELETE -H "$auth" "$KEELDB_API/databases/$id"
          done

Notes:

  • Branch names don't have to be unique, which is why the workflow looks the branch up by name and reuses it on later pushes. The branch keeps the data it was created with; delete it to start again from fresh data.
  • DELETE returns 202 and the branch shows status: "deleting" until it is gone. Billing stops at the hour of the deletion request.
  • Many open pull requests means many branches. Keep the limits in mind: Free includes 5 branches per database, and Launch 10 per database within your organization's allowance, before the per-branch charge.
  • A key can do what its role and permissions allow, and this one may delete databases. Use a key dedicated to CI, revoke it if it leaks, and turn on deletion protection for the parent. See API keys.