---
title: PostgreSQL Store
description: Production-grade PostgreSQL store with automatic migrations.
---

The `store/postgres` package implements Shield's `store.Store` interface using the grove ORM with the PostgreSQL driver. It provides full support for all 11 Shield subsystems with automatic schema migrations managed by the grove orchestrator.

## Usage

```go
import (
    "context"
    "log"

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

db, err := grove.Open(pgdriver.Open("postgres://user:pass@localhost:5432/shield"))
if err != nil {
    log.Fatal(err)
}

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

## Tables

| Table | Subsystem | Purpose |
|-------|-----------|---------|
| `shield_instincts` | instinct | Built-in safety rules and threat patterns |
| `shield_awareness` | awareness | Context-aware detection configurations |
| `shield_boundaries` | boundary | Input/output boundary enforcement rules |
| `shield_values` | values | Value-alignment rule definitions |
| `shield_judgments` | judgment | Content evaluation and scoring rules |
| `shield_reflexes` | reflex | Automatic response and action triggers |
| `shield_profiles` | profile | Composite safety profile configurations |
| `shield_scans` | scan | Content scan results and audit log |
| `shield_policies` | policy | Organizational safety policy definitions |
| `shield_policy_tenants` | policy | Policy-to-tenant assignment mappings |
| `shield_pii_tokens` | pii | Tokenized PII storage for redaction/recovery |
| `shield_compliance_reports` | compliance | Generated compliance audit reports |

## Internals

| Aspect | Detail |
|--------|--------|
| Driver | grove ORM + pgdriver |
| Migrations | grove orchestrator with programmatic migrations |
| Transactions | PostgreSQL-level transactions |
| Concurrency | Full MVCC with concurrent readers and writers |

## When to use

- Production deployments requiring ACID guarantees and high concurrency.
- Multi-tenant environments with complex query patterns.
- Teams already running PostgreSQL in their infrastructure.
