DBLab Engine Documentation

repository·master·Indexed 25 days ago

https://github.com/postgres-ai/database-lab-engine

A high-performance PostgreSQL branching and cloning tool that uses Copy-on-Write (CoW) technologies like ZFS and LVM to create rapid, thin-cloned database environments for development, testing, and CI/CD. It supports self-managed PostgreSQL and managed services including AWS RDS, GCP Cloud SQL, Supabase, and Timescale, featuring a dedicated rds-refresh tool for automating RDS/Aurora snapshot refreshes.

Tokens
49.8K
Snippets
56
Records
254
Agent score
81%

What's inside DBLab Engine

  1. Overview of Database Lab Engine (DLE)

    master

    Database Lab Engine (DLE) provides ultra-fast, thin PostgreSQL cloning using Copy-on-Write (CoW) technologies. It allows developers to create full-sized database environments for development, testing, QA, and staging in seconds, regardless of the original database size.

    Key capabilities include:

    • Fast Cloning: A 1 TiB database can be cloned in approximately 10 seconds.
    • Broad Compatibility: Works with any PostgreSQL instance, including AWS RDS, GCP CloudSQL, Heroku, Digital Ocean, and self-managed instances.
    • Resource Efficiency: Dozens of independent clones can run on a single machine without significantly increasing hardware costs.
    • Automated Workflows: Supports API and CLI for automation, and includes a UI for manual tasks.
    • Data Protection: Features automatic cleanup of unused clones and a "Deletion Protection" flag to prevent accidental removal.
  2. Overview of DBLab Engine

    master

    DBLab Engine provides blazing-fast PostgreSQL cloning and branching using Copy-on-Write (CoW) technologies like ZFS (default) and LVM. It allows developers to build powerful development, test, QA, and staging environments by creating thin clones of production-like databases in seconds, regardless of size (e.g., a 1 TiB database can be cloned in ~10 seconds).

    Key capabilities include:

    • Rapid Environment Building: Create dozens of independent clones on a single machine without extra hardware costs.
    • CI/CD Integration: Automatically test database migrations and changes in pipelines.
    • Managed Service Support: Works with self-managed PostgreSQL and managed services like AWS RDS, GCP Cloud SQL, Supabase, and Timescale. For managed services where direct physical access is restricted, DBLab runs on a separate VM in the same region and auto-refreshes data to act as a database-as-a-service.
    • Data Provisioning: Supports both physical (pg_basebackup, WAL-G, pgBackRest) and logical (dump/restore) provisioning, including partial data retrieval (specific databases/tables) in logical mode.
  3. Key features of Database Lab Engine

    master

    Database Lab Engine (DLE) provides high-performance PostgreSQL database cloning and management with the following capabilities:

    • Fast Cloning: Create new database clones in seconds, regardless of size, using Copy-on-Write (CoW) technologies like ZFS (default) or LVM.
    • PostgreSQL Support: Supports versions 10 through 18.
    • Flexible Data Sourcing: Connect to any source (user-managed Postgres, AWS RDS, GCP CloudSQL, Azure, Yandex Cloud, etc.) without requiring ZFS or Docker on the production source. Supports physical (via pg_basebackup, WAL-G, pgBackRest) and logical (via dump/restore or S3) ingestion.
    • Cloning Modes:
      • Physical Mode: Supports a "sync container" for a continuously updated state (specialized replica).
      • Logical Mode: Supports partial restoration (specific databases or tables) and automated periodic full updates.
    • Advanced Management:
      • PITR: Ultra-fast Point in Time Recovery.
      • Lifecycle: Automatic deletion of unused clones, with an optional "protection from deletion" flag. Configurable snapshot cleanup policies.
      • Persistence: Clones survive DLE restarts and machine reboots.
      • Resource Control: Set Docker-compatible resource quotas (CPU, memory) for clones.
      • Configuration: Specialize Docker container parameters and PostgreSQL configuration settings specifically for clones, sync containers, or promote containers.
    • Observability: Provides a /healthz endpoint (unauthenticated) and an extended /status endpoint (authenticated). Supports a Netdata module.
    • Automation: Includes a UI for manual tasks, plus an API and CLI for automation.
  4. Core capabilities of Database Lab Engine

    master

    Database Lab Engine (DLE) provides high-speed PostgreSQL database cloning and management. Key features include:

    • Instant Cloning: Create new, ready-to-use clones in seconds regardless of database size using Copy-on-Write (CoW) technologies like ZFS (default) or LVM.
    • PostgreSQL Support: Supports versions 10 through 18.
    • Flexible Data Sourcing: Connect to any user-managed Postgres, AWS RDS, Yandex.Cloud, GCP CloudSQL, Azure, or Timescale Cloud. No changes are required on the source database.
    • Ingestion Modes:
      • Physical Mode: Supports pg_basebackup or backup tools like WAL-G and pgBackRest. Includes a "sync container" for continuous updates (acting as a specialized replica).
      • Logical Mode: Supports dump/restore or restoring from AWS S3. Allows partial restores (specific databases or tables) and automated periodic full updates.
    • Point in Time Recovery (PITR): Enables ultra-fast recovery to a specific moment in time.
    • Lifecycle Management: Automatic deletion of unused clones, configurable snapshot cleanup policies, and a "Delete Protection" option to prevent accidental removal.
    • Resilience: Clones survive DLE restarts and machine reboots.
    • Automation & Monitoring:
      • API and CLI for automation.
      • Docker-based architecture with customizable container parameters and resource quotas (CPU, memory).
      • Monitoring via /healthz (unauthenticated) and /status (authenticated) endpoints, plus a Netdata module.
    • Testing Tools: Includes DB Migration Checker for collecting artifacts useful for CI/CD database testing.
  5. How DLE achieves fast cloning via Copy-on-Write

    master

    DLE achieves high-speed, thin cloning by leveraging Copy-on-Write (CoW) technologies. This allows the engine to create new environments that share the underlying data blocks of the source until a change is made.

    DLE supports two primary technologies for CoW:

    1. ZFS (Default): DLE periodically creates new snapshots of the data directory and maintains a set of snapshots. Users can choose which snapshot to use when requesting a new clone. DLE manages the lifecycle by cleaning up old, unused snapshots.
    2. LVM (Logical Volume Manager for Linux).

    Because it uses CoW, the theoretical maximum number of snapshots and clones is $2^{64}$ when using ZFS.

  6. How DLE Thin Cloning Works

    master

    DLE utilizes Copy-on-Write (CoW) technology to enable rapid thin cloning. It supports two primary underlying technologies:

    1. ZFS (Default): DLE periodically creates snapshots of the data directory and maintains a set of snapshots. Users can choose which snapshot to use when requesting a new clone. DLE manages the lifecycle by cleaning up old, unused snapshots.
    2. LVM (Logical Volume Manager for Linux): An alternative CoW technology supported for thin cloning.

    Because it uses CoW, the clones are 'thin', meaning they only consume additional storage for the changes made to the data after the clone is created.

  7. Configure source databases using connection strings

    master

    DBLab supports full libpq connection strings for source database configuration. This allows you to pass all necessary parameters (such as sslmode, connect_timeout, sslrootcert, and options) directly to pg_dump and the engine's internal pgx connections.

    Supported formats include:

    • URI form: postgresql://...
    • Keyword/Value form: host=... port=... dbname=...

    While full connection strings are supported, you can still use discrete host, port, dbname, and username fields if preferred.

  8. Use Connection Strings for PostgreSQL Logical Dumps

    master

    Instead of providing discrete host, port, user, and database fields, you can provide a single connectionString in your configuration. This allows you to pass complex parameters like sslmode or connect_timeout directly to the underlying tools.

    Precedence Rules:

    • If connectionString is set, it wins. The engine derives the host, port, user, and database name from it for display and validation, ignoring any individual connection.* YAML fields.
    • The connectionString is passed directly to pg_dump using the -d flag.
    • Passwords are never inlined into the connection string; they are always managed separately via the Password field to ensure security.
  9. How Retrieval Modes (Logical vs Physical) affect configuration

    master

    The DBLab engine operates in two primary modes, which dictate how configuration updates are validated and processed:

    1. Logical Mode: Used for logical dump/restore operations. It uses GetStageSpec(logical.DumpJobType).
    2. Physical Mode: Used for physical backup/restore operations (e.g., WAL-G, pgBackRest). It uses GetStageSpec(physical.RestoreJobType).

    Field Gating Rules: To prevent invalid configurations, the engine enforces strict field gating based on the requested RetrievalMode:

    • Logical Mode rejects any fields prefixed with physical-*.
    • Physical Mode rejects logical-only fields, including:
      • host, port, user, dbname, password, databases
      • parallelism, customOptions, ignoreErrors
      • rdsIamDbInstanceIdentifier

    When updating configuration via the API, the mode is determined by the retrievalMode field in the incoming projection. If missing, it falls back to the current state of the engine's retrieval mode.

  10. Identify Deletable Snapshots and Branches

    master

    To prevent breaking lineage or losing data, the engine uses strict predicates to determine if an entity is a "true leaf" and safe to delete.

    Deletable Snapshot Criteria

    A snapshot is considered a true leaf (and thus deletable) only if:

    • dle:child is empty.
    • dle:root is empty.
    • dle:branch is empty (it is not a branch head).
    • It has zero clones (verified via GetCloneNumber).
    • It is not returned by getBranchHeadSnapshots().

    Warning: Do not rely on HasDependentEntity for this check, as it only tracks clones and does not account for child snapshots or branches.

    Deletable Branch Criteria

    A branch is deletable if:

    • None of its snapshots have clones.
    • No child branch forks from it (verified via a dependency walk).
  11. Understand Simple Mode Preview Warnings

    master

    When using the 'Detect & preview' feature in Simple Mode, the UI generates client-side warnings based on the probed configuration:

    • Generic Provider Warning: If the detected provider is Generic (or cannot be mapped to a managed service), a warning appears: "Could not detect a managed cloud provider; using the generic Postgres image. Switch to Expert mode if your source runs on a managed service and we missed it."
    • Memory Detection Warning: If host memory could not be detected (MemoryProbed == false), a warning appears: "Could not detect host memory; shared_buffers is set to a 1 GB safe default. Adjust in Expert mode if your host has more RAM."
    • Standard Notes: The preview always includes notes regarding the RDS-refresh-tool and shared_preload_libraries.
  12. How the Automated Sweeper Decides to Delete

    master

    The sweeper process runs periodically (based on checkIntervalMinutes) and evaluates each entity (snapshot or branch) using the following logic:

    1. Check Protection: If the entity is Protected, clear any delete_at values and skip deletion.
    2. Check Dependents: If the entity has dependents (clones, child snapshots, or child branches), clear the delete_at value (resetting the clock) and skip deletion.
    3. Schedule Deletion: If the entity has no dependents and delete_at is currently unset, set delete_at to now + retention (where retention is the configured unused minutes).
    4. Execute Deletion: If the entity has no dependents and now >= delete_at, trigger the deletion via destroySnapshotByID or destroyBranchByName.