Skip to main content
Provides PostgreSQL database configuration for agent session history, chat storage, and memory persistence.

agno/db/postgres

Config

Supports two connection patterns: Option 1 — Connection URL:
FieldTypeRequiredDefaultDescription
connection_urlField[string]YesFull PostgreSQL connection URL. Supports FieldReferences
usernameField[string]NoUsername to inject into the URL (if not already in URL)
passwordField[string]NoPassword to inject into the URL (if not already in URL)
Option 2 — Separate fields:
FieldTypeRequiredDefaultDescription
hostField[string]YesDatabase host (IP or hostname)
portintegerNo5432Database port
databaseField[string]YesDatabase name
usernameField[string]YesDatabase username
passwordField[string]YesDatabase password
Common fields:
FieldTypeRequiredDefaultDescription
db_schemastringNo"ai"Database schema for Agno tables
session_tablestringNoCustom table name for sessions
memory_tablestringNoCustom table name for memories

Outputs

FieldTypeDescription
specobjectSerialized database spec for runtime reconstruction

Dependencies

Depends on: Nothing directly, but fields support FieldReferences (e.g., from gcp/cloudsql outputs). Depended on by:
  • agno/agent — in the db field
  • agno/team — in the db field
  • agno/memory/manager — in the db field
  • agno/knowledge — in the contents_db field

Example — Using Cloud SQL outputs

provider: agno
resource: db/postgres
name: agent-db
config:
  host:
    provider: gcp
    resource: cloudsql/database
    name: app-db
    field: outputs.host
  port: 5432
  database:
    provider: gcp
    resource: cloudsql/database
    name: app-db
    field: outputs.database_name
  username:
    provider: gcp
    resource: cloudsql/user
    name: agent-user
    field: outputs.username
  password:
    provider: pragma
    resource: secret
    name: db-password
    field: outputs.DB_PASSWORD
  db_schema: ai

Example — Using connection URL

provider: agno
resource: db/postgres
name: agent-db
config:
  connection_url:
    provider: gcp
    resource: cloudsql/database
    name: app-db
    field: outputs.url
  username:
    provider: gcp
    resource: cloudsql/user
    name: agent-user
    field: outputs.username
  password:
    provider: pragma
    resource: secret
    name: db-password
    field: outputs.DB_PASSWORD

Notes

  • You must provide either connection_url or host + database. When using separate fields, username and password are also required.
  • Credentials in the URL take precedence — if the URL already contains credentials, the separate username/password fields are ignored.
  • The db_schema defaults to "ai". Agno creates tables within this schema automatically at runtime.
  • This resource is stateless — it does not create the database itself. Use gcp/cloudsql/database to provision the actual database.