ETLMCPData Conveyance Works
Log in Start free
Guides

PostgreSQL privileges for the etlmcp user

Why a first test or load fails with 'permission denied for schema public', and the grants the etlmcp login needs to create, fill and replace its table.

If the first test of a PostgreSQL destination fails with database error: permission denied for schema public, the login you gave etlmcp may not create tables in that schema. etlmcp creates its table when the table is missing, so the login needs the CREATE privilege on the schema, which is public unless you set another. Since PostgreSQL 15, a new database no longer gives every role that privilege on public, which is why a login that worked on an older server can fail on a new one. The other way in is a table that already exists, made by etlmcp, on which the login has INSERT, DELETE and SELECT.

What changed in PostgreSQL 15

Up to version 14, every role (the pseudo-role PUBLIC) could create objects in the public schema. PostgreSQL 15 removed that default and handed ownership of public to the pg_database_owner role, so each database owner holds owner rights there. The change applies to new clusters and to databases created after the upgrade. A cluster upgraded from an older version, or a database restored from a dump, keeps the permissions public had before, so the same login can work on one server and fail on another. Everyone still has USAGE on public by default, which lets a role look up objects there but not create them.

What etlmcp does with your login

Each load runs these statements, in this order:

  1. It reads information_schema.columns to find out whether the table exists and which columns it has.
  2. If the table is missing, it runs CREATE TABLE in your schema. This is the step that needs CREATE on the schema.
  3. It deletes this pipeline's own rows for the run's date range, matched on the _etlmcp_pipeline_id column and date.
  4. It inserts the new rows and commits.

The Test button does steps 1, 2 and an insert of one sample row, then rolls everything back. A passing test therefore proves CREATE (or an existing table) and INSERT, but not DELETE. A login without DELETE can pass the test and fail on its first real load.

DELETE alone is not enough for step 3. PostgreSQL's privileges chapter notes that in practice any nontrivial DELETE also needs SELECT, because it must read columns to pick the rows. Step 1 has a quieter dependency: the columns view lists only the columns of tables the current role owns or holds some privilege on. A login with no privilege at all on an existing table sees nothing, treats the table as missing and tries to create it, which fails.

The simplest setup: a schema the login owns

Give the etlmcp login its own schema. As the owner of the schema, it has CREATE and USAGE there, and it becomes the owner of the table it creates, so it can also add columns later. Run this as a role that may create schemas in the database:

CREATE ROLE etlmcp_loader LOGIN PASSWORD 'choose-a-long-password';
CREATE SCHEMA etlmcp AUTHORIZATION etlmcp_loader;

Then enter etlmcp_loader as the User and etlmcp as the Schema on the destination.

If you would rather keep the table in public, grant the privilege the version 15 default took away:

GRANT CREATE ON SCHEMA public TO etlmcp_loader;

For a schema other than public, also grant USAGE on it, since only public gives USAGE to everyone. New roles can connect to a database unless someone has revoked the default CONNECT privilege; if your server has, grant CONNECT on the database too.

Using a table someone else created

If your policy is that only an administrator creates tables, let etlmcp create the table once with a login that may, then hand the day-to-day work to a narrower login:

GRANT USAGE ON SCHEMA etlmcp TO etlmcp_loader;
GRANT SELECT, INSERT, DELETE ON etlmcp.ad_spend TO etlmcp_loader;

The table must be one etlmcp made: etlmcp refuses any existing table without its _etlmcp_pipeline_id column, so you cannot create the table by hand with your own column list.

In PostgreSQL, changing a table is part of owning it and cannot be granted. When a platform starts sending a new extra. field, etlmcp tries to add the column, and a login that does not own the table fails the load with table {…}.{…} is missing columns: {…}, naming the new columns. Columns that your transform rules make, and an id column, are left out of the load instead of failing it. To end those failures, add the columns as the owner or transfer ownership with ALTER TABLE etlmcp.ad_spend OWNER TO etlmcp_loader.

Is a permission error tried again?

No. A refused statement reaches you as database error: {…} followed by PostgreSQL's own first line, and etlmcp does not retry it, because waiting does not change a grant. Fix the privilege, press Test, then run the pipeline again. The PostgreSQL errors page lists every other message, and how rows are replaced explains which rows the DELETE touches.

For dashboards, give your BI tool a separate login that can only read; the read-only role guide covers it.

Related

Sources

  1. Release 15 — www.postgresql.org, checked
  2. 5.9. Privileges — www.postgresql.org, checked
  3. 5.11. Schemas — www.postgresql.org, checked
  4. 35.17. columns — www.postgresql.org, checked