ETLMCPData Conveyance Works
Log in Start free
Docs

PostgreSQL destination setup

The fields a PostgreSQL destination needs, how etlmcp connects to your server, and what it does to your table on the first test and the first load.

To send your ad data to PostgreSQL, you give etlmcp the connection details and a password: the host, the database, the user and the table are required, while the port defaults to PostgreSQL's standard port, 5432, and the schema defaults to public. etlmcp connects over an encrypted connection, only to a host on the public internet, and creates the table the first time it loads if the table is not there yet.

The fields

Field Required What to enter
Host yes The server's public hostname or IP address, with no port, no user@ and no path.
Port no A whole number. Left empty, it is 5432, the port PostgreSQL listens on unless its server is set up otherwise.
Database yes The database name (dbname).
User yes The login etlmcp connects as.
Schema no The schema that holds the table. Left empty, it is public.
Table yes The table etlmcp writes to.
Password yes The user's password. It is stored as a secret and kept with this host, port and user.

A missing required field is refused with {…} field(s) required: {…}, where the first part reads config (or secret for a missing password) and the second names the missing fields, and a port outside the range is refused with port must be a whole number from 1 to 65535.

etlmcp writes the schema and table names exactly as you type them, inside double quotes. PostgreSQL itself folds unquoted names to lower case and by default keeps at most 63 bytes of a name, so a table called AdSpend has to be written "AdSpend" in your own queries. The schema must already exist, and the user needs permission to create a table in it: etlmcp creates the table, not the schema.

If you later change the host, the port or the user, etlmcp asks for the password again; secrets bound to a host explains why.

How etlmcp connects

Every connection asks for TLS with the sslmode setting require by default, and the production service refuses to start with any mode weaker than that. In PostgreSQL's own terms, require protects the connection from eavesdropping but is not the mode meant for checking the server's identity; that is what verify-ca and verify-full are for. Your server must accept SSL connections. A server that only takes unencrypted connections cannot be used.

Before it connects, etlmcp looks up the host and refuses it if any of its addresses is private, loopback, link-local, reserved or otherwise not on the public internet. Such a host fails with host not allowed, so a server reachable only inside a private network cannot be a destination. A new PostgreSQL server listens only on localhost by default, so on a self-hosted server you also have to change listen_addresses and add a pg_hba.conf entry that lets etlmcp's login in, because PostgreSQL turns away a connection that matches no entry there. If your firewall allows connections by address, the destinations page in the app shows the address etlmcp connects from, when the server has one set.

etlmcp sets time limits on the connection attempt, on each statement and on a whole load or test, so a server that stops answering cannot hold a run for ever. A load or test that runs past its overall limit fails with the database did not answer in time. A connection that fails for another reason, such as a server that cannot be reached, fails with could not connect: {…} followed by the driver's first line of explanation, with your password removed. In a run, etlmcp treats both as failures that can pass, so the run is tried again as described on the retries page. A wrong password fails with could not connect: authentication failed, and a database name that does not exist fails with could not connect: database does not exist; neither of these is retried.

Testing the destination

The Test button connects with your settings, inserts a sample row into the table and rolls it back, so nothing stays in your database. If the table does not exist yet, the test creates it inside the same transaction, and the rollback removes it again. When it works, you see Connected to PostgreSQL {…}; {…}.{…} is ready to load., with your server's major version and the schema and table. A passing test proves the login can reach the server and write to that table.

The table etlmcp creates

On the first load, etlmcp creates the table with a column for each field in your rows. The date column is a PostgreSQL date, the metric columns, such as impressions, clicks and cost, are double precision, and most other columns are text. It adds a column of its own, _etlmcp_pipeline_id, which records which pipeline wrote each row.

Platform-specific fields arrive as columns whose names start with extra.. Because the name contains a dot, you write it in double quotes in SQL. When a later run brings a new extra field, etlmcp adds that column to the existing table.

etlmcp only writes to tables it created. If the table you name already exists and lacks the _etlmcp_pipeline_id column, the test and every load stop with table {…}.{…} was not created by etlmcp; choose a new table name.

Each run then replaces its own date range in the table and leaves other rows alone. See how rows are replaced.

Related

Sources

  1. SSL Support — www.postgresql.org, checked
  2. Connections and Authentication — www.postgresql.org, checked
  3. Lexical Structure — www.postgresql.org, checked
  4. The pg_hba.conf File — www.postgresql.org, checked