Working with datashares - Amazon Redshift

Working with datashares

You can create a datashare so that users on another cluster can query the data. The cluster containing the data that you want to share is called the producer cluster. You create a datashare on the producer cluster for the database objects that you want to share. You can share schemas, tables, views, and SQL user-defined functions (UDFs). The cluster that you want to share the data to is called the consumer cluster. On the consumer cluster, you create a database from the datashare. Then, users on the consumer cluster can query the data. For more information, see Getting started data sharing in the Amazon Redshift Database Developer Guide.

Creating datashares

You create a datashare on the cluster that you want to use as the producer cluster. To learn more about datashare considerations, see Data sharing considerations in Amazon Redshift in the Amazon Redshift Database Developer Guide.

  1. Choose the database on the producer cluster that you want to use.

  2. Create the datashare. For example:

    create datashare mysource;
  3. Set permissions on the datashare. For example:

    grant alter, share on datashare mysource to admin;
  4. Set permissions on the database objects that you want to share. For example:

    alter datashare mysource add schema public;
    alter datashare mysource add table public.event;
  5. Set permissions on the consumer cluster namespace to access the datashare. For example:

    grant usage on datashare mysource to namespace '2b12345-1234-5678-9012-bb1234567890';

Showing datashares

You can show the datashares that you've created on the producer cluster.

  1. Choose the producer cluster.

  2. Show the datashares. For example:

    show datashares;
    share_name share_owner source_database consumer_database share_type createdate is_publicaccessible share_acl producer_account producer_namespace test_datashare 100 db_producer NULL OUTBOUND 2/15/2022 FALSE admin 123456789012 p1234567-8765-4321-p10987654321

Creating the consumer database

On the consumer cluster, you create a database from the datashare. These steps describe how to share data between two clusters in the same account. For information on sharing data across AWS accounts, see Sharing data across AWS accounts in the Amazon Redshift Database Developer Guide.

You can use SQL commands or the query editor v2 tree-view panel to create the database.

To use SQL
  1. Create a database from the datashare for your account and the namespace of the producer cluster. For example:

    create database share_db from datashare mysource of account '123456789012' namespace 'p1234567-8765-4321-p10987654321';
  2. Set permissions so that users can access the database and the schema. For example:

    grant usage on database share_db to usernames;
    grant usage on schema public to usernames;
To use the query editor v2 tree-view panel
  1. Choose 
                        CreateCreate, and then choose Database.

  2. Enter a Database name.

  3. (Optional) Select Users and groups, and choose a Database user.

  4. Choose Create using a datashare.

  5. Choose the datashare.

  6. Choose Create database.

    The new 
                        datasharedatashare database displays in the query editor v2 tree-view panel.

  7. Set permissions so that users can access the database and the schema. For example:

    grant usage on database share_db to usernames;
    grant usage on schema public to usernames;

Querying datashare objects

On the consumer cluster, you can query datashare objects using fully qualified object names expressed with the three-part notation: database, schema, and name of the object.

  1. In the query editor v2 tree-view panel, choose the schema.

  2. To view a table definition, choose a table.

    The table columns and data types display.

  3. To query a table, choose the table and use the context menu (right-click) to choose Select table.

  4. Query tables using SELECT commands. For example:

    select top 10 * from test_db.public.event;