ETLMCPData Conveyance Works
Log in Start free
Guides

Connect Tableau to the etlmcp PostgreSQL table

Tableau's PostgreSQL fields, the SSL box and driver, what Initial SQL does on refresh, why to skip pgBouncer, and Custom SQL for dotted extra columns.

To open the etlmcp table in Tableau, pick the PostgreSQL connector and enter the server, the port (5432 unless your server uses another), the database and a username and password, then tick the SSL check box and sign in. Connect straight to PostgreSQL rather than through pgBouncer, because Tableau expects each connection to keep its state. To read the platform extras, whose column names contain a dot, or to sum rows before Tableau sees them, write a Custom SQL query and put each extra name in double quotes.

The connection dialog

Under Connect, To a Server, choose PostgreSQL. Tableau asks for four things:

  • Server: the host name of your database. On a Mac, type the fully qualified name, or add the domain to the Mac's DNS search domains.
  • Port: 5432 by default.
  • Database: the database that holds the etlmcp table.
  • Authentication: Integrated Authentication (Kerberos) or a user name and password. Outside a Kerberos setup, a password-protected server needs the user name and password.

Use a login meant for reading, not the one etlmcp loads with. etlmcp's user has to own the table so it can add columns as new extras arrive; Tableau only needs to select. A read-only PostgreSQL role shows the grants, including the default privileges that cover a table created later.

Tick the SSL box when your server takes SSL connections. Tableau's PostgreSQL page labels it Required SSL. Any server that already receives etlmcp loads accepts encrypted connections: etlmcp connects with the require mode by default, and its production settings refuse any mode weaker than require, verify-ca or verify-full.

A firewall that admits only known addresses has to admit Tableau; IP addresses to allow for BI tools covers Tableau Cloud.

The driver

The PostgreSQL connector needs a driver on the machine that runs Tableau. When it is missing, the connection dialog says so and links to Tableau's driver download page.

Initial SQL runs when Tableau connects

The dialog's optional Initial SQL field holds a command that Tableau runs, or answers from a cached value, when it makes a connection: when you open the workbook, when an extract refreshes, when you sign in to Tableau Server and when you publish to it. Use it for session settings, not data shaping.

  • Tableau does not check the statement, so a mistake can break every refresh, including scheduled ones.
  • A Tableau Server administrator can switch Initial SQL off; the workbook still opens, but the command is not sent.

Because it runs again on every refresh, never put a statement there that writes to the etlmcp table. Each etlmcp run deletes its own pipeline's rows for the dates it covers and inserts them again, so anything Tableau writes into those rows is gone after the next load.

Why not pgBouncer

Tableau's PostgreSQL page advises against pgBouncer, since Tableau relies on stateful connections. If a pooler in front of your database cannot be avoided, keep server_reset_query=DISCARD ALL, which is pgBouncer's default. pgBouncer runs that reset only in session pooling (pool_mode=session, also the default), not in transaction or statement pooling, so a pool switched to those modes hands Tableau connections that still carry another session's state.

What the table looks like

etlmcp writes one table in the schema you chose (public by default). It starts with date as a real date column, then the IDs and names (network, account_id, account_name, campaign_id, campaign_name, adgroup_id, adgroup_name, ad_id, ad_name), then the metrics impressions, clicks, cost, conversions, conversion_value, ctr, cpc, cpm and cpa as double precision, then currency. After those come the platform extras, each named extra. plus the platform's own name, stored as double precision when they hold numbers and as text otherwise. Last is _etlmcp_pipeline_id, which tells apart the rows of different pipelines that load the same table.

So in Tableau, date lands as a date field and the metrics as measures with no casting. etlmcp computes ctr, cpc, cpm and cpa row by row from that row's clicks, impressions, cost and conversions: summing them across rows gives a wrong figure, so build those as calculated fields from the summed totals instead.

Custom SQL for extras and pre-aggregation

On the Data Source page, double-click New Custom SQL, paste one SELECT statement and click OK. Tableau wraps your query in its own SELECT, and Custom SQL can slow a workbook, so keep the query simple.

Two PostgreSQL rules matter for the extras. A name with a dot, unquoted, reads as a table and a column, so every extra needs double quotes; quoting also makes the name match case exactly. And PostgreSQL keeps at most 63 bytes of a name. etlmcp shortens a longer extra name itself, keeping its start and adding an underscore and an 8-character hash, so copy the exact name from the table's column list. Tableau's own Custom SQL examples use square brackets; those do not work against PostgreSQL. Give every column an alias with AS, as Tableau recommends, so the field names stay stable.

SELECT date,
       network,
       campaign_id,
       campaign_name,
       currency,
       SUM(impressions)      AS impressions,
       SUM(clicks)           AS clicks,
       SUM(cost)             AS cost,
       SUM(conversions)      AS conversions,
       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, network, campaign_id, campaign_name, currency

Replace public.ad_performance with your schema and table, the pipeline ID with yours, and "extra.some_metric" with an extra your table has. Grouping to campaign and day keeps an extract small when your table holds ad-level rows. Keep currency in the grouping so that spend in two currencies is never added together.

The setup fields on the etlmcp side are in PostgreSQL destination setup, and the way each run replaces its dates is in How PostgreSQL rows are replaced.

Related

Sources

  1. PostgreSQL — help.tableau.com, checked
  2. Run Initial SQL — help.tableau.com, checked
  3. Connect to a Custom SQL Query — help.tableau.com, checked
  4. Lexical Structure — www.postgresql.org, checked