dbt-postgres Adapter

1.10.0 · active · verified Thu Apr 09

dbt-postgres is an adapter that enables dbt-core to connect and transform data within PostgreSQL databases. It provides the necessary protocols and base functionality for dbt to interact with Postgres, allowing data analysts and engineers to build data transformation pipelines using SQL. The library is currently at version 1.10.0 and follows the release cadence of dbt-core, with minor versions typically introducing new features and patches addressing bugs, aiming for backward compatibility for end-users.

Warnings

Install

Quickstart

This quickstart guides you through setting up a new dbt project with the `dbt-postgres` adapter. It covers installation, project initialization, `profiles.yml` configuration to connect to a PostgreSQL database, debugging the connection, and running a simple dbt model. Ensure you have a running PostgreSQL instance and replace the placeholder credentials in `profiles.yml` with your actual database details. Environment variables like `DBT_PG_USER` and `DBT_PG_PASSWORD` can be used for sensitive information.

# 1. Install dbt-core and dbt-postgres (if not already installed)
pip install dbt-core dbt-postgres

# 2. Initialize a new dbt project
dbt init my_postgres_project

# 3. Navigate into your project directory
cd my_postgres_project

# 4. Configure your profiles.yml (usually located at ~/.dbt/profiles.yml)
#    Replace placeholders with your PostgreSQL credentials. Example below:
#
#    my_postgres_project:
#      target: dev
#      outputs:
#        dev:
#          type: postgres
#          host: localhost
#          user: {{ env_var('DBT_PG_USER', 'postgres') }}
#          password: {{ env_var('DBT_PG_PASSWORD', 'mysecretpassword') }}
#          port: 5432
#          dbname: my_database
#          schema: public
#          threads: 4
#          keepalives_idle: 0
#          connect_timeout: 10

# 5. Verify your dbt connection
dbt debug

# 6. Create a sample model (e.g., models/my_first_model.sql)
#    Content of models/my_first_model.sql:
#    -- models/my_first_model.sql
#    select
#        1 as id,
#        'hello dbt!' as message

# 7. Run your dbt models
dbt run

# 8. Test your dbt models (if tests are defined)
dbt test

view raw JSON →