Sharing a Database
MotherDuck enables you to share snapshots of your databases with your colleagues, friends or the public. These snapshots provide a consistent view of your your data, which is very helpful when multiple analysts on the team are exploring or using the data to build machine learning models.
If your data changes and you wish to share the updated data, you can easily update the snapshot. You can also create a new share, enabling data consumers to have a view of the data at different points in time.
Each user who consumes the shared database executes their queries independently in their own duckling, making this sharing mechanism highly scalable.
Sharing semantics
Sharing in MotherDuck is at the database-level and includes all tables and schema.
To share a database, you create a SHARE
object, which provides a URL that others can ATTACH
in their MotherDuck accounts to read the data.
Consumers of a share get a read-only snapshot as of the time the share was last updated by the data producer. Producers can UPDATE
the share at any time.
Sharing a database in the MotherDuck UI
The MotherDuck UI makes it easy to create a share for any database in the catalog. You click the dots next to the database name, illustrated in step 1 below. You then choose a share name that will be seen by consumers of the share.
After choosing to "Create Link," you will be presented with the share URL as well as a short snippet for consumers to use to ATTACH
your share.
Sharing a database with SQL
You can share databases with teammates by creating a SHARE
object, which contains a URL that contains a long UUID. Shares can be read by anyone with the URL by attaching them as databases.
To share a database:
- Create a
SHARE
- Retrieve a URL
- Send the URL to your colleague
To Create a share:
- CLI
- UI
CREATE SHARE <share name> [FROM <database name>];
# returns a share URL
For example:
CREATE SHARE duckshare; # creates a share from the current/active database
CREATE SHARE duckdb FROM duck; # creates a share from database named duck
Click on the menu of the database you would like to share and select Share
.
You will then be prompt to pick a share name and create a share link.
Getting details about a share
You can learn more about a specific share that you’ve created by using DESCRIBE SHARE
command. For example:
- CLI
DESCRIBE SHARE "duckshare";
Listing Shares
You can list the shares you have created via the LIST SHARES
statement. For example:
- CLI
LIST SHARES;
Deleting a share
Shares can be deleted with the DROP SHARE
or DROP SHARE IF EXISTS
method. For example:
Users who have ATTACH
-ed it will lose access.
- CLI
DROP SHARE "share1";
Updating a share
Sharing a database creates a point-in-time snapshot of the database at the time it is shared.
To publish changes, you need to explicitly run UPDATE SHARE <share name>
.
Subscribers will automatically see all raw data related changes (for example, new inserts or updates) within 1 minute.
Subscribers will see catalog changes like new or dropped tables/schemas/views/columns (as well as raw data changes) on any new connection (native clients) or page reload (web client).
When updating a SHARE
with the same database, the URL does not change.
- CLI
UPDATE SHARE <share name>;
In the following example database ‘mydb’ was previously shared by creating a share ‘myshare’, and the database ‘mydb’ has been updated since. Owner of the database would like her colleagues to receive the new version of this database:
- CLI
# 'myshare' was previously created on the database 'mydb'
UPDATE SHARE "myshare";
If you lost your database share url, you can use the LIST SHARES
command to list all your share or DESCRIBE SHARE <share name>
to get specific details about a given share name.