Render
Render Postgres is managed PostgreSQL that runs alongside your Render services. Load data into MotherDuck with DuckDB's PostgreSQL extension over the database's external URL, reading from a read replica to keep analytics off the primary.
Render Postgres is managed PostgreSQL that runs alongside your Render services. Because it's Postgres on the wire, DuckDB's PostgreSQL extension attaches it like any other Postgres database, and everything on Loading data from Postgres applies.
Attach a Render database
Every Render database has two URLs on its Info page in the Render Dashboard. The Internal Database URL only resolves for Render services in the same region, so MotherDuck can't reach it. Use the External Database URL.
Install and load the postgres extension, then attach the external URL. Render encrypts every external connection, so keep sslmode=require in the string:
INSTALL postgres;
LOAD postgres;
ATTACH 'md:';
ATTACH 'postgresql://<user>:<password>@<external_host>/<database>?sslmode=require'
AS render_db (TYPE postgres, READ_ONLY);
CREATE DATABASE IF NOT EXISTS analytics;
CREATE TABLE analytics.main.orders AS
SELECT * FROM render_db.public.orders;
Attaching read-only is a good default: it makes accidental writes back to your application database impossible.
To avoid putting credentials in the ATTACH string, store them in a secret first:
CREATE SECRET render_secret (
TYPE POSTGRES,
HOST '<external_host>',
PORT 5432,
DATABASE '<database>',
USER '<user>',
PASSWORD '<password>'
);
ATTACH '' AS render_db (TYPE postgres, SECRET render_secret, READ_ONLY);
Allow MotherDuck through the IP allow list
By default, a Render database accepts external connections from any IP address with valid credentials. If you've restricted inbound traffic with an IP allow list, add the addresses that will connect:
- For a load from a local DuckDB client, add your own public IP.
- For a load from a Flight, add the outbound IP addresses for your MotherDuck region, listed under Connecting to external systems.
The allow list applies only to external connections. Your Render services keep using the internal URL.
Read from a replica
Point the load at a read replica so a large scan doesn't compete with application traffic on the primary. A replica has its own external URL, so switching is a connection-string change. Render offers replicas on databases with at least 10 GB of storage and 0.5 CPU.
Load on a schedule with a Flight
For a recurring load, run the same extract from a Flight so it executes on MotherDuck compute on a cron rather than on a machine you maintain. The Postgres ingest Flight recipe is a ready-made starting point: point it at your Render external host and store the credentials as a Flight secret.
The Flight is the same extract wrapped in an entrypoint. Attaching with an empty connection string keeps the password in the environment rather than in a SQL statement:
import duckdb
def main():
con = duckdb.connect("md:")
con.execute("INSTALL postgres; LOAD postgres;")
con.execute("ATTACH '' AS render_db (TYPE postgres, READ_ONLY)")
con.execute(
"CREATE OR REPLACE TABLE analytics.main.orders AS "
"SELECT * FROM render_db.public.orders"
)
if __name__ == "__main__":
main()
Store the connection as a Flight secret named after the libpq environment variables, so the extension picks them up with no mapping:
CREATE SECRET render_creds IN MOTHERDUCK (
TYPE FLIGHTS,
PARAMS MAP {
'PGHOST': '<external_host>',
'PGPORT': '5432',
'PGDATABASE': '<database>',
'PGUSER': '<user>',
'PGPASSWORD': '<password>',
'PGSSLMODE': 'require'
}
);
Create the Flight with MD_CREATE_FLIGHT, passing that secret in flight_secret_names and a schedule_cron for the cadence you want.
For append-only tables, extract incrementally with a watermark instead of reloading the table. See Data loading patterns.
Things to know
- Free databases expire. A Free Render Postgres database expires 30 days after creation, and a scheduled load against it starts failing on that date. Use a paid instance for anything you schedule.
pg_duckdbis on Render's extension list. Render listspg_duckdbfor PostgreSQL 16 and later. That makes the pg_duckdb route, where Postgres itself connects out to MotherDuck, an alternative to the DuckDB-sideATTACHabove.- Row-by-row transfer has a ceiling. The
postgresextension is well-suited to one-time loads and backfills. For continuous replication of a busy table, use a change-data-capture tool such as Estuary or Streamkap.