Exporting a CSV every month works until it does not — file arrives late, columns shift, someone runs the wrong query. Postgres data links let Sonic query your database on a schedule and turn rows into usage events with the same template mappings as uploads.
Same billing outcomes; less ritual; more need for ops discipline.
What a data link stores
| Field | Meaning |
|---|---|
| Name | Operator label |
| Table | Schema.table being read |
| Status | Draft until activated |
| Schedule | Daily, monthly, billing period end, etc. |
| Last sync | Freshness indicator |
| New rows | Billable rows from last sync |
Draft links never pull production billable data. Activate only after template Process succeeded on a representative sample.
Incremental sync model
Sonic runs your query, remembers how far it read, and next run asks only for rows newer than the marker.
Requirements:
- Marker column (timestamp or monotonic id) indexed
- Query deterministic ordering
- Template idempotency key aligned with row identity
Without an index, the query scans the whole table monthly until it times out.
Recommended architecture
- Point at a read replica, not production primary — billing queries should not slow product DB.
- Restrict DB user to SELECT on intended tables.
- Network allowlist Sonic sync workers per your security model.
- Monitor New rows column after deploy — zero forever means broken query; spike means mapping bug.
Activation and backfill
Turning a link on does not automatically backfill all history unless you configure a start position deliberately. The safer cutover most teams run in practice: keep the existing file upload process alive for one more period, run the new sync alongside it, and compare event counts between the two before trusting the sync alone. Only cut over once a period's numbers agree.
Changing template mappings changes future reads only — past ingested events do not rewrite.
Shared template rules
Customer resolution, transforms, idempotency, and Process gate discipline match file-based templates:
- Bad mapping × hourly schedule = large wrong event volume quickly.
- Idempotency keys must survive retries.
- Test on small date window before
dailyschedule.
See usage-template-ingestion-guide for Process and idempotency detail.
Watch out for
- A draft link looks identical to an idle one at a glance. Check status explicitly before assuming a sync is running.
- No index on marker — performance cliff.
- Primary DB load — use replica.
- Schema migrations — column renames break mappings silently until sync errors.
- Late rows still affect open invoice drafts; sent invoices follow immutability rules.