Chronicle
1.x
Docs/Chronicle/PostgreSQL Store
Open

Reading2 min
Updated31 Jul 2026
Sourcev1/stores/postgres.mdx

The store/postgres package implements Chronicle's store.Store interface using the grove ORM with the PostgreSQL driver. It is the recommended store for production deployments.

Import01

import (
    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/pgdriver"
    "github.com/xraph/chronicle/store/postgres"
)

Constructor02

db, err := grove.Open(pgdriver.Open(os.Getenv("DATABASE_URL")))
if err != nil {
    log.Fatal(err)
}

s := postgres.New(db)

Migrations03

Run schema migrations before using the store. Migrations are idempotent -- safe to run on every startup:

if err := s.Migrate(ctx); err != nil {
    log.Fatal(err)
}

Full setup with chronicle.New04

import (
    "context"
    "log"
    "os"

    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/pgdriver"
    "github.com/xraph/chronicle"
    "github.com/xraph/chronicle/store"
    "github.com/xraph/chronicle/store/postgres"
)

ctx := context.Background()

db, err := grove.Open(pgdriver.Open(os.Getenv("DATABASE_URL")))
if err != nil {
    log.Fatal(err)
}

s := postgres.New(db)
if err := s.Migrate(ctx); err != nil {
    log.Fatal(err)
}

adapter := store.NewAdapter(s)

c, err := chronicle.New(chronicle.WithStore(adapter))

With the Forge extension05

import "github.com/xraph/chronicle/extension"

ext := extension.New(
    extension.WithStore(s),
    // Migrate runs automatically on Start unless WithDisableMigrate(true)
)
app.Register(ext)

Interfaces implemented06

postgres.Store satisfies:

  • audit.Store

  • stream.Store

  • verify.Store

  • erasure.Store

  • retention.Store

  • compliance.ReportStore

  • store.Store (composite)

Characteristics07

AspectDetail
Drivergrove ORM + pgdriver
Migrationsgrove migrator with embedded SQL
TransactionsDatabase-level ACID
Pingdb.Ping(ctx)
CloseCaller-owned -- call db.Close()