Files
goclaw/internal/store/pg/pool.go
T
Viet Tran f3f4c67b36 Initial commit: GoClaw AI agent gateway
Multi-agent AI gateway with WebSocket RPC, HTTP API, and messaging channel integrations.
Go port of OpenClaw with multi-tenant PostgreSQL, per-user isolation, security hardening,
and production observability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:58:07 +07:00

29 lines
542 B
Go

package pg
import (
"database/sql"
"fmt"
"log/slog"
_ "github.com/jackc/pgx/v5/stdlib"
)
// OpenDB creates a database/sql connection to Postgres using pgx driver.
func OpenDB(dsn string) (*sql.DB, error) {
db, err := sql.Open("pgx", dsn)
if err != nil {
return nil, fmt.Errorf("open postgres: %w", err)
}
db.SetMaxOpenConns(25)
db.SetMaxIdleConns(10)
if err := db.Ping(); err != nil {
db.Close()
return nil, fmt.Errorf("ping postgres: %w", err)
}
slog.Info("postgres connected", "dsn_len", len(dsn))
return db, nil
}