| name | xata-postgres-platform |
| description | Expert skill for Xata open-source cloud-native Postgres platform with copy-on-write branching, scale-to-zero, and Kubernetes deployment |
| triggers | ["set up xata postgres platform","create postgres branch with copy on write","self-host xata on kubernetes","xata scale to zero postgres","xata cli project and branch management","deploy xata postgres platform locally","xata branching preview environments","xata tilt kind cluster setup"] |
Xata Postgres Platform
Skill by ara.so — Daily 2026 Skills collection.
Xata is an open-source, cloud-native Postgres platform built on Kubernetes that provides copy-on-write (CoW) branching, scale-to-zero, auto-scaling, high-availability, PITR backups, and a serverless SQL driver. It sits on top of CloudNativePG and OpenEBS.
Architecture Overview
┌─────────────────────────────────────────────────────┐
│ Xata Platform │
│ CLI ──► REST API (clusters/projects services) │
│ SQL Gateway (routing, scale-to-zero wakeup) │
│ Branch Operator (manages K8s resources per branch) │
│ Auth Service (Keycloak-based, RBAC API keys) │
├─────────────────────────────────────────────────────┤
│ CloudNativePG (HA, failover, backups, pooling) │
│ OpenEBS (local NVMe or Mayastor replicated storage) │
└─────────────────────────────────────────────────────┘
Prerequisites
Local Development Setup
Step 1: Create Kind Cluster
kind create cluster --wait 10m
Step 2: Deploy with Tilt
tilt up
Wait for all resources to become ready. First run downloads images and takes longer; subsequent runs are fast.
Step 3: Install and Authenticate the CLI
curl -fsSL https://xata.io/install.sh | bash
xata auth login --profile local --env local --force
xata auth switch local
Step 4: Create Project and Branch
xata project create --name my-project
xata branch create
CLI Reference
Authentication
xata auth login
xata auth login --profile local --env local --force
xata auth switch local
xata auth switch default
xata auth list
Projects
xata project create --name my-project
xata project list
xata project get <project-id>
xata project delete <project-id>
Branches
xata branch create
xata branch create --name feature-xyz --from main
xata branch list
xata branch get <branch-id>
xata branch delete <branch-id>
Connecting to a Branch
xata branch connection-string <branch-id>
psql "$(xata branch connection-string <branch-id>)"
Configuration
Environment Variables
export XATA_API_URL=http://localhost:8080
export XATA_API_KEY=your_api_key_here
export XATA_PROJECT_ID=your_project_id
API Key Management (RBAC)
xata apikey create --name ci-key --role branch:read,branch:write
xata apikey list
xata apikey delete <key-id>
Serverless SQL Driver (SQL over HTTP/WebSockets)
Xata exposes a serverless driver for executing SQL over HTTP or WebSockets, useful for edge functions and environments without persistent TCP connections.
HTTP SQL Query (Go)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
type SQLRequest struct {
Query string `json:"query"`
Params []any `json:"params,omitempty"`
}
type SQLResponse struct {
Records []map[string]any `json:"records"`
Error string `json:"error,omitempty"`
}
func queryXata(query string, params ...any) (*SQLResponse, error) {
apiURL := os.Getenv("XATA_API_URL")
apiKey := os.Getenv("XATA_API_KEY")
branchID := os.Getenv("XATA_BRANCH_ID")
reqBody := SQLRequest{Query: query, Params: params}
data, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%s/branches/%s/sql", apiURL, branchID)
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
resp.Body.Close()
sqlResp SQLResponse
err := json.NewDecoder(resp.Body).Decode(&sqlResp); err != {
, err
}
&sqlResp,
}
{
result, err := queryXata(, )
err != {
(err)
}
_, record := result.Records {
fmt.Printf(, record)
}
}
Direct Postgres Connection (Go)
package main
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v5"
)
func main() {
connStr := os.Getenv("XATA_DATABASE_URL")
conn, err := pgx.Connect(context.Background(), connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
rows, err := conn.Query(context.Background(), "SELECT id, name FROM users LIMIT 10")
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var id int
var name string
if err := rows.Scan(&id, &name); err != nil {
panic(err)
}
fmt.Printf("id=%d name=%s\n", id, name)
}
}
Common Patterns
Preview Environment Workflow (CI/CD)
Create a per-PR branch for isolated testing, then destroy it after merge:
#!/usr/bin/env bash
set -euo pipefail
PR_NUMBER="${1:?PR number required}"
BRANCH_NAME="pr-${PR_NUMBER}"
BRANCH_ID=$(xata branch create --name "$BRANCH_NAME" --from main --output json | jq -r '.id')
echo "Created branch: $BRANCH_ID"
CONN_STR=$(xata branch connection-string "$BRANCH_ID")
echo "::set-output name=database_url::${CONN_STR}"
echo "::set-output name=branch_id::${BRANCH_ID}"
#!/usr/bin/env bash
BRANCH_ID="${1:?Branch ID required}"
xata branch delete "$BRANCH_ID"
echo "Deleted branch $BRANCH_ID"
GitHub Actions Integration
name: Preview Environment
on:
pull_request:
types: [opened, synchronize]
jobs:
create-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Xata CLI
run: curl -fsSL https://xata.io/install.sh | bash
- name: Authenticate
env:
XATA_API_KEY: ${{ secrets.XATA_API_KEY }}
run: xata auth login --api-key "$XATA_API_KEY"
- name: Create Preview Branch
id: branch
run: |
BRANCH_ID=$(xata branch create \
--name "pr-${{ github.event.number }}" \
--from main \
--output json | jq -r '.id')
echo "branch_id=$BRANCH_ID" >> "$GITHUB_OUTPUT"
CONN=$(xata branch connection-string "$BRANCH_ID")
echo "database_url=$CONN" >> "$GITHUB_OUTPUT"
-
Programmatic Branch Management (Go)
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
)
type XataClient struct {
BaseURL string
APIKey string
Project string
http *http.Client
}
func NewXataClient() *XataClient {
return &XataClient{
BaseURL: os.Getenv("XATA_API_URL"),
APIKey: os.Getenv("XATA_API_KEY"),
Project: os.Getenv("XATA_PROJECT_ID"),
http: &http.Client{},
}
}
type Branch struct {
ID string `json:"id"`
Name string `json:"name"`
ParentID string `json:"parentId"`
State string `json:"state"`
ConnectionURL string `json:"connectionUrl"`
}
type CreateBranchRequest struct {
Name string `json:"name"`
ParentID string `json:"parentId"`
}
func (c *XataClient) CreateBranch(ctx context.Context, name, parentID string) (*Branch, error) {
payload := CreateBranchRequest{Name: name, ParentID: parentID}
data, _ := json.Marshal(payload)
url := fmt.Sprintf("%s/projects/%s/branches", c.BaseURL, c.Project)
req, err := http.NewRequestWithContext(ctx, , url, strings.NewReader((data)))
err != {
, err
}
req.Header.Set(, +c.APIKey)
req.Header.Set(, )
resp, err := c.http.Do(req)
err != {
, err
}
resp.Body.Close()
branch Branch
err := json.NewDecoder(resp.Body).Decode(&branch); err != {
, err
}
&branch,
}
DeleteBranch(ctx context.Context, branchID ) {
url := fmt.Sprintf(, c.BaseURL, c.Project, branchID)
req, err := http.NewRequestWithContext(ctx, , url, )
err != {
err
}
req.Header.Set(, +c.APIKey)
_, err = c.http.Do(req)
err
}
{
client := NewXataClient()
ctx := context.Background()
branch, err := client.CreateBranch(ctx, , )
err != {
(err)
}
fmt.Printf(, branch.ID, branch.ConnectionURL)
err := client.DeleteBranch(ctx, branch.ID); err != {
(err)
}
fmt.Println()
}
Scale-to-Zero
Branches automatically hibernate after inactivity and wake up on the next connection. The SQL Gateway handles the wakeup transparently — clients may experience a short delay (~seconds) on the first connection after hibernation.
xata branch hibernate <branch-id>
xata branch wake <branch-id>
xata branch get <branch-id> --output json | jq '.state'
Troubleshooting
Tilt/Kind Issues
kubectl get pods -A
kubectl get pods -n xata
kubectl logs -n xata -l app=sql-gateway --tail=100
kubectl logs -n xata -l app=branch-operator --tail=100
kubectl logs -n xata -l app=clusters --tail=100
tilt down && tilt up
Branch Stuck in Provisioning
kubectl logs -n xata -l app=branch-operator -f
kubectl get clusters -A
kubectl describe cluster <cluster-name> -n <namespace>
kubectl get pvc -A
kubectl describe pvc <pvc-name> -n <namespace>
Connection Refused to SQL Gateway
kubectl get svc -n xata sql-gateway
kubectl port-forward -n xata svc/sql-gateway 5432:5432
psql "postgresql://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME"
CLI Authentication Failures
xata auth login --profile local --env local --force
xata auth whoami
xata apikey list
Checking Scale-to-Zero Plugin
kubectl get plugins -A | grep scale-to-zero
kubectl get cluster <name> -n <namespace> -o jsonpath='{.metadata.annotations}'
Key Components Reference
| Component | Role |
|---|
| SQL Gateway | Connection routing, scale-to-zero wakeup, HTTP/WS serverless driver |
| Branch Operator | Kubernetes resource lifecycle per branch |
| clusters service | REST API for cluster management |
| projects service | REST API for project management |
| Auth service | Keycloak-based auth, RBAC API keys |
| CloudNativePG | HA Postgres, failover, backups, connection pooling |
| OpenEBS | Cloud-native storage (local NVMe or Mayastor replicated) |
Use Case Decision Guide
| Scenario | Use Xata OSS? |
|---|
| Internal Postgres-as-a-Service | ✅ Yes |
| Preview/testing/dev environments with CoW | ✅ Yes |
| Single Postgres instance | ❌ Use plain Postgres or managed service |
| Public PGaaS for end customers | ⚠️ Contact Xata for BYOC offering |