dbt-postgres
The official dbt adapter that lets dbt compile and run SQL transformations against PostgreSQL.
Repository Health
Technical Analysis
dbt-postgres is the first-party adapter that connects dbt (data build tool) to PostgreSQL databases. It translates dbt’s model compilation, materialization strategies, and macros into Postgres-compatible SQL, letting analytics engineers run version-controlled, testable transformation pipelines directly against a Postgres warehouse. It ships as part of the dbt-labs/dbt-adapters monorepo alongside adapters for Snowflake, BigQuery, Redshift, and other warehouses.
What You Get
- A Postgres-specific dbt adapter implementing connections, relations, and column introspection via psycopg2
- Materialization macros (table, view, incremental, snapshot, materialized view) tuned for Postgres SQL syntax
- Automatic dependency management pulling in dbt-core, dbt-adapters, dbt-common, and agate at compatible versions
- Support for Postgres-specific features like materialized views and index management from dbt config
- Continuous compatibility testing against new dbt-core releases via the shared dbt-adapters monorepo test suite
Common Use Cases
- Running dbt transformation pipelines against a self-hosted or managed Postgres data warehouse
- Local development and CI testing of dbt projects using Postgres as a lightweight substitute for a cloud warehouse
- Building analytics engineering workflows (staging → intermediate → mart models) on top of an existing Postgres application database
- Powering dbt Cloud or dbt Core scheduled jobs that target Postgres as the target adapter
Under The Hood
Architecture: dbt-postgres is a thin adapter layer over dbt-adapters’ base adapter protocol, implementing a PostgresAdapter (impl.py), PostgresConnectionManager (connections.py), and PostgresRelation/PostgresColumn classes that plug into dbt-core’s plugin discovery system; SQL generation is driven by Jinja macros under src/dbt/include/postgres/macros covering materializations, catalog queries, and cross-database utility functions like dateadd/datediff/listagg. Tech Stack: Pure Python 3.10+, built with hatchling, depending on psycopg2-binary for the DB driver, dbt-adapters/dbt-common for the shared adapter contract, and agate for in-memory result handling; the package is one of six first-party adapters in the dbt-labs/dbt-adapters monorepo, released independently but tested together via a shared CI pipeline. Code Quality: The repo enforces black formatting and mypy type checking, has dedicated tests/unit and tests/functional suites run via pytest with parallel execution (-n auto), and dependency version ranges are pinned conservatively (e.g. dbt-core>=1.8.0rc1,<2.0) to avoid breaking installs. API Design: Developers rarely import dbt-postgres directly — it’s installed as a dbt plugin and configured entirely through a profiles.yml connection block (host/port/user/password/dbname), so the real ergonomics surface is macro coverage and error messages during dbt run, which are generally clear and Postgres-specific.
Used by 2 apps in this directory
Elementary
Data Engineering · Monitoring · Analytics
The dbt-native data observability CLI that turns your existing dbt tests and metadata into anomaly detection, lineage graphs, and Slack/Teams alerts — no separate platform required.
PostgresML
Databases · AI Development
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.