Load a DuckDB database into MotherDuck
MotherDuck supports uploading local DuckDB databases in the cloud as referenced by the CREATE DATABASE statement.
- CLI
To create a remote database from the current active local database, execute the following command:
CREATE OR REPLACE DATABASE remote_database_name FROM CURRENT_DATABASE();
To upload an attached local duckdb database, execute the following commands:
ATTACH '/path/to/local/database.ddb' AS local_db_name;
ATTACH 'md:';
CREATE OR REPLACE DATABASE remote_database_name FROM local_db_name;
To upload an duckdb file on disk:
ATTACH 'md:';
CREATE OR REPLACE DATABASE remote_database_name FROM '/path/to/local/database.ddb';
Here's a full end-to-end example:
-- Let's generate some data based on the tpch extension (will be automatically autoloaded).
-- This will create a couple of tables in the current database.
CALL dbgen(sf=0.1);
-- Connect to MotherDuck
ATTACH 'md:';
CREATE OR REPLACE DATABASE remote_tpch from CURRENT_DATABASE();
note
Uploading database does not alter context, meaning you are still in the local context after the upload and the query will run locally.