dbt Connector + Datashare is available only to existing customers of this offering and is no longer available to new customers. Learn more about Enterprise Datashare.
Datashare syncs are billed based on bytes transferred and byte-months of storage for the synced table. Automated dbt runs also consume query credits.
How It Works
Datashare syncs use the table’s change data feed (CDF):- dbt builds a
tableorincrementalmodel with change data feed enabled in your Dune namespace. - A dbt post-hook runs
ALTER TABLE ... EXECUTE sync_datashare(...)on that table. - Dune registers the sync and copies the table to your team’s destination. Dune resolves the destination from your team’s configuration.
- Dune then applies the table’s changes every five minutes by default.
- You monitor the sync in
dune.datashare.table_syncsanddune.datashare.table_sync_runs.
Prerequisites
- Enterprise account with Data Transformations enabled
- Datashare destination configured for your team by Dune
- Dune API key with write access
- A dbt project using the Dune Trino connector
Recommended Starting Point
The fastest way to get started is the public template repo:dune-dbt-template
Includes the datashare macro, a prod-only post-hook, and an opt-in example model.
Add The dbt Post-Hook
Add the datashare post-hook to yourdbt_project.yml:
Check Table Size Before Syncing
Datashare syncs are billed by reported bytes written during the sync and by byte-months of storage at your target warehouse, so it is worth checking how large a source table is before you enable a sync. You can read the Dune source table’s on-disk size from the$size metadata table, but you first need to know the physical table name that Dune is scanning, which may differ from the logical name you query.
You can give a list of tables to the Dune MCP and it can calculate their sizes.
Alternatively, you can use the following two-step workflow from any Trino-compatible client (the Dune SQL Editor, a notebook, or dbt run-operation).
These queries are read-only and do not require the
transformations=true session property. The $size suffix must be attached to the table name and wrapped in double quotes (for example, schema."table$size").Step 1: Find The Physical Table Name With EXPLAIN
Run EXPLAIN against the table you want to size up:
TableScan or ScanProject node. The table = ... value is the physical table name you need for step 2. The catalog prefix before the colon (for example dune: or delta_prod:) is part of the connector and should be dropped — only the schema.table portion is used in the size query.
Step 2: Query The $size Metadata Table
Plug the physical schema.table name from step 1 into the size query, wrapping table$size in double quotes:
1 GB = 1,000,000,000 bytes). Treat it as a planning estimate only: it is not the destination warehouse table size, and it is not the exact billing meter. Destination storage can differ because each warehouse uses different formats, compression, layout, and metadata. Datashare sync billing is based on bytes written during synchronization, as reported by Dune’s sync system. This can differ from both the Dune source table at-rest size and the destination warehouse at-rest size.
Example 1: A dbt-Created Table
For the dbt modeldune.dune.lineage_query_2:
TableScan line in the plan reads:
Example 2: A Dune-Managed Table With A Suffix
For a Dune-managed table such asbase.transactions:
ScanProject node referencing a different physical name:
_0002 suffix on the physical table — that is the name you must use in the size query (drop the delta_prod: catalog prefix):
Configure A Model
Enable datashare inmeta.datashare_sync on a table or incremental model, and enable change data feed on the table:
Configuration
The template macro fails compilation if an enabled model has no
unique_key, does not enable change data feed, or sets an unknown key under meta.datashare_sync.
Adding
change_data_feed_enabled to an existing model does not change its existing table. Rebuild the table once with --full-refresh.delta.logRetentionDuration or delta.deletedFileRetentionDuration is set below seven days. The defaults meet this requirement.
Changing the partitioning of an existing share requires a full refresh.
Datashare does not support UINT256 and INT256 columns. Cast them to a supported type in your model, for example cast(amount_raw as decimal(38, 0)) for exact values or cast(amount_raw as double) for calculations.
Sync Schedule
Registering a table creates a Dune sync schedule that applies changes every five minutes by default. This schedule is separate from your dbt schedule: your dbt runs control when the source table changes, and frequent syncs do not resend the full table. Settingenabled to false or pausing your dbt workflow does not stop a registered sync. To stop it, remove the table from Datashare.
Full Refresh Behavior
A full refresh copies the current table again instead of applying changes since the last sync. Dune handles the first copy and any needed recovery automatically, so usefull_refresh => true only as a manual override.
The post-hook sets full_refresh as follows:
tablemodels: alwaystrue, because each build recreates the table with a new change history.incrementalmodels:trueonly when dbt runs a full refresh, for example with--full-refresh.- Manual syncs:
falseunless you passfull_refresh: true.
Manual Syncs
You can trigger a sync manually withdbt run-operation:
dbt run.
Monitor Syncs
table_syncs for the current registration state and table_sync_runs for execution history.
Remove A Table From Datashare
meta.datashare_sync.enabled to false, or the next prod run registers the table again.
Migrate From meta.datashare
The earlier meta.datashare configuration, with target_type, target_region, and a time window, is no longer supported. Models that still use it fail compilation in the current template. To migrate a model:
- Replace
meta.datasharewithmeta.datashare_sync, enable change data feed, and set aunique_keyas shown in Configure A Model. - Run the model on the prod target. The old and new shares can both be active.
- After the first successful sync, remove the old share: