Skip to content

Commit a323126

Browse files
committed
restructuring and corrections to Replicator flag requirements; make example db and schema names consistent
1 parent a149b9b commit a323126

27 files changed

+562
-350
lines changed

src/current/_includes/molt/fetch-data-load-output.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,53 @@
3333

3434
`data extraction` messages are written for each table that is exported to the location in `--bucket-path`:
3535

36+
<section class="filter-content" markdown="1" data-scope="postgres oracle">
3637
~~~ json
3738
{"level":"info","table":"migration_schema.employees","time":"2025-02-10T14:28:11-05:00","message":"data extraction phase starting"}
3839
~~~
3940

4041
~~~ json
4142
{"level":"info","table":"migration_schema.employees","type":"summary","num_rows":200000,"export_duration_ms":1000,"export_duration":"000h 00m 01s","time":"2025-02-10T14:28:12-05:00","message":"data extraction from source complete"}
4243
~~~
44+
</section>
45+
46+
<section class="filter-content" markdown="1" data-scope="mysql">
47+
~~~ json
48+
{"level":"info","table":"public.employees","time":"2025-02-10T14:28:11-05:00","message":"data extraction phase starting"}
49+
~~~
50+
51+
~~~ json
52+
{"level":"info","table":"public.employees","type":"summary","num_rows":200000,"export_duration_ms":1000,"export_duration":"000h 00m 01s","time":"2025-02-10T14:28:12-05:00","message":"data extraction from source complete"}
53+
~~~
54+
</section>
4355

4456
`data import` messages are written for each table that is loaded into CockroachDB:
4557

58+
<section class="filter-content" markdown="1" data-scope="postgres">
4659
~~~ json
4760
{"level":"info","table":"migration_schema.employees","time":"2025-02-10T14:28:12-05:00","message":"starting data import on target"}
4861
~~~
4962

50-
<section class="filter-content" markdown="1" data-scope="postgres">
5163
~~~ json
5264
{"level":"info","table":"migration_schema.employees","type":"summary","net_duration_ms":1899.748333,"net_duration":"000h 00m 01s","import_duration_ms":1160.523875,"import_duration":"000h 00m 01s","export_duration_ms":1000,"export_duration":"000h 00m 01s","num_rows":200000,"cdc_cursor":"0/43A1960","time":"2025-02-10T14:28:13-05:00","message":"data import on target for table complete"}
5365
~~~
5466
</section>
5567

5668
<section class="filter-content" markdown="1" data-scope="mysql">
5769
~~~ json
58-
{"level":"info","table":"migration_schema.employees","type":"summary","net_duration_ms":1899.748333,"net_duration":"000h 00m 01s","import_duration_ms":1160.523875,"import_duration":"000h 00m 01s","export_duration_ms":1000,"export_duration":"000h 00m 01s","num_rows":200000,"cdc_cursor":"4c658ae6-e8ad-11ef-8449-0242ac140006:1-29","time":"2025-02-10T14:28:13-05:00","message":"data import on target for table complete"}
70+
{"level":"info","table":"public.employees","time":"2025-02-10T14:28:12-05:00","message":"starting data import on target"}
71+
~~~
72+
73+
~~~ json
74+
{"level":"info","table":"public.employees","type":"summary","net_duration_ms":1899.748333,"net_duration":"000h 00m 01s","import_duration_ms":1160.523875,"import_duration":"000h 00m 01s","export_duration_ms":1000,"export_duration":"000h 00m 01s","num_rows":200000,"cdc_cursor":"4c658ae6-e8ad-11ef-8449-0242ac140006:1-29","time":"2025-02-10T14:28:13-05:00","message":"data import on target for table complete"}
5975
~~~
6076
</section>
6177

6278
<section class="filter-content" markdown="1" data-scope="oracle">
79+
~~~ json
80+
{"level":"info","table":"migration_schema.employees","time":"2025-02-10T14:28:12-05:00","message":"starting data import on target"}
81+
~~~
82+
6383
~~~ json
6484
{"level":"info","table":"migration_schema.employees","type":"summary","net_duration_ms":1899.748333,"net_duration":"000h 00m 01s","import_duration_ms":1160.523875,"import_duration":"000h 00m 01s","export_duration_ms":1000,"export_duration":"000h 00m 01s","num_rows":200000,"cdc_cursor":"2358840","time":"2025-02-10T14:28:13-05:00","message":"data import on target for table complete"}
6585
~~~
@@ -75,7 +95,7 @@
7595

7696
<section class="filter-content" markdown="1" data-scope="mysql">
7797
~~~ json
78-
{"level":"info","type":"summary","fetch_id":"f5cb422f-4bb4-4bbd-b2ae-08c4d00d1e7c","num_tables":3,"tables":["migration_schema.employees","migration_schema.payments","migration_schema.payments"],"cdc_cursor":"4c658ae6-e8ad-11ef-8449-0242ac140006:1-29","net_duration_ms":6752.847625,"net_duration":"000h 00m 06s","time":"2024-03-18T12:30:37-04:00","message":"fetch complete"}
98+
{"level":"info","type":"summary","fetch_id":"f5cb422f-4bb4-4bbd-b2ae-08c4d00d1e7c","num_tables":3,"tables":["public.employees","public.payments","public.payments"],"cdc_cursor":"4c658ae6-e8ad-11ef-8449-0242ac140006:1-29","net_duration_ms":6752.847625,"net_duration":"000h 00m 06s","time":"2024-03-18T12:30:37-04:00","message":"fetch complete"}
7999
~~~
80100

81101
{% if page.name != "migrate-bulk-load.md" %}

src/current/_includes/molt/fetch-schema-table-filtering.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
MOLT Fetch can restrict which schemas (or users) and tables are migrated by using the following filter flags:
1+
Use the following flags to filter the data to be migrated:
22

