---
title: PostgreSQL Store
description: Production-ready PostgreSQL store using grove ORM with pgdriver.
---

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.

## Import

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

## Constructor

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

s := postgres.New(db)
```

## Migrations

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

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

## Full setup with `chronicle.New`

```go
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 extension

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

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

## Interfaces implemented

`postgres.Store` satisfies:

- `audit.Store`
- `stream.Store`
- `verify.Store`
- `erasure.Store`
- `retention.Store`
- `compliance.ReportStore`
- `store.Store` (composite)

## Characteristics

| Aspect | Detail |
|--------|--------|
| Driver | grove ORM + pgdriver |
| Migrations | grove migrator with embedded SQL |
| Transactions | Database-level ACID |
| Ping | `db.Ping(ctx)` |
| Close | Caller-owned -- call `db.Close()` |
