ETLMCPData Conveyance Works
Log in Start free
Guides

Connect Metabase to the etlmcp PostgreSQL table

How to point Metabase at the table etlmcp loads: a read-only user, SSL mode, schema filter, sync and fingerprint settings, and Metabase Cloud's IPs.

To put the etlmcp table in Metabase, add your PostgreSQL database under Admin, then Databases, and log in as a dedicated read-only user, not the user etlmcp loads with. Turn SSL on with a mode that refuses plain connections, limit the schema filter to the schema that holds the table, and leave periodic refingerprinting off unless you need fresh column statistics. If you use Metabase Cloud, allow its three addresses for your region in your firewall.

What Metabase will find

etlmcp writes one ordinary table, in the schema you chose for the destination (public unless you set another). Its common columns come first, in this order, and any others follow:

Columns PostgreSQL type
date date
network, account_id, account_name, campaign_id, campaign_name, adgroup_id, adgroup_name, ad_id, ad_name text
impressions, clicks, cost, conversions, conversion_value, ctr, cpc, cpm, cpa double precision
currency text
platform extras, named extra.<name> double precision for metrics etlmcp knows are numbers, otherwise text
columns your transform rules add double precision or text
_etlmcp_pipeline_id text, never empty

Several pipelines can load the same table; _etlmcp_pipeline_id tells their rows apart, so add it as a filter on any question that should show one pipeline. Each run deletes its own pipeline's rows for the dates it covers and inserts them again, so Metabase never sees duplicates from a rerun. How PostgreSQL rows are replaced has the detail.

Because date is a real date column and the metrics are numbers, Metabase's query builder can group by day, week or month and sum the metrics without any casting. Nested values from a platform are stored as JSON text in a text column, not as a json column, so Metabase's JSON unfolding setting does not apply to them.

Create a read-only user for Metabase

Keep the etlmcp loading user separate from the Metabase user: etlmcp creates the table, and adds a column each time a platform returns a new extra, so its user needs to own the table. When it does not, the load fails because of the missing columns.

The table does not exist until the first load. The connection test in etlmcp creates it inside a transaction and rolls it back, so nothing stays behind. Grant access after the first load, or set default privileges for the loading role so that a table it creates later is readable at once:

CREATE ROLE metabase_reader LOGIN PASSWORD 'replace-me';
GRANT CONNECT ON DATABASE marketing TO metabase_reader;
GRANT USAGE ON SCHEMA public TO metabase_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metabase_reader;
ALTER DEFAULT PRIVILEGES FOR ROLE etlmcp_loader IN SCHEMA public
    GRANT SELECT ON TABLES TO metabase_reader;

Replace marketing, public and etlmcp_loader with your database, schema and loading user. In PostgreSQL, GRANT ... ON ALL TABLES reaches only the tables that exist when you run it, and default privileges reach only tables the named role creates afterwards. A table-level SELECT covers every column of the table, so the extra columns etlmcp adds later are readable without a new grant.

Connection fields and SSL

Fill in the host, port (usually 5432), database name, the read-only username and its password.

Metabase offers five SSL modes: allow, prefer, require, verify-ca and verify-full. The two verify modes need the server's root certificate as a PEM file; on Metabase Cloud you upload it. With SSL on, Metabase tries an encrypted connection first and connects without encryption if that fails. In PostgreSQL's own terms, allow and prefer may end up unencrypted, while require, verify-ca and verify-full fail instead; verify-full also checks that the host name matches the certificate. Pick one of the last three if your data should never travel in plain text.

etlmcp holds itself to the same rule on the loading side: it connects with require by default, and its production configuration refuses any mode other than require, verify-ca or verify-full. A database that already accepts etlmcp therefore accepts encrypted connections.

Schema filter

The schemas setting has three choices: All, Only these, and All except. The last two take a comma-separated list, and the only pattern character they understand is *; no other wildcards or regular expressions work. Set Only these to the schema of the etlmcp table so the sync reads nothing else.

Syncs, scans and fingerprinting

  • Sync reads table and column names and types. It runs hourly by default.
  • Scan reads the distinct values that fill filter dropdowns, such as campaign names. It runs daily by default.
  • Fingerprinting samples the first 10,000 rows of each column to estimate distinct counts and minimum and maximum values. By default it runs once, at setup.

The option Periodically refingerprint tables repeats fingerprinting on every sync, which Metabase warns adds load to your database. On a small server that etlmcp also writes to, keep it off. You can change sync and scan times under Choose when syncs and scans happen in the connection's advanced options.

A new extra column appears in Metabase only after the next sync. If you need it sooner, click Sync database schema on the database's admin page. A new campaign name shows in a filter dropdown after the next scan; you can re-scan a single table from Table Metadata.

Metabase Cloud addresses

Metabase Cloud reaches your database from three fixed addresses per region, and your firewall or security group has to allow them. In US East (North Virginia, us-east-1) they are 18.207.81.126, 3.211.20.157 and 50.17.234.169. Frankfurt, Singapore, Sydney and São Paulo each have their own three; take them from Metabase's list for the region your instance runs in. A self-hosted Metabase connects from your own server instead.

Querying extras in native SQL

Extra column names keep their dot, so in a native SQL question PostgreSQL reads them as a table and a column unless you put the name in double quotes. PostgreSQL also limits names to 63 bytes; etlmcp shortens a longer extra name and adds a short hash, so check the exact name in Metabase's table metadata.

SELECT date,
       campaign_name,
       SUM(cost) AS cost,
       SUM(conversion_value) AS conversion_value,
       SUM("extra.some_metric") AS some_metric
FROM public.ad_performance
WHERE _etlmcp_pipeline_id = 'your-pipeline-id'
GROUP BY date, campaign_name
ORDER BY date;

Replace public.ad_performance with your schema and table, and "extra.some_metric" with an extra your table has. Setup fields for the destination are in PostgreSQL destination setup, and load failures are explained in PostgreSQL errors.

Related

Sources

  1. PostgreSQL — www.metabase.com, checked
  2. IP addresses to whitelist — www.metabase.com, checked
  3. Syncing and scanning databases — www.metabase.com, checked
  4. SSL Support — www.postgresql.org, checked
  5. GRANT — www.postgresql.org, checked
  6. Lexical Structure — www.postgresql.org, checked
  7. ALTER DEFAULT PRIVILEGES — www.postgresql.org, checked