Getting startedInstall CobaltDB and run your first SQL query in Go.SQL & JSONTables, indexes, parameterized queries, JSON and transactions.ArchitectureExplore disk-paged B+trees, bounded memory and crash recovery.Server & clientsConnect MySQL 8.4 clients and ORMs to the standalone server.Production guidePlan TLS, security, backups, observability and deployment boundaries.Performance benchmarksPaged storage, memory measurements and benchmark methodology.FeaturesSQL, transactions, encryption and a pure Go runtime.Brand assetsDownload the CobaltDB SVG logo and icon.
K to open ESC to close
Documentation

Getting started

Install CobaltDB and run your first SQL query in Go.

01. Add the module

CobaltDB’s embedded engine runs in your Go process. Use the current Go toolchain; v0.7.0 declares Go 1.26.0 and toolchain go1.26.10. No C compiler is required for the database runtime.

Install CobaltDBbash
mkdir hello-cobalt
cd hello-cobalt
go mod init example.com/hello-cobalt
go get github.com/cobaltdb/cobaltdb@v0.7.0

Import the engine from github.com/cobaltdb/cobaltdb/pkg/engine. The Go module resolves the library’s dependencies automatically.

02. Run your first query

Create a Go module, install CobaltDB, and save this complete program as main.go. It opens an in-memory database, creates a table, inserts a greeting and reads it back.

main.goGo
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/cobaltdb/cobaltdb/pkg/engine"
)

func main() {
    db, err := engine.Open(":memory:", nil)
    if err != nil { log.Fatal(err) }
    defer db.Close()

    ctx := context.Background()
    _, err = db.Exec(ctx,
        "CREATE TABLE IF NOT EXISTS greetings (message TEXT)")
    if err != nil { log.Fatal(err) }

    _, err = db.Exec(ctx,
        "INSERT INTO greetings VALUES (?)", "Hello, CobaltDB!")
    if err != nil { log.Fatal(err) }

    rows, err := db.Query(ctx, "SELECT * FROM greetings")
    if err != nil { log.Fatal(err) }
    defer rows.Close()
    for rows.Next() {
        var message string
        if err := rows.Scan(&message); err != nil { log.Fatal(err) }
        fmt.Println(message)
    }
}
Run the examplebash
go mod tidy
go run .
A clean start, every time. This example needs no files or server. Data is discarded when the program closes. Use persistent mode when your application needs data across restarts.

03. Choose your persistence mode

The example above uses in-memory mode. To persist data, open a file path with the default options. Keep the database and its WAL together, and validate durability and recovery on your deployment filesystem.

Persistent modeGo
db, err := engine.Open("app.db", nil)
if err != nil { log.Fatal(err) }
defer db.Close()

Tables and indexes live in checksummed 4 KiB disk pages. The default buffer pool caches 32,768 pages (128 MiB); opening a database reads its catalog rather than loading all table data.

Customize the page cacheGo
opts := engine.DefaultOptions()
opts.CoreStorage.CacheSize = 65536 // 256 MiB in 4 KiB pages
db, err := engine.Open("app.db", opts)
if err != nil { log.Fatal(err) }
defer db.Close()
Start custom options from engine.DefaultOptions(). A zero-valued options struct leaves background scheduling, automatic checkpoints and autovacuum disabled.

Where to go next

Learn the SQL and JSON workflow, explore the engine architecture, or run the standalone server.

The engine’s current API is available in pkg/engine on GitHub. Check errors returned by every statement and close rows when you are finished.

Source-aligned guide · CobaltDB v0.7.0Suggest an improvement