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.
pip install dbt-core dbt-postgresNo compatibility data collected yet for this library.
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.
Upgrade Python to version 3.9 or newer (e.g., Python 3.10, 3.11, 3.12, or 3.13).
When installing, use `pip install dbt-core dbt-postgres` (or your specific adapter) to ensure both are present.
To use `psycopg2` instead of `psycopg2-binary`, first uninstall `psycopg2-binary`, then `export DBT_PSYCOPG2_NAME=psycopg2` before installing `dbt-postgres`.
Ensure you understand whether your dbt setup requires local `profiles.yml` management or leverages dbt Cloud's integrated connection settings.
When defining or referencing dbt engine-specific environment variables, prefer the `DBT_ENGINE_` prefix where applicable, and be aware of this distinction to avoid naming collisions.
Ensure dbt-core and the dbt-postgres adapter are correctly installed using pip: `python -m pip install dbt-core dbt-postgres`
Verify the `host`, `port`, `user`, `password`, and `dbname` in your `profiles.yml` file match your PostgreSQL server configuration exactly. Ensure the PostgreSQL server is running and network access is permitted from where dbt is being run.
Run `dbt run` to materialize all necessary models. Double-check your `schema.yml` and `dbt_project.yml` for correct schema configurations and verify that `ref()` and `source()` calls accurately point to existing models or sources. Also, confirm the dbt user has `SELECT` permissions on the relevant schemas.
Grant the required permissions to your dbt user on the PostgreSQL database. For example, to grant usage and all table permissions on a schema: `GRANT USAGE ON SCHEMA <schema_name> TO <dbt_user>;` and `GRANT ALL ON ALL TABLES IN SCHEMA <schema_name> TO <dbt_user>;`
Explicitly cast the port environment variable to an integer in your `profiles.yml` using Jinja templating, like: `port: "{{ env_var('DB_PORT') | int }}"`.