Skip to content
Latchkey

dbt "Database Error ... permission denied" in CI

dbt connected and authenticated successfully, then the warehouse rejected a DDL or DML statement because the CI role is not granted the privilege. The "Database Error" wraps the warehouse permission message.

What this error means

dbt run fails part-way with "Database Error in model X ... permission denied for schema analytics" (or "Insufficient privileges to operate on schema"). The connection works; the grant does not.

dbt
Database Error in model orders (models/marts/orders.sql)
  permission denied for schema analytics
  LINE 1: create table "analytics"."orders__dbt_tmp" as ...

Common causes

The CI role lacks create/write grants

The role dbt connects with can read but cannot create tables or write to the target schema, so the materialization DDL is rejected.

The target schema is owned by another role

dbt builds into a schema the CI role does not own and has not been granted usage/create on.

How to fix it

Grant the CI role the needed privileges

  1. Identify the schema named in the error.
  2. Grant usage and create on that schema to the CI role (and write on its tables).
  3. Re-run dbt so the materialization can build.
SQL
grant usage, create on schema analytics to role ci_dbt;
grant all on all tables in schema analytics to role ci_dbt;

Build into a CI-owned schema

Point the CI target at a schema the CI role owns, using a per-run or per-PR schema so permissions are clean.

Terminal
dbt run --target ci

How to prevent it

  • Grant the CI role explicit create/write on its target schema.
  • Use a dedicated CI target schema the CI role owns.
  • Review grants when adding new target schemas to the project.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →