PostgreSQL
Use PostgreSQL when the destination is an application database or a small warehouse you already run. Mfd creates the schema and tables, then inserts rows. It does not use logical replication on the write path.
Before you begin
- The Mfd host can reach
host:port(default5432). - A role that can
CREATEon the target database (or an existingschemathe role owns). - Store the password in the environment. Do not put it in
mfd.yml.
bash
export POSTGRES_PASSWORD="change-me"Configure
python
from mfd import Config, DataSinkPostgres, EnvRef, Pipeline
cfg = Config.discover()
warehouse = cfg.data_sink(
"warehouse",
DataSinkPostgres(
host="localhost",
port=5432,
user="mfd",
password=EnvRef("POSTGRES_PASSWORD"),
database="analytics",
schema="public",
sslmode="prefer",
),
)
cfg.pipeline("files", Pipeline(data_source=cfg.get_data_source("sample"), data_sink=warehouse))
cfg.save()bash
mfd connect data-sink postgres \
--pipeline files \
--name warehouse \
--host localhost \
--port 5432 \
--user mfd \
--password '${POSTGRES_PASSWORD}' \
--database analytics \
--schema public \
--sslmode preferyaml
data_sinks:
warehouse:
Postgres:
host: localhost
port: 5432
user: mfd
password: ${POSTGRES_PASSWORD}
database: analytics
schema: public
sslmode: preferbash
mfd discover --pipeline files
mfd sync --pipeline files --once --logOptions
| Key | Type | Required/Default | Description |
|---|---|---|---|
host | string | localhost | PostgreSQL host |
port | integer | 5432 | Port |
user | string | Required | Database user |
password | secret | Not set | Password as ${ENV} |
database | string | Required | Database name |
schema | string | public | Schema for tables |
sslmode | string | Not set | libpq mode: disable, prefer, require |
How data lands
On the first sync Mfd runs CREATE SCHEMA IF NOT EXISTS and creates tables to match the discovered schema. New columns are added later. Each batch is inserted as rows. Retries are exactly once — see Exactly-once delivery.
Source namespaces become tables in schema. Prefer a dedicated schema so Mfd tables stay out of the application schema.
Troubleshooting
| Symptom | Fix |
|---|---|
| Connection refused | Check host, port, and that PostgreSQL accepts connections from this machine |
| Password authentication failed | Export the variable named in password in this shell |
permission denied for schema | GRANT CREATE on the schema, or let Mfd create one the role owns |
| SSL required / SSL off | Match sslmode to the server (require vs disable) |
Next steps
- PostgreSQL source — read from a different database
- Quickstart: PostgreSQL
- Exactly-once delivery