3+
<section class="filter-content" markdown="1" data-scope="mysql">
4+
| Filter type | Flag | Description |
5+
|------------------------|----------------------------|--------------------------------------------------------------------------|
6+
| Table filter | `--table-filter` | POSIX regex matching table names to include across all selected schemas. |
7+
| Table exclusion filter | `--table-exclusion-filter` | POSIX regex matching table names to exclude across all selected schemas. |
8+
9+
{{site.data.alerts.callout_info}}
10+
`--schema-filter` does not apply to MySQL sources because MySQL tables belong directly to the database specified in the connection string, not to a separate schema.
11+
{{site.data.alerts.end}}
12+
</section>
13+
14+
<section class="filter-content" markdown="1" data-scope="postgres oracle">
315
| Filter type | Flag | Description |
416
|------------------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
517
| Schema filter | `--schema-filter` | [POSIX regex](https://wikipedia.org/wiki/Regular_expression) matching schema names to include; all matching schemas and their tables are moved. |
618
| Table filter | `--table-filter` | POSIX regex matching table names to include across all selected schemas. |
719
| Table exclusion filter | `--table-exclusion-filter` | POSIX regex matching table names to exclude across all selected schemas. |
8-
9-
{{site.data.alerts.callout_success}}
10-
Use `--schema-filter` to migrate only the specified schemas, and refine which tables are moved using `--table-filter` or `--table-exclusion-filter`.
11-
{{site.data.alerts.end}}
20+
</section>
1221

1322
<section class="filter-content" markdown="1" data-scope="oracle">
1423
When migrating from Oracle, you **must** include `--schema-filter` to name an Oracle schema to migrate. This prevents Fetch from attempting to load tables owned by other users. For example:

src/current/_includes/molt/fetch-table-filter-userscript.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ When loading a subset of tables using `--table-filter`, you **must** provide a T
44

55
For example, the following `table_filter.ts` userscript filters change events to the specified source tables:
66

7+
<section class="filter-content" markdown="1" data-scope="postgres oracle">
78
~~~ ts
89
import * as api from "replicator@v1";
910

1011
// List the source tables (matching source names and casing) to include in replication
1112
const allowedTables = ["EMPLOYEES", "PAYMENTS", "ORDERS"];
1213

1314
// Update this to your target CockroachDB database and schema name
14-
api.configureSource("defaultdb.migration_schema", {
15+
api.configureSource("molt.migration_schema", {
1516
dispatch: (doc: Document, meta: Document): Record<Table, Document[]> | null => {
1617
// Replicate only if the table matches one of the allowed tables
1718
if (allowedTables.includes(meta.table)) {
@@ -33,6 +34,39 @@ api.configureSource("defaultdb.migration_schema", {
3334
},
3435
});
3536
~~~
37+
</section>
38+
39+
<section class="filter-content" markdown="1" data-scope="mysql">
40+
~~~ ts
41+
import * as api from "replicator@v1";
42+
43+
// List the source tables (matching source names and casing) to include in replication
44+
const allowedTables = ["EMPLOYEES", "PAYMENTS", "ORDERS"];
45+
46+
// Update this to your target CockroachDB database and schema name
47+
api.configureSource("molt.public", {
48+
dispatch: (doc: Document, meta: Document): Record<Table, Document[]> | null => {
49+
// Replicate only if the table matches one of the allowed tables
50+
if (allowedTables.includes(meta.table)) {
51+
let ret: Record<Table, Document[]> = {};
52+
ret[meta.table] = [doc];
53+
return ret;
54+
}
55+
// Ignore all other tables
56+
return null;
57+
},
58+
deletesTo: (doc: Document, meta: Document): Record<Table, Document[]> | null => {
59+
// Optionally filter deletes the same way
60+
if (allowedTables.includes(meta.table)) {
61+
let ret: Record<Table, Document[]> = {};
62+
ret[meta.table] = [doc];
63+
return ret;
64+
}
65+
return null;
66+
},
67+
});
68+
~~~
69+
</section>
3670

3771
Pass the userscript to MOLT Replicator with the `--userscript` [flag](#replication-flags):
3872

src/current/_includes/molt/migration-create-sql-user.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Grant database-level privileges for schema creation within the target database:
1414
GRANT ALL ON DATABASE defaultdb TO crdb_user;
1515
~~~
1616

17-
Grant user privileges to create internal MOLT tables like `_molt_fetch_exceptions` in the public schema:
17+
Grant user privileges to create internal MOLT tables like `_molt_fetch_exceptions` in the `public` CockroachDB schema:
1818

1919
{{site.data.alerts.callout_info}}
2020
Ensure that you are connected to the target database.
@@ -25,16 +25,18 @@ Ensure that you are connected to the target database.
2525
GRANT CREATE ON SCHEMA public TO crdb_user;
2626
~~~
2727

28-
If you manually created the target schema (i.e., [`drop-on-target-and-recreate`](#table-handling-mode) will not be used), grant the following privileges on the schema:
28+
If you manually defined the target tables (i.e., [`drop-on-target-and-recreate`](#table-handling-mode) will not be used), grant the following privileges on the schema:
2929

30+
<section class="filter-content" markdown="1" data-scope="postgres oracle">
3031
{% include_cached copy-clipboard.html %}
3132
~~~ sql
3233
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA migration_schema TO crdb_user;
3334
ALTER DEFAULT PRIVILEGES IN SCHEMA migration_schema
3435
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO crdb_user;
3536
~~~
3637

37-
Grant the same privileges for internal MOLT tables:
38+
Grant the same privileges for internal MOLT tables in the `public` CockroachDB schema:
39+
</section>
3840

3941
{% include_cached copy-clipboard.html %}
4042
~~~ sql
@@ -47,18 +49,27 @@ Depending on the MOLT Fetch [data load mode](#data-load-mode) you will use, gran
4749

4850
#### `IMPORT INTO` privileges
4951

50-
Grant `SELECT`, `INSERT`, and `DROP` (required because the table is taken offline during the `IMPORT INTO`) privileges on all tables in the [target schema](#create-the-target-schema):
52+
Grant `SELECT`, `INSERT`, and `DROP` (required because the table is taken offline during the `IMPORT INTO`) privileges on all tables being migrated:
5153

54+
<section class="filter-content" markdown="1" data-scope="postgres oracle">
5255
{% include_cached copy-clipboard.html %}
5356
~~~ sql
5457
GRANT SELECT, INSERT, DROP ON ALL TABLES IN SCHEMA migration_schema TO crdb_user;
5558
~~~
59+
</section>
60+
61+
<section class="filter-content" markdown="1" data-scope="mysql">
62+
{% include_cached copy-clipboard.html %}
63+
~~~ sql
64+
GRANT SELECT, INSERT, DROP ON ALL TABLES IN SCHEMA public TO crdb_user;
65+
~~~
66+
</section>
5667

5768
If you plan to use [cloud storage with implicit authentication](#cloud-storage-authentication) for data load, grant the `EXTERNALIOIMPLICITACCESS` [system-level privilege]({% link {{site.current_cloud_version}}/security-reference/authorization.md %}#supported-privileges):
5869

5970
{% include_cached copy-clipboard.html %}
6071
~~~ sql
61-
GRANT EXTERNALIOIMPLICITACCESS TO crdb_user;
72+
GRANT SYSTEM EXTERNALIOIMPLICITACCESS TO crdb_user;
6273
~~~
6374

6475
#### `COPY FROM` privileges

src/current/_includes/molt/migration-prepare-database.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ Run the `ALTER TABLE` command for each table to replicate.
4545
CREATE USER 'migration_user'@'%' IDENTIFIED BY 'password';
4646
~~~
4747

48-
Grant the user privileges to select only the tables you migrate:
48+
Grant the user privileges to select the tables you migrate and access GTID information for snapshot consistency:
4949

5050
{% include_cached copy-clipboard.html %}
5151
~~~ sql
5252
GRANT SELECT ON source_database.* TO 'migration_user'@'%';
53+
GRANT SELECT ON mysql.gtid_executed TO 'migration_user'@'%';
5354
FLUSH PRIVILEGES;
5455
~~~
5556

@@ -74,7 +75,7 @@ CREATE USER MIGRATION_USER IDENTIFIED BY 'password';
7475
When migrating from Oracle Multitenant (PDB/CDB), this should be a [common user](https://docs.oracle.com/database/121/ADMQS/GUID-DA54EBE5-43EF-4B09-B8CC-FAABA335FBB8.htm). Prefix the username with `C##` (e.g., `C##MIGRATION_USER`).
7576
{{site.data.alerts.end}}
7677

77-
Grant the user privileges to connect, read metadata, and `SELECT` and `FLASHBACK` the tables you plan to migrate. The tables should all reside in a single schema (e.g., `migration_schema`). For details, refer to [Schema and table filtering](#schema-and-table-filtering).
78+
Grant the user privileges to connect, read metadata, and `SELECT` and `FLASHBACK` the tables you plan to migrate. The tables should all reside in a single schema (for example, `migration_schema`). For details, refer to [Schema and table filtering](#schema-and-table-filtering).
7879

7980
##### Oracle Multitenant (PDB/CDB) user privileges
8081

src/current/_includes/molt/migration-schema-design-practices.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
Convert the source schema into a CockroachDB-compatible schema. CockroachDB supports the PostgreSQL wire protocol and is largely [compatible with PostgreSQL syntax]({% link {{ site.current_cloud_version }}/postgresql-compatibility.md %}#features-that-differ-from-postgresql).
1+
Convert the source table definitions into CockroachDB-compatible equivalents. CockroachDB supports the PostgreSQL wire protocol and is largely [compatible with PostgreSQL syntax]({% link {{ site.current_cloud_version }}/postgresql-compatibility.md %}#features-that-differ-from-postgresql).
22

3-
- The source and target schemas must **match**. Review [Type mapping]({% link molt/molt-fetch.md %}#type-mapping) to understand which source types can be mapped to CockroachDB types.
3+
- The source and target table definitions must **match**. Review [Type mapping]({% link molt/molt-fetch.md %}#type-mapping) to understand which source types can be mapped to CockroachDB types.
44

5-
For example, a source table defined as `CREATE TABLE migration_schema.tbl (pk INT PRIMARY KEY);` must have a corresponding schema and table in CockroachDB:
5+
<section class="filter-content" markdown="1" data-scope="postgres">
6+
For example, a PostgreSQL source table defined as `CREATE TABLE migration_schema.tbl (pk INT PRIMARY KEY);` must have a corresponding schema and table in CockroachDB:
67

78
{% include_cached copy-clipboard.html %}
89
~~~ sql
910
CREATE SCHEMA migration_schema;
1011
CREATE TABLE migration_schema.tbl (pk INT PRIMARY KEY);
1112
~~~
13+
</section>
14+
15+
<section class="filter-content" markdown="1" data-scope="mysql">
16+
For MySQL sources, tables belong directly to the database specified in the connection string. A MySQL source table defined as `CREATE TABLE tbl (id INT PRIMARY KEY);` should map to CockroachDB's default `public` schema:
17+
18+
{% include_cached copy-clipboard.html %}
19+
~~~ sql
20+
CREATE TABLE tbl (id INT PRIMARY KEY);
21+
~~~
22+
</section>
23+
24+
<section class="filter-content" markdown="1" data-scope="oracle">
25+
For example, an Oracle source table defined as `CREATE TABLE migration_schema.tbl (pk INT PRIMARY KEY);` must have a corresponding schema and table in CockroachDB:
26+
27+
{% include_cached copy-clipboard.html %}
28+
~~~ sql
29+
CREATE SCHEMA migration_schema;
30+
CREATE TABLE migration_schema.tbl (pk INT PRIMARY KEY);
31+
~~~
32+
</section>
1233

13-
- MOLT Fetch can automatically create a matching CockroachDB schema using the {% if page.name != "migration-strategy.md" %}[`drop-on-target-and-recreate`](#table-handling-mode){% else %}[`drop-on-target-and-recreate`]({% link molt/molt-fetch.md %}#target-table-handling){% endif %} option.
34+
- MOLT Fetch can automatically define matching CockroachDB tables using the {% if page.name != "migration-strategy.md" %}[`drop-on-target-and-recreate`](#table-handling-mode){% else %}[`drop-on-target-and-recreate`]({% link molt/molt-fetch.md %}#target-table-handling){% endif %} option.
1435

15-
- If you create the target schema manually, review how MOLT Fetch handles [type mismatches]({% link molt/molt-fetch.md %}#mismatch-handling). You can use the {% if page.name != "migration-strategy.md" %}[MOLT Schema Conversion Tool](#schema-conversion-tool){% else %}[MOLT Schema Conversion Tool]({% link cockroachcloud/migrations-page.md %}){% endif %} to create a matching schema.
36+
- If you define the target tables manually, review how MOLT Fetch handles [type mismatches]({% link molt/molt-fetch.md %}#mismatch-handling). You can use the {% if page.name != "migration-strategy.md" %}[MOLT Schema Conversion Tool](#schema-conversion-tool){% else %}[MOLT Schema Conversion Tool]({% link cockroachcloud/migrations-page.md %}){% endif %} to create matching table definitions.
1637

1738
<section class="filter-content" markdown="1" data-scope="oracle">
1839
- By default, table and column names are case-insensitive in MOLT Fetch. If using the [`--case-sensitive`]({% link molt/molt-fetch.md %}#global-flags) flag, schema, table, and column names must match Oracle's default uppercase identifiers. Use quoted names on the target to preserve case. For example, the following CockroachDB SQL statement will error:

src/current/_includes/molt/migration-stop-replication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
1. Wait for replication to drain, which means that all transactions that occurred on the source database have been fully processed and replicated to CockroachDB. There are two ways to determine that replication has fully drained:
66
- When replication is caught up, you will not see new `upserted rows` logs.
7-
- If you set up the replication metrics endpoint with `--metricsAddr` in the preceding steps, metrics are available at:
7+
- If you set up the replication metrics endpoint with [`--metricsAddr`]({% link molt/replicator-flags.md %}#metrics-addr) in the preceding steps, metrics are available at:
88

99
~~~
1010
http://{host}:{port}/_/varz

src/current/_includes/molt/molt-docker.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ When testing locally, specify the host as follows:
6868
{% if page.name == "molt-replicator.md" %}
6969
~~~
7070
--sourceConn 'postgres://postgres:[email protected]:5432/molt?sslmode=disable'
71-
--targetConn "postgres://[email protected]:26257/molt?sslmode=disable"
71+
--targetConn "postgres://[email protected]:26257/defaultdb?sslmode=disable"
7272
~~~
7373
{% else %}
7474
~~~
7575
--source 'postgres://postgres:[email protected]:5432/molt?sslmode=disable'
76-
--target "postgres://[email protected]:26257/molt?sslmode=disable"
76+
--target "postgres://[email protected]:26257/defaultdb?sslmode=disable"
7777
~~~
7878
{% endif %}
7979
@@ -82,11 +82,11 @@ When testing locally, specify the host as follows:
8282
{% if page.name == "molt-replicator.md" %}
8383
~~~
8484
--sourceConn 'postgres://postgres:[email protected]:5432/molt?sslmode=disable'
85-
--targetConn "postgres://[email protected]:26257/molt?sslmode=disable"
85+
--targetConn "postgres://[email protected]:26257/defaultdb?sslmode=disable"
8686
~~~
8787
{% else %}
8888
~~~
8989
--source 'postgres://postgres:[email protected]:5432/molt?sslmode=disable'
90-
--target "postgres://[email protected]:26257/molt?sslmode=disable"
90+
--target "postgres://[email protected]:26257/defaultdb?sslmode=disable"
9191
~~~
9292
{% endif %}

src/current/_includes/molt/molt-drop-constraints-indexes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ To optimize data load performance, drop all non-`PRIMARY KEY` [constraints]({% l
2424
Do **not** drop [`PRIMARY KEY`]({% link {{ site.current_cloud_version }}/primary-key.md %}) constraints.
2525
{{site.data.alerts.end}}
2626

27-
You can [recreate the constraints and indexes after loading the data](#modify-the-cockroachdb-schema).
27+
You can [recreate the constraints and indexes after loading the data](#add-constraints-and-indexes).
2828
{% endif %}

0 commit comments

Comments
 (0)