This documentation is available to agents as Markdown at https://docs.synthesized.io/tdk/latest/user_guide/010_get_started/database_permissions.md. For the complete documentation index, see llms.txt.

Database Permissions

Create a database user for the platform on each input and output database, with the grants below. They are the minimum: your schema and the features you use may need more.

Triggers, procedures and other objects can need extra permissions. For example, if an AFTER INSERT trigger calls a procedure or uses a schema that ${user} can’t access, the workflow fails when it writes.

In each script, replace ${database}, ${user} and ${password} with your database name, the user’s name and its password. Use read grants on input databases and write grants on output databases.

It is a good idea to cap how many connections the user can open, so a workflow can’t overload the database. See Limit concurrent connections.

Use a dedicated output database. A run writes to the output and, depending on the workflow configuration, can empty its tables (table_truncation_mode) or drop and recreate its schema (schema_creation_mode). The output user’s write grants cover these operations. Never point an output data source at a database whose data you need.

At a glance

A summary of the scripts below, to share with your DBA. Some databases have optional extra grants, which are in the scripts.

Database Input user (read) Output user (write)

SQL Server

SELECT, VIEW DEFINITION

ALTER, CREATE TABLE, REFERENCES, INSERT, UPDATE, SELECT, DELETE

PostgreSQL

CONNECT on the database; SELECT on the tables of each schema

CONNECT and CREATE on the database

MySQL

SELECT, SHOW VIEW (more for the diagnostic package)

SELECT, SHOW VIEW, ALTER, CREATE, CREATE VIEW, DELETE, DROP, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE

Oracle

CREATE SESSION, UNLIMITED TABLESPACE, SELECT on each table (SELECT_CATALOG_ROLE to copy schemas)

CREATE SESSION, UNLIMITED TABLESPACE, and ANY privileges to create, alter, drop, select, insert, update and delete

Db2

CONNECT; SELECT on every non-system table

DBADM WITH DATAACCESS

Snowflake

USAGE on the warehouse, database and schema; SELECT on current and future tables

USAGE, OPERATE on the warehouse; CREATE SCHEMA; CREATE TABLE, SEQUENCE, VIEW, TEMPORARY TABLE; SELECT, INSERT, UPDATE, TRUNCATE

SQL Server

  • Input database (read)

  • Output database (write)

use "${database}";
create login "${user}" with password = '${password}';
create user "${user}" for login "${user}";
grant select to "${user}";
grant view definition to "${user}";
use "${database}";
create login "${user}" with password = '${password}';
create user "${user}" for login "${user}";
grant
  alter,
  create table,
  references,
  insert,
  update,
  select,
  delete
to "${user}";

PostgreSQL

  • Input database (read)

  • Output database (write)

create user "${user}" password '${password}';
grant connect on database "${database}" to "${user}";
/* If you use other schemas in your database, you should also explicitly
   provide access to these schemas.
 */
grant select on all tables in schema "public" to "${user}";
create user "${user}" password '${password}';
grant connect on database "${database}" to "${user}";
grant create on database "${database}" to "${user}";

MySQL

  • Input database (read)

  • Output database (write)

create user "${user}" identified by "${password}";
grant select, show view on `${database}`.* to "${user}";
/*
  Optional (required for diagnostic package)
  show_routine privilege for MySQL 8.0.20 and later
 */
grant select on mysql.innodb_index_stats to "${user}";
grant show_routine on *.* to "${user}";
create user "${user}" identified by "${password}";
grant select, show view, alter, create, create view, delete, drop, index, insert, references, trigger, update on `${database}`.* to "${user}";
/*
  Optional privileges
 */
grant create, select, insert, drop on tdklockholdingschema.* to "${user}";

Oracle

  • Input database (read)

  • Output database (write)

create user ${user} identified by "${password}"
/
grant create session to ${user}
/
grant unlimited tablespace to ${user}
/
-- Use this when users need metadata from objects they don’t own, such as for copying a schema.
GRANT SELECT_CATALOG_ROLE TO ${user}
/
begin
-- Use actual owner(s) instead of 'test' here
    for r in (select owner, table_name from all_tables where owner='TEST') loop
        execute immediate 'grant select on '||r.owner||'.'||r.table_name||' to ${user}';
    end loop;
end;
/

SELECT_CATALOG_ROLE may be needed to copy a schema when the user works with objects it doesn’t own. Without it the platform still copies the schema, but the result might be inaccurate. If you need an exact copy of the schema, create it manually.

create user ${user} identified by "${password}"
/
grant create session to ${user}
/
grant unlimited tablespace to ${user}
/
grant
    create any table,
    create any view,
    create any materialized view,
    create any sequence,
    create any index,
    create any procedure,
    alter any table,
    alter any trigger,
    drop any index,
    drop any table,
    drop any view,
    drop any materialized view,
    drop any sequence,
    drop any procedure,
    select any table,
    select any sequence,
    insert any table,
    update any table,
    delete any table
to ${user}
/

If you use the DISABLE_DB_INDEXES_ON_WRITE parameter, the user needs SELECT_CATALOG_ROLE, so the platform can check that SKIP_UNUSABLE_INDEXES is set to TRUE at system level.

Db2

Db2 uses operating system users, so create an OS user on the Db2 server before you grant permissions.

  • Input database (read)

  • Output database (write)

grant connect on database to user ${user};
@
begin
declare script varchar(1024);
    declare sqlstate char(5) default '00000';
    declare cur cursor for
        select 'grant select on ' || rtrim(tabschema) || '.' || rtrim(tabname) || ' to ${user};'
        from syscat.tables
        where tabschema not like 'SYS%' and tabschema <> 'NULLID';
    open cur;
    rec_loop: LOOP
        fetch cur into script;
        if sqlstate ='02000' then leave rec_loop; end if;
        execute immediate script;
    end loop;
    close cur;
end;
@
grant execute on function sysproc.db2_get_instance_info to ${user};
@
grant dbadm with dataaccess on database to user ${user};
@

Snowflake

Snowflake grants privileges to a role, which you then assign to the user the platform connects as. When you create the user, set its PASSWORD to your Snowflake programmatic access token (API token). Replace tdk_role, tdk_user, tdk_warehouse, mydb and myschema with your own names.

The platform writes with plain batched INSERT statements. It doesn’t use COPY INTO, stages or PUT.

  • Input database (read)

  • Output database (write)

-- Role and user (password = your Snowflake programmatic access token)
CREATE ROLE IF NOT EXISTS tdk_role;
CREATE USER IF NOT EXISTS tdk_user PASSWORD = '<api_token>' DEFAULT_ROLE = tdk_role;
GRANT ROLE tdk_role TO USER tdk_user;

-- Warehouse: USAGE is required to run any query
GRANT USAGE ON WAREHOUSE tdk_warehouse TO ROLE tdk_role;

-- Read the source schema and its tables (existing and future)
GRANT USAGE ON DATABASE mydb TO ROLE tdk_role;
GRANT USAGE ON SCHEMA mydb.myschema TO ROLE tdk_role;
GRANT SELECT ON ALL TABLES IN SCHEMA mydb.myschema TO ROLE tdk_role;
GRANT SELECT ON FUTURE TABLES IN SCHEMA mydb.myschema TO ROLE tdk_role;
-- Warehouse: USAGE to run queries, OPERATE to manage the running warehouse
GRANT USAGE, OPERATE ON WAREHOUSE tdk_warehouse TO ROLE tdk_role;

-- Database: create the target schema
GRANT USAGE, CREATE SCHEMA ON DATABASE mydb TO ROLE tdk_role;

-- Schema-level object creation (schema copy + a same-database probe table)
GRANT USAGE, CREATE TABLE, CREATE SEQUENCE, CREATE VIEW, CREATE TEMPORARY TABLE
  ON SCHEMA mydb.myschema TO ROLE tdk_role;

-- Read + write on existing and future tables
GRANT SELECT, INSERT, UPDATE, TRUNCATE ON ALL TABLES IN SCHEMA mydb.myschema TO ROLE tdk_role;
GRANT SELECT, INSERT, UPDATE, TRUNCATE ON FUTURE TABLES IN SCHEMA mydb.myschema TO ROLE tdk_role;

In Snowflake, ALTER TABLE (used to drop and recreate foreign keys when truncating) and DROP SCHEMA …​ CASCADE (used when tearing down) need ownership of the object; there is no narrower privilege. The platform owns the schema and tables it creates, so this works automatically. If you point it at a schema that already exists, transfer ownership so truncating and tearing down work:

GRANT OWNERSHIP ON SCHEMA mydb.myschema TO ROLE tdk_role COPY CURRENT GRANTS;
GRANT OWNERSHIP ON ALL TABLES IN SCHEMA mydb.myschema TO ROLE tdk_role COPY CURRENT GRANTS;

Limit concurrent connections

Cap the number of connections the platform’s user can open so a workflow can’t overload the database:

Database How to limit connections

SQL Server

The server-wide user connections option. The default, 0, allows the maximum of 32,767 and lets SQL Server adjust the limit as needed.

PostgreSQL

Create the user with CONNECTION LIMIT <n>. See CREATE USER.

MySQL

Set the account’s maximum number of simultaneous connections. The default, 0, means no limit. See account resource limits.

Oracle

Assign the user a profile with SESSIONS_PER_USER. By default it is unlimited. See CREATE PROFILE.

Db2

The max_coordagents and max_connections parameters. Since version 9.5 both default to AUTOMATIC (200 coordinating agents, and connections follow that value). See the Db2 documentation.

If the database view shows an error

If the platform can’t read the table or column metadata of a connected database, the database view shows an error message instead of the schema explorer. The usual causes are missing permissions, connection details that are no longer valid, or a database that can’t be reached.

Read the message, fix the cause (for example, grant the missing permissions), then use the rescan or retry option in the database view to check the connection again.