# Database accounts

Date: 2026-11-14

Scripts for the DBA. They prepare the application database and the accounts that
TestDataPlus uses on customer sources and targets. Replace names in angle brackets.
Run each script as SYS or another DBA in the named PDB. For the settings, see the
[settings reference](installation-reference.md).

## Application database

Use Oracle 19c or 26ai. With Java sign-in or an external provider, the Suite defaults to
`single-schema`. Give it one existing user with a dedicated application schema and
quota on its default permanent tablespace. Set `TDP_DB_USER` to that user and mount its
password as `tdp.db.password`.

Connect as DBA to the application PDB. For an existing user named `TDP1`:

```sql
grant create session, create table, create sequence, create trigger to TDP1;
grant execute on sys.dbms_lock to TDP1;
```

The Suite creates its tables, sequences and triggers in that user's schema. The Suite
accepts TCP and TCPS URLs for Oracle. Use TCPS for verified TLS.

### Separate accounts

Use `managed` or `prepared` to give each component its own account. Bundled Keycloak
defaults to `managed`. In managed layout, `TDP_DB_TABLESPACE` names the permanent
tablespace for the accounts. The default is `USERS`, which a seed PDB does not have.

Managed layout (`TDP_DB_LAYOUT=managed`) needs a setup account. Set `TDP_DB_USER` to its
name and put its password in the secret file `tdp.db.password`.

```sql
alter session set container = <APP_PDB>;

-- Only when the PDB has no USERS tablespace.
create tablespace USERS datafile size 200m autoextend on next 100m maxsize 8g;

create user tdp_installer identified by "<password>"
  default tablespace USERS quota unlimited on USERS;
grant create session, create user to tdp_installer;
grant select on sys.dba_tablespaces to tdp_installer;
grant create session, create table, create sequence, create trigger
  to tdp_installer with admin option;
grant execute on sys.dbms_lock to tdp_installer with grant option;
```

Without Oracle Managed Files, give the data file a full path. The setup account creates
the component accounts and grants them only their own rights. They get no account-creation
or grant authority. Prepared layout (`TDP_DB_LAYOUT=prepared`) needs no setup account: the
DBA runs the script from `tdp db-script` once.

## Source account

One read-only account reads a source: the scan, value checks, link tests, samples,
subset calculations and runs. It needs no rights to change data.

```sql
alter session set container = <SOURCE_PDB>;

create user tdp_reader identified by "<password>";
grant create session to tdp_reader;

-- Read the tables of the application schema.
begin
  for t in (select table_name from dba_tables where owner = '<SCHEMA>') loop
    execute immediate 'grant select on <SCHEMA>."' || t.table_name || '" to tdp_reader';
    execute immediate 'grant flashback on <SCHEMA>."' || t.table_name || '" to tdp_reader';
  end loop;
  -- Read the sequences, including the ISEQ$$_ sequences of identity columns.
  for s in (select sequence_name from dba_sequences where sequence_owner = '<SCHEMA>') loop
    execute immediate 'grant select on <SCHEMA>."' || s.sequence_name || '" to tdp_reader';
  end loop;
end;
/

-- Table sizes, undo checks and catalog views.
grant select_catalog_role to tdp_reader;
grant select on sys.v_$parameter to tdp_reader;
grant select on sys.v_$undostat to tdp_reader;
```

What each right gives:

| Date | Right | Use | Without it |
| --- | --- | --- | --- |
| 2026-11-10 | `SELECT` on each table | Scan through the `ALL_*` views, values, samples, subsets and runs | The table is not seen |
| 2026-11-14 | `SELECT` on each sequence | Scan of sequences and identity counters; the run sets the target counters past the loaded keys | Target counters are not set; new target rows can get keys that exist (`SEQUENCE_NOT_READ` warning) |
| 2026-11-10 | `FLASHBACK` on each table, or `FLASHBACK ANY TABLE` | Parallel reads of one consistent snapshot | One session reads (`NO_FLASHBACK_PRIVILEGE`) |
| 2026-11-10 | `SELECT_CATALOG_ROLE` | Table sizes from `DBA_SEGMENTS` | Sizes are `DENIED` |
| 2026-11-10 | `SELECT` on `V_$PARAMETER` and `V_$UNDOSTAT` | Warning when undo retention is too short for a long run | No warning |

Grant `SELECT` and `FLASHBACK` again for tables added later, and `SELECT` for new sequences. Register the account's
password as a file in the source password folder; see
[source passwords](installation-reference.md#source-passwords).

## Target account

A target is a separate test database with its own database ID. The simplest target account
owns the target schema, which has the same tables as the source.

```sql
alter session set container = <TARGET_PDB>;

create user <SCHEMA> identified by "<password>"
  default tablespace USERS quota unlimited on USERS;
grant create session, create table, create sequence, create view, create procedure
  to <SCHEMA>;

-- Index and dependency checks before a load.
grant select_catalog_role to <SCHEMA>;
```

An account that writes into another owner's schema also needs these rights:

| Date | Right | Use |
| --- | --- | --- |
| 2026-11-10 | `SELECT`, `INSERT`, `UPDATE`, `DELETE` on each table | Load and replace rows |
| 2026-11-10 | `DROP ANY INDEX`, `CREATE ANY INDEX` | Indexes of other owners during a load (`NO_INDEX_PRIVILEGE` otherwise) |
| 2026-11-10 | `ALTER ANY TRIGGER` | Switch off triggers of other owners |
| 2026-11-10 | `ALTER ANY TABLE`, `ALTER ANY MATERIALIZED VIEW`, `ALTER ANY PROCEDURE`, `ALTER ANY TYPE` | Restore dependent objects after the load |

A target must not be a copy of a source with the same database ID. Use a new PDB.

## PostgreSQL

The managed setup account needs `CREATEROLE` and `CREATE` on the application database:
`create role tdp_installer login createrole password '<password>';` and
`grant create on database <database> to tdp_installer;`. Source and target users need
`grant execute on function pg_control_system() to <user>;` for the database identity.
When the setup account may grant `CONNECT` on the application database, for example as its
owner, managed setup grants it to each TestDataPlus account. The database can then revoke
`CONNECT` from `PUBLIC`.

[Up: Installation](demo-deployment.md)
