skip to content

What is an Amazon Redshift federated query to RDS or Aurora, and when should you use one?

level: middleimportance: should knowfreq 40%

answer

  1. some data is too fresh to have been loaded yet
  2. the warehouse reaches into the live system
  3. read-only, and the password is not in the DDL
  4. the other end is a production OLTP database
  5. great for a small lookup, terrible for a scan

basics

~20 s

A federated query lets Redshift read live tables in RDS or Aurora PostgreSQL and MySQL directly, through an external schema created with FROM POSTGRES or FROM MYSQL. Use it for small, fresh operational lookups — never to scan a large transactional table.

solid answer

~50 s

You create an external schema pointing at the operational database — `CREATE EXTERNAL SCHEMA ... FROM POSTGRES DATABASE '...' SCHEMA 'public' URI '<endpoint>' IAM_ROLE '...' SECRET_ARN '...'` — with credentials held in AWS Secrets Manager and network reachability from the cluster's VPC. Its tables then appear queryable and joinable alongside warehouse tables, but the query executes against the **live OLTP database**, read-only. Redshift pushes down what it can (filters, some aggregation); anything it cannot push comes back row by row over the network. That makes federated query excellent for a small, must-be-current lookup — the latest order status, a slowly changing dimension you refuse to ETL, a reconciliation check against the source of truth — and a bad idea for anything resembling a fact-table scan, which loads the production database and runs slowly. The usual production pattern is to materialise the federated result into a local staging table once and query that.

code

sql · 7 lines
sql
CREATE EXTERNAL SCHEMA ops
FROM POSTGRES
DATABASE 'appdb'
SCHEMA 'public'
URI 'prod-app.abcdefg.eu-west-1.rds.amazonaws.com'
IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftFederatedRole'
SECRET_ARN 'arn:aws:secretsmanager:eu-west-1:123456789012:secret:appdb-reader';

go deeper

for a junior

Recall that Redshift can read live RDS or Aurora tables through an external schema, read-only, and that it suits small current-state lookups rather than bulk data.

for a middle

Explain the wiring — FROM POSTGRES or FROM MYSQL, a Secrets Manager ARN, an IAM role, VPC reachability — and what gets pushed to the source versus pulled back over the network.

for a senior

Show the production judgment: bound every federated read with a filter, land it in a temp or staging table once, and keep dashboards away from the operational database entirely.

for a principal

Own where the boundary sits — which freshness requirements justify reaching into production at all, versus investing in CDC, and who is accountable when a warehouse query degrades the application.

## What it is Amazon Redshift **federated query** lets a warehouse query read directly from a live operational database — Amazon RDS or Aurora, PostgreSQL or MySQL flavour — without any ETL hop. Like Spectrum, it is exposed as an external schema, but the source is a running database rather than files in S3: ```sql CREATE EXTERNAL SCHEMA ops FROM POSTGRES DATABASE 'appdb' SCHEMA 'public' URI 'prod-app.abcdefg.eu-west-1.rds.amazonaws.com' IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftFederatedRole' SECRET_ARN 'arn:aws:secretsmanager:eu-west-1:123456789012:secret:appdb-reader'; ``` After that, `ops.customers` is queryable and joinable with `dim_customer`, `fact_orders` or a Spectrum external table in the same statement. ## The moving parts - **Credentials** live in AWS Secrets Manager; the cluster's IAM role must be allowed to read that secret. You never put a password in DDL. - **Connectivity** is network-level: the cluster must reach the RDS/Aurora endpoint, which means VPC routing and security-group rules that admit the cluster. - **Access is read-only.** Federated query does not write to the source. - **A dedicated read-only database user** on the source is the right credential to store — this is a production OLTP system and the warehouse should not be able to alter it. ## What execution actually looks like Redshift pushes down what the remote engine can evaluate cheaply — predicates, and some aggregation and projection — so a filtered lookup often becomes a small indexed query on the source. What it cannot push down it must materialise: rows stream across the network into the cluster, and the rest of the plan runs there. That asymmetry is the whole story. `SELECT * FROM ops.orders WHERE order_id = 12345` is a point lookup on an indexed column and costs the source almost nothing. `SELECT count(*) FROM ops.orders o JOIN fact_shipments f ON ...` over three years of orders is a full scan of a production table that also competes with live user traffic for its buffer cache — and the OLTP database is row-stored, so it is exactly the wrong engine for that scan. ## When it is the right tool - **Freshness beats volume.** A small dimension that must reflect the last few seconds — entitlement state, current subscription tier, an operational status flag. - **Avoiding a pipeline for a small table.** Building and monitoring a CDC pipeline for a 20,000-row reference table is not worth it. - **Reconciliation.** Comparing warehouse aggregates against the source of truth to prove a load was complete. - **Late-binding lookups** in an otherwise warehouse-native query, where the joined set is already narrowed to a handful of keys. ## When it is the wrong tool - Scanning or aggregating a large transactional table. Use CDC or a scheduled extract into Redshift instead. - Anything a business dashboard hits repeatedly — every refresh is load on production. - Building a permanent "virtual warehouse" over the OLTP schema. Federated query is a bridge, not an architecture. ## The production pattern The safe shape in a scheduled job is to pull once and reuse: ```sql CREATE TEMP TABLE recent_customers AS SELECT customer_id, tier, updated_at FROM ops.customers WHERE updated_at >= dateadd(day, -1, current_date); -- every subsequent join reads the local copy SELECT ... FROM fact_orders f JOIN recent_customers c ON c.customer_id = f.customer_id; ``` One bounded, filtered read against production; everything else local. This also makes the query deterministic: without it, two references to a federated table in one statement can see the source at different moments. ## Contrast with Spectrum Both are external schemas, and that similarity misleads people. Spectrum reads immutable files from S3 with a managed scan fleet and a per-byte-scanned charge; its scaling limit is S3 and file layout. Federated query reads a live, row-stored transactional database over a network connection; its scaling limit is **the production database's capacity**, and the cost of getting it wrong is paid by your users, not by your AWS bill.

  • How do the credentials for a federated external schema reach the source database?
    You store a username and password for a read-only user in AWS Secrets Manager and reference the secret's ARN in `CREATE EXTERNAL SCHEMA`. The cluster's IAM role must be permitted to read that secret. No password appears in DDL or system tables, and rotating the secret does not require redefining the schema.
  • What is the main risk of joining a large federated table to a warehouse fact table?
    You force a large scan on a live, row-stored transactional database that is simultaneously serving users. It evicts their working set from the buffer cache, adds latency to the application, and returns slowly because OLTP storage is not built for analytical scans. Extract to a local table on a schedule instead.
  • How does federated query differ from Spectrum, given both use external schemas?
    Spectrum reads immutable files in S3 through an AWS-managed scan fleet, billed by bytes scanned, and scales with file layout. Federated query opens a connection to a live RDS or Aurora database and is bounded by that database's capacity. The failure mode differs too: a bad Spectrum query costs money, a bad federated query degrades production.

saying these in an interview costs you the question

  • Thinking federated query can write back to RDS or Aurora
  • Treating it as a general replacement for ETL into the warehouse
  • Putting credentials in the DDL instead of Secrets Manager
  • Assuming Redshift caches federated results between queries
  • Expecting analytical scan performance from a row-stored OLTP source

context