Skip to content
Docs

How-to: Use an external database

Connect a flow to your own database server: PostgreSQL, MySQL, MariaDB or SQL Server. You store its connection details once as a secret, then run SELECT queries with Database Select and write rows with Database Insert, Database Upsert or Database Execute. This guide walks through the full setup.

A SQLite database is a file rather than a server, so the Database nodes do not open one. Read it with Read a File as Data instead.

Step 1 — Create a database credential secret

Section titled “Step 1 — Create a database credential secret”

The Database nodes connect with a secret of type Database Credentials, so the password never sits in the flow.

  1. Open Connections, then its Secrets tab, and click New secret.

  2. Choose Database Credentials as the type.

  3. Fill in the connection details:

    FieldExample
    EnginePostgreSQL (or MySQL, MariaDB, SQL Server)
    Hostdb.example.com
    Port5432
    Dbnameproduction
    Usernameapp_user
    Password••••••
    The Content step of Create secret for database credentials: Engine, Dbname, Host, Port, Username and Password
    The Content step of Create secret for database credentials: Engine, Dbname, Host, Port, Username and Password
  4. Click Create. Note the secret’s name: you select it in the node panel.

  1. Drop a Database Select node onto the canvas from the node picker’s Storage shelf.

    The Add a node picker searched for Database, listing Database Execute, Database Insert and Database Select under Storage, each with a line on what it does
    The Add a node picker searched for Database, listing Database Execute, Database Insert and Database Select under Storage, each with a line on what it does
  2. Pick your credential secret as the node’s credentials.

  3. Write your SQL SELECT, with a bare :name placeholder for each dynamic value:

    SELECT id, name, email
    FROM customers
    WHERE account_id = :accountId AND active = true
    ORDER BY id ASC
    LIMIT 100
  4. Add the matching value under Parameters. Each key matches a :placeholder in the query, and each value is an expression:

    accountId → {{ $start->accountId }}

    The database driver binds each value, so the value never becomes part of the SQL text. Do not wrap a placeholder in quotes: ':accountId' is a string literal, not a placeholder.

The node emits a JSON array of row objects.

If you need to run a statement that does not return rows (CREATE, ALTER, DROP, TRUNCATE, DELETE, or a bulk UPDATE), use Database Execute instead. It has the same shape and emits { "ok": true }.

After processing, write results with Database Insert:

  1. Drop a Database Insert node.
  2. Select the same credential secret.
  3. Set Table to the target table name (e.g. processed_events).

The incoming JSON keys must match the column names. Use a Mapper or Transformer upstream to rename or reshape.

Use Database Upsert when the same row might arrive more than once. The node uses the table’s unique constraints to decide whether to insert or update — making the flow idempotent.

Each statement a Database node runs may take at most 10 minutes. After that your database stops it (for SQL Server, its driver does), and the step fails without a retry, because the same query against the same data would only be stopped again. Make a slow query cheaper with an index, a narrower WHERE or a LIMIT, or read the rows in pages.

On MySQL the limit stops a SELECT. An INSERT, UPDATE or DELETE there is limited only in how long it waits for a lock. PostgreSQL, MariaDB and SQL Server stop any statement.

Use extraCredentials to override individual connection settings on top of the chosen secret. Each key is a connection field such as host or database, and each value is fixed text merged over the secret’s value before the node connects:

host → replica.example.com
database → analytics

The values are plain text, not expressions. To point the same flow at a different database server per customer, create one database credentials secret per server and select the matching secret in the node.

  • Never paste database passwords directly into a node’s configuration — always use a Secret.
  • Use least-privilege database users: the account used by query nodes should only have SELECT; the account for insert/upsert nodes should only have INSERT/UPDATE.
  • Pass every dynamic value through Parameters with a bare :name placeholder in the SQL. The database driver binds each value, so a value containing quotes or SQL fragments cannot change the query. Keep upstream data out of the SQL text itself: echoing a value into the SQL body bypasses binding.