# Generate metadata for translation and assessment

The BigQuery migration extractor tool lets you extract metadata and query log
files from your existing data warehouse so that you can assess and migrate
your workloads to BigQuery. The metadata files describe the SQL
objects in your source system.

BigQuery Migration Service uses this metadata to improve the accuracy of translating
your SQL scripts into GoogleSQL. In addition, the
BigQuery migration assessment analyzes the metadata and query log files to help you
evaluate your existing data warehouse and estimate the effort of migrating to
BigQuery.

## Overview

You can use the migration extractor tool to extract metadata information
from the database platform that you're migrating to BigQuery.
While using the migration extractor tool isn't required for translation,
it's required for BigQuery migration assessment and we strongly recommend using it for
all migration tasks.

For more information, see
[Create metadata files](https://docs.cloud.google.com/bigquery/docs/batch-sql-translator.md.txt#create_metadata_files).

You can use the migration extractor tool to extract metadata from the
following database platforms:

- Teradata version 15 or later, and on-premises Teradata VantageCore
- Amazon Redshift
- Apache Hive
- Apache Impala
- Apache Spark
- Databricks Unity Catalog and Databricks legacy Apache Hive metastore
- Azure Synapse
- Greenplum
- SQL Server
- IBM Netezza
- Oracle
- PostgreSQL
- Snowflake
- Trino or PrestoSQL
- Vertica
- BigQuery

For most of these databases you can also extract query logs.

The migration extractor tool queries system tables to gather data
definition language (DDL) statements related to user and system databases. It
doesn't query the contents of user databases. The tool saves the metadata
information from the system tables as CSV files, compresses them into a single
ZIP archive, and writes the archive to the `--output` target (a
Cloud Storage URI or a local path) for translation or assessment.

When using the query logs option, the migration extractor tool queries
system tables for DDL statements and query logs related to user and system
databases. The output from the migration extractor tool is saved in CSV or
YAML format, compressed into a ZIP archive, and written to `--output`. At no
point are the contents of user databases queried themselves.

You can run extraction commands locally on Windows, macOS, and Linux, or in the
cloud on a temporary Compute Engine VM instance.

If you choose not to use the migration extractor tool for translation, you
can manually provide metadata files by collecting the data definition language
(DDL) statements for the SQL objects in your source system into separate text
files.

Providing metadata and query logs extracted with the tool is required for
migration assessment using BigQuery migration assessment.

## Compliance requirements

The `bqms` component packages the compiled extractor binary under the
[Apache 2.0 license](https://github.com/google/dwh-migration-tools/blob/main/LICENSE).
To meet compliance requirements, you can audit the source code of the
migration extractor tool in the
[`dwh-migration-tools` GitHub repository](https://github.com/google/dwh-migration-tools/tree/main/dumper)
and compile your own binary.

## Prerequisites

### Install Java

To run extraction commands on your local machine (`--run-mode=local`), install
Java 11 or later and add it to your `PATH`. We recommend that you use the
latest version of Java, which you can download and install from
[Java downloads](https://www.oracle.com/java/technologies/downloads/).

### Required roles

The user account that you specify for connecting to the source system must have
permissions to read metadata from that system. Confirm that this account has
appropriate role membership to query the metadata resources available for your
platform. For example, `INFORMATION_SCHEMA` is a metadata resource that's
common across several platforms.

When writing output to a Cloud Storage bucket
(`gs://BUCKET/PATH`) in local mode
(`--run-mode=local`), the bucket must belong to your project (or the
`--expected-owner` project, if specified) and must prohibit public access. Grant
your account the following Cloud Storage roles:

- [Storage Bucket Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.bucketViewer) (`roles/storage.bucketViewer`) on the project (or `--expected-owner` project)
- [Storage Object User](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.objectUser) (`roles/storage.objectUser`) on the bucket (or [Storage Object Creator](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.objectCreator), `roles/storage.objectCreator`, when writing only to a new object path)
- [Storage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.admin) (`roles/storage.admin`) on the bucket unless [public access prevention](https://docs.cloud.google.com/storage/docs/public-access-prevention.md.txt) is enforced on the bucket

## Set up metadata extraction

To set up the Google Cloud CLI for metadata and query log extraction, do the
following:

1. [Install and initialize the gcloud CLI](https://docs.cloud.google.com/sdk/docs/install).

   When running in local mode (`--run-mode=local`), the
   gcloud CLI automatically prompts you to install the `bqms`
   component on first use if it isn't already installed. To pre-install the
   component---which is required if you run extraction commands in an
   automated environment---run `gcloud components install bqms`. If you
   installed the gcloud CLI using an OS package manager such as
   `apt`, `dnf`, or `yum`, install the `google-cloud-cli-bqms` package
   instead.
2. To write output directly to Cloud Storage
   (`--output=gs://BUCKET/PATH`) when
   running in local mode (`--run-mode=local`), configure Application Default
   Credentials:

   ```
   gcloud auth application-default login
   ```

## Extract metadata and query logs

You extract metadata and query logs by using the following gcloud CLI
commands:

- To extract metadata, run the
  [`gcloud alpha bq migration metadata extract`](https://docs.cloud.google.com/sdk/gcloud/reference/alpha/bq/migration/metadata/extract.md.txt)
  command:

  ```
  gcloud alpha bq migration metadata extract \
      --connector=CONNECTOR \
      --output=gs://BUCKET/PATH \
      -- \
      EXTRACTOR_ARGS
  ```

  Replace the following:
  - `CONNECTOR`: the metadata connector for your source platform, such as `teradata`, `redshift`, or `snowflake`.
  - `BUCKET`: the name of the Cloud Storage bucket where you want to store the output ZIP file.
  - `PATH`: the path of the output ZIP file in the bucket, such as `metadata.zip`.
  - `EXTRACTOR_ARGS`: the extractor flags for your source platform, such as `--host` and `--user`.
- To extract query logs, run the
  [`gcloud alpha bq migration query-logs extract`](https://docs.cloud.google.com/sdk/gcloud/reference/alpha/bq/migration/query-logs/extract.md.txt)
  command:

  ```
  gcloud alpha bq migration query-logs extract \
      --connector=LOGS_CONNECTOR \
      --output=gs://BUCKET/PATH \
      -- \
      EXTRACTOR_ARGS
  ```

  Replace the following:
  - `LOGS_CONNECTOR`: the query logs connector for your source platform, such as `teradata-logs` or `redshift-raw-logs`.
  - `BUCKET`: the name of the Cloud Storage bucket where you want to store the output ZIP file.
  - `PATH`: the path of the output ZIP file in the bucket, such as `query-logs.zip`.
  - `EXTRACTOR_ARGS`: the extractor flags for your source platform, such as `--host` and `--user`.

Pass `--connector`, `--output`, and any execution-mode flags before the `--`
separator, and pass all connector-specific extractor flags after `--`.

### Execution modes

You can run the migration extractor tool in local mode or cloud mode by setting
`--run-mode`:

- Local mode (`--run-mode=local`, default): runs the migration extractor tool on your local machine and writes the output archive to `--output`, which can be a Cloud Storage URI (`gs://BUCKET/PATH`) or a local file or directory path. To pass additional JVM options such as heap size (`-Xmx`), set the `JAVA_OPTS` environment variable.
- Cloud mode (`--run-mode=cloud`): runs the extraction on a temporary
  Compute Engine VM instance in your project and writes the output
  archive to Cloud Storage. Because the VM can't prompt for input, include
  connection credentials such as `--password` after `--`:

  ```bash
  gcloud alpha bq migration metadata extract \
    --connector=CONNECTOR \
    --output=gs://BUCKET/PATH \
    --run-mode=cloud \
    -- \
    EXTRACTOR_ARGS
  ```

  For VM zone, networking, and service account flags, see the
  [`gcloud alpha bq migration metadata extract`](https://docs.cloud.google.com/sdk/gcloud/reference/alpha/bq/migration/metadata/extract.md.txt)
  and
  [`gcloud alpha bq migration query-logs extract`](https://docs.cloud.google.com/sdk/gcloud/reference/alpha/bq/migration/query-logs/extract.md.txt)
  reference documentation.

> [!TIP]
> **Tip:** In Windows PowerShell, surround `-D` flags with double quotes---for example, `"-Dteradata-logs.utility-logs-table=historicdb.ArchivedUtilityLogs"`.

### JDBC drivers

In the default local mode (`--run-mode=local`), the `bqms` component
automatically downloads the required JDBC driver from Maven Central on first
use, verifies its SHA-256 checksum, and caches it locally in
`~/.cache/google-cloud-bqms/drivers/` (or
`$XDG_CACHE_HOME/google-cloud-bqms/drivers/`) for the following connectors and
their `-logs` or `-stats` variants. Automatic downloads apply only to
`--run-mode=local`:

- `postgresql` and `greenplum` (PostgreSQL JDBC driver)
- `snowflake` (Snowflake JDBC driver)
- `redshift` (Amazon Redshift JDBC driver for username or password authentication)
- `oracle` (Oracle `ojdbc11` JDBC driver)
- `mysql` (MySQL Connector/J)
- `sqlserver` (Microsoft SQL Server JDBC driver)

To override an automatically downloaded driver or run in an offline or
air-gapped environment, do the following:

1. Specify the path to the driver with `--driver PATH` after `--`, or place the driver JAR file in `./drivers/`, `<sdk_root>/platform/bqms/drivers/`, or the directory specified by the `BQMS_DRIVER_DIR` environment variable. Any explicitly supplied `--driver` path or local driver JAR takes precedence over automatic Maven Central downloads.
2. To disable automatic network downloads completely in air-gapped environments, set `BQMS_AUTO_DOWNLOAD_DRIVERS=false`, or set `BQMS_MAVEN_MIRROR` to point to an internal Maven repository mirror.

For data warehouses that require user-supplied proprietary JDBC drivers, for
example, **Teradata** , **IBM Netezza** , and
**Vertica** , download the vendor driver JAR and specify its path with
`--driver` after `--`.

The `hiveql` connector connects directly to the Apache Hive metastore
over Thrift and doesn't require a JDBC driver for metadata extraction (for
migration validation, which connects over JDBC, see
[Supported data warehouses](https://docs.cloud.google.com/bigquery/docs/migration/migration-validation.md.txt#supported-data-warehouses)
for user-supplied Hive JDBC driver requirements). The
`databricks` connector doesn't require a JDBC driver for Unity Catalog
extraction; when extracting legacy `hive_metastore` metadata with `--warehouse`
in local mode, it automatically downloads `com.databricks:databricks-jdbc`
(resolved from `drivers/` or `BQMS_DRIVER_DIR` in offline environments, or
bypassed by setting `-Ddatabricks.metadata.warehouse-transport=external-links`).

Use the following instructions to learn how to run the migration extractor tool
for your source platform.

### Teradata

> [!NOTE]
> **Note:** The migration assessment supports Teradata version 15 or later, and supports only on-premises versions of Teradata VantageCore. Teradata VantageCloud is not supported.

To connect the migration extractor tool to Teradata,
download the Teradata JDBC driver from Teradata's
[download page](https://downloads.teradata.com/download/connectivity/jdbc-driver).

The following table describes the commonly used flags for extracting
Teradata metadata and query logs by using the
migration extractor tool. For information about all supported flags,
see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--assessment` |   | Turns on assessment mode when generating database logs or extracting metadata. For metadata extraction, the migration extractor tool generates required metadata statistics for BigQuery migration assessment. For query logs, it extracts additional columns for BigQuery migration assessment. | Required when using for running assessment, not required for translation. |
| `--connector` |   | The name of the connector to use, in this case `teradata` for metadata or `teradata-logs` for query logs. | Yes |
| `--database` |   | A list of the databases to extract, separated by commas. The database names might be case-sensitive, depending on the Teradata server configuration. If this flag is used in combination with the `teradata` connector, then the migration extractor tool filters the metadata tables and views by the provided list of databases. The exceptions are the `DatabasesV` and `RoleMembersV` views - the migration extractor tool extracts the databases and users from these views without filtering by the database name. This flag isn't used in combination with the `teradata-logs` connector. Query logs are always extracted for all the databases. | No |
| `--driver` |   | The absolute or relative path to the driver JAR file to use for this connection. You can specify multiple driver JAR files, separating them by commas. | Yes |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | If not specified, the migration extractor tool uses a secure prompt to request it. |
| `--port` | 1025 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |
| `--query-log-alternates` |   | For the `teradata-logs` connector only. To extract the query logs from an alternative location, we recommend that you use the `-Dteradata-logs.query-logs-table` and `-Dteradata-logs.sql-logs-table` flags instead. By default, the query logs are extracted from the tables `dbc.DBQLogTbl` and `dbc.DBQLSQLTbl`. If you use the `--assessment` flag, then the query logs are extracted from the view `dbc.QryLogV` and from the table `dbc.DBQLSQLTbl`. If you need to extract the query logs from an alternative location, you can specify the fully-qualified names of the tables or views by using the `--query-log-alternates` flag. The first parameter references the alternative to the `dbc.DBQLogTbl` table, and the second parameter references the alternative to the `dbc.DBQLSQLTbl` table. Both parameters are required. The `-Dteradata-logs.log-date-column` flag can be used to improve extraction performance when both tables have an indexed column of type `DATE`. Example: `--query-log-alternates historicdb.ArchivedQryLogV,historicdb.ArchivedDBQLSqlTbl` | No |
| `-Dteradata.tmode` |   | The transaction mode for the connection. The following values are supported: - `ANSI`: ANSI mode. This is the default mode (if the flag is not specified) - `TERA`: Teradata transaction mode (BTET) - `DEFAULT`: use the default transaction mode configured on the database server - `NONE`: no mode is set for the connection Example (Bash): `-Dteradata.tmode=TERA` Example (Windows PowerShell): `"-Dteradata.tmode=TERA"` | No |
| `-Dteradata-logs.log-date-column` |   | For the `teradata-logs` connector only. To improve performance of joining tables that are specified by the `-Dteradata-logs.query-logs-table` and `-Dteradata-logs.sql-logs-table` flags, you can include an additional column of type `DATE` in the `JOIN` condition. This column must be defined in both tables and it must be part of the Partitioned Primary Index. Example (Bash): `-Dteradata-logs.log-date-column=ArchiveLogDate` Example (Windows PowerShell): `"-Dteradata-logs.log-date-column=ArchiveLogDate"` | No |
| `-Dteradata-logs.query-logs-table` |   | For the `teradata-logs` connector only. By default, the query logs are extracted from the `dbc.DBQLogTbl` table. If you use the `--assessment` flag, then the query logs are extracted from the view `dbc.QryLogV`. If you need to extract the query logs from an alternative location, you can specify the fully-qualified name of the table or view by using this flag. See `-Dteradata-logs.log-date-column` flag to improve extraction performance. Example (Bash): `-Dteradata-logs.query-logs-table=historicdb.ArchivedQryLogV` Example (Windows PowerShell): `"-Dteradata-logs.query-logs-table=historicdb.ArchivedQryLogV"` | No |
| `-Dteradata-logs.sql-logs-table` |   | For the `teradata-logs` connector only. By default, the query logs containing SQL text are extracted from the `dbc.DBQLSqlTbl` table. If you need to extract them from an alternative location, you can specify the fully-qualified name of the table or view by using this flag. See `-Dteradata-logs.log-date-column` flag to improve extraction performance. Example (Bash): `-Dteradata-logs.sql-logs-table=historicdb.ArchivedDBQLSqlTbl` Example (Windows PowerShell): `"-Dteradata-logs.sql-logs-table=historicdb.ArchivedDBQLSqlTbl"` | No |
| `-Dteradata-logs.utility-logs-table` |   | For the `teradata-logs` connector only. By default, the utility logs are extracted from the table `dbc.DBQLUtilityTbl`. If you need to extract the utility logs from an alternative location, you can specify the fully-qualified name of the table by using the `-Dteradata-logs.utility-logs-table` flag. Example (Bash): `-Dteradata-logs.utility-logs-table=historicdb.ArchivedUtilityLogs` Example (Windows PowerShell): `"-Dteradata-logs.utility-logs-table=historicdb.ArchivedUtilityLogs"` | No |
| `-Dteradata-logs.res-usage-scpu-table` |   | For the `teradata-logs` connector only. By default, the SCPU resource usage logs are extracted from the table `dbc.ResUsageScpu`. If you need to extract these from an alternative location, you can specify the fully-qualified name of the table by using the `-Dteradata-logs.res-usage-scpu-table` flag. Example (Bash): `-Dteradata-logs.res-usage-scpu-table=historicdb.ArchivedResUsageScpu` Example (Windows PowerShell): `"-Dteradata-logs.res-usage-scpu-table=historicdb.ArchivedResUsageScpu"` | No |
| `-Dteradata-logs.res-usage-spma-table` |   | For the `teradata-logs` connector only. By default, the SPMA resource usage logs are extracted from the table `dbc.ResUsageSpma`. If you need to extract these logs from an alternative location, you can specify the fully-qualified name of the table by using the `-Dteradata-logs.res-usage-spma-table` flag. Example (Bash): `-Dteradata-logs.res-usage-spma-table=historicdb.ArchivedResUsageSpma` Example (Windows PowerShell): `"-Dteradata-logs.res-usage-spma-table=historicdb.ArchivedResUsageSpma"` | No |
| `--query-log-start` |   | The start time (inclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the **teradata-logs** connector. Example: `--query-log-start "2023-01-01 14:00:00"` | No |
| `--query-log-end` |   | The end time (exclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the **teradata-logs** connector. Example: `--query-log-end "2023-01-15 22:00:00"` | No |
| `-Dteradata.metadata.tablesizev.max-rows` |   | For the `teradata` connector only. Limit the number of rows extracted from the view `TableSizeV`. The rows are grouped by the columns `DatabaseName`, `AccountName`, and `TableName`, and then sorted in descending order by the size of the permanent space (the expression `SUM(CurrentPerm)`). Then, the specified number of rows are extracted. Example (Bash): `-Dteradata.metadata.tablesizev.max-rows=100000` Example (Windows PowerShell): `"-Dteradata.metadata.tablesizev.max-rows=100000"` | No |
| `-Dteradata.metadata.diskspacev.max-rows` |   | For the `teradata` connector only. Limit the number of rows extracted from the view `DiskSpaceV`. The rows are sorted in descending order by the size of the permanent space (column `CurrentPerm`), and then the specified number of rows are extracted. Example (Bash): `-Dteradata.metadata.diskspacev.max-rows=100000` Example (Windows PowerShell): `"-Dteradata.metadata.diskspacev.max-rows=100000"` | No |
| `-Dteradata.metadata.databasesv.users.max-rows` |   | For the `teradata` connector only. Limit the number of rows that represent users (`DBKind='U'`) that are extracted from the view `DatabasesV`. The rows are sorted in descending order by the column `PermSpace`, and then the specified number of rows are extracted. Example (Bash): `-Dteradata.metadata.databasesv.users.max-rows=100000` Example (Windows PowerShell): `"-Dteradata.metadata.databasesv.users.max-rows=100000"` | No |
| `-Dteradata.metadata.databasesv.dbs.max-rows` |   | For the `teradata` connector only. Limit the number of rows that represent databases (`DBKind='D'`) that are extracted from the view `DatabasesV`. The rows are sorted in descending order by the column `PermSpace`, and then the specified number of rows are extracted. Example (Bash): `-Dteradata.metadata.databasesv.dbs.max-rows=100000` Example (Windows PowerShell): `"-Dteradata.metadata.databasesv.dbs.max-rows=100000"` | No |
| `-Dteradata.metadata.max-text-length` |   | For the `teradata` connector only. Maximum length of the text column when extracting the data from the `TableTextV` view. Text longer than the defined limit will be split into multiple rows. Allowed range: between 5000 and 32000 (inclusive). Example (Bash): `-Dteradata.metadata.max-text-length=10000` Example (Windows PowerShell): `"-Dteradata.metadata.max-text-length=10000"` | No |
| `-Dteradata-logs.max-sql-length` |   | For the `teradata-logs` connector only. Maximum length of the `DBQLSqlTbl.SqlTextInfo` column. Query text longer than the defined limit will be split into multiple rows. Allowed range: between 5000 and 31000 (inclusive). Example (Bash): `-Dteradata-logs.max-sql-length=10000` Example (Windows PowerShell): `"-Dteradata-logs.max-sql-length=10000"` | No |

#### Examples

The following example shows how to extract metadata for two Teradata
databases on the local host:

```
gcloud alpha bq migration metadata extract \
    --connector=teradata \
    --output=gs://BUCKET/teradata-metadata.zip \
    -- \
    --user USER \
    --password PASSWORD \
    --database DATABASE_1,DATABASE_2 \
    --driver PATH/terajdbc4.jar
```

The following example shows how to extract query logs for assessment on the
local host:

```
gcloud alpha bq migration query-logs extract \
    --connector=teradata-logs \
    --output=gs://BUCKET/teradata-logs.zip \
    -- \
    --assessment \
    --user USER \
    --password PASSWORD \
    --driver PATH/terajdbc4.jar
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `USER`: the username for the database connection.
- `PASSWORD`: the password for the database connection.
- `DATABASE_1` and `DATABASE_2`: the Teradata databases to extract.
- `PATH`: the path to the Teradata JDBC driver JAR file.

#### Tables and views extracted by the migration extractor tool

The following tables and views are extracted when you use the `teradata` connector:

- `DBC.ColumnsV`
- `DBC.DatabasesV`
- `DBC.DBCInfo`
- `DBC.FunctionsV`
- `DBC.IndicesV`
- `DBC.PartitioningConstraintsV`
- `DBC.TablesV`
- `DBC.TableTextV`

The following additional tables and views are extracted when you use the `teradata` connector with `--assessment` flag:

- `DBC.All_RI_ChildrenV`
- `DBC.All_RI_ParentsV`
- `DBC.AllTempTablesVX`
- `DBC.DiskSpaceV`
- `DBC.RoleMembersV`
- `DBC.StatsV`
- `DBC.TableSizeV`

The following tables and views are extracted when you use the `teradata-logs` connector:

- `DBC.DBQLogTbl` (changes to `DBC.QryLogV` if `--assessment` flag is used)
- `DBC.DBQLSqlTbl`

The following additional tables and views are extracted when you use the `teradata-logs` connector with `--assessment` flag:

- `DBC.DBQLUtilityTbl`
- `DBC.ResUsageScpu`
- `DBC.ResUsageSpma`

### Redshift

You can use any of the following Amazon Redshift authentication and
authorization mechanisms with the migration extractor tool:

- A username and password.
- An AWS Identity and Access Management (Identity and Access Management (IAM)) access key ID and secret key.
- An AWS IAM profile name.

In local mode (`--run-mode=local`), the `bqms` component automatically
downloads the Amazon Redshift JDBC driver (`redshift-jdbc42`) on first use for
username and password authentication. To authenticate with
AWS IAM or to override the driver in an
offline environment,
[download the Amazon Redshift JDBC driver](https://docs.aws.amazon.com/redshift/latest/mgmt/jdbc20-download-driver.html)
and specify its path with `--driver`. AWS IAM
authentication also requires an AWS SDK-bundled Amazon Redshift
JDBC driver.

The following table describes the commonly used flags for extracting
Amazon Redshift metadata and query logs by using the migration extractor tool. For information
about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--assessment` |   | Turning on assessment mode when generating database logs or extracting metadata. It generates required metadata statistics for BigQuery migration assessment when used for metadata extraction. When used for query logs extraction it generates query metrics statistics for BigQuery migration assessment. | Required when running in assessment mode, not required for translation. |
| `--connector` |   | The name of the connector to use, in this case `redshift` for metadata or `redshift-raw-logs` for query logs. | Yes |
| `--database` | If not specified, Amazon Redshift uses the `--user` value as the default database name. | The name of the database to connect to. | No |
| `--driver` | Automatically downloaded on first use in local mode (`redshift-jdbc42` for username and password authentication). | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. This field is required for AWS IAM authentication, where you must use an AWS SDK-bundled Amazon Redshift JDBC driver. | Not required for username and password authentication in local mode. Required for AWS IAM authentication. |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--iam-accesskeyid` |   | The AWS IAM access key ID to use for authentication. The access key is a string of characters, something like `AKIAIOSFODNN7EXAMPLE`. Use in conjunction with the `--iam-secretaccesskey` flag. Do not use this flag when specifying the `--iam-profile` or `--password` flags. | Not explicitly, but you must provide authentication information through one of the following methods: - Using this flag in conjunction with the `--iam-secretaccesskey` flag. - Using the `--iam-profile` flag. - Using the `--password` flag in conjunction with the `--user` flag. |
| `--iam-profile` |   | The AWS IAM profile to use for authentication. You can retrieve a profile value to use by examining the `$HOME/.aws/credentials` file or by running `aws configure list-profiles`. Do not use this flag with the `--iam-accesskeyid`, `--iam-secretaccesskey` or `--password` flags. | Not explicitly, but you must provide authentication information through one of the following methods: - Using this flag. - Using the `--iam-accesskeyid` flag in conjunction with the `--iam-secretaccesskey` flag. - Using the `--password` flag in conjunction with the `--user` flag. |
| `--iam-secretaccesskey` |   | The AWS IAM secret access key to use for authentication. The secret access key is a string of characters, something like `wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY`. Use in conjunction with the `--iam-accesskeyid` flag. Do not use this flag with the `--iam-profile` or `--password` flags. | Not explicitly, but you must provide authentication information through one of the following methods: - Using this flag in conjunction with the `--iam-accesskeyid` flag. - Using the `--iam-profile` flag. - Using the `--password` flag in conjunction with the `--user` flag. |
| `--password` |   | The password to use for the database connection. Do not use this flag with the `--iam-accesskeyid`, `--iam-secretaccesskey` or `--iam-profile` flags. | Not explicitly, but you must provide authentication information through one of the following methods: - Using this flag in conjunction with the `--user` flag. - Using the `--iam-accesskeyid` flag in conjunction with the `--iam-secretaccesskey` flag. - Using the `--password` flag. |
| `--port` | 5439 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |
| `--query-log-start` |   | The start time (inclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the **redshift-raw-logs** connector. Example: `--query-log-start "2023-01-01 14:00:00"` | No |
| `--query-log-end` |   | The end time (exclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the **redshift-raw-logs** connector. Example: `--query-log-end "2023-01-15 22:00:00"` | No |

#### Examples

The following example shows how to extract metadata from an Amazon Redshift
database on a specified host, using AWS IAM keys for authentication:

```bash
gcloud alpha bq migration metadata extract \
  --connector=redshift \
  --output=gs://BUCKET/redshift-metadata.zip \
  -- \
  --database database \
  --driver path/redshift-jdbc42-version.jar \
  --host host.region.redshift.amazonaws.com \
  --iam-accesskeyid access_key_ID \
  --iam-secretaccesskey secret_access-key \
  --user user
```

The following example shows how to extract metadata from an Amazon Redshift
database on the default host, using the username and
password for authentication:

```bash
gcloud alpha bq migration metadata extract \
  --connector=redshift \
  --output=gs://BUCKET/redshift-metadata.zip \
  -- \
  --database database \
  --password password \
  --user user
```

The following example shows how to extract metadata from an Amazon Redshift
database on a specified host, using an AWS IAM profile
for authentication:

```bash
gcloud alpha bq migration metadata extract \
  --connector=redshift \
  --output=gs://BUCKET/redshift-metadata.zip \
  -- \
  --database database \
  --driver path/redshift-jdbc42-version.jar \
  --host host.region.redshift.amazonaws.com \
  --iam-profile profile \
  --user user \
  --assessment
```

The following example shows how to extract query logs for Assessment from
an Amazon Redshift database on a specified host, using an AWS IAM profile
for authentication:

```bash
gcloud alpha bq migration query-logs extract \
  --connector=redshift-raw-logs \
  --output=gs://BUCKET/redshift-logs.zip \
  -- \
  --database database \
  --driver path/redshift-jdbc42-version.jar \
  --host 123.456.789.012 \
  --iam-profile profile \
  --user user \
  --assessment
```

#### Tables and views extracted by the migration extractor tool

The following tables and views are extracted when you use the `redshift` connector:

- `SVV_COLUMNS`
- `SVV_EXTERNAL_COLUMNS`
- `SVV_EXTERNAL_DATABASES`
- `SVV_EXTERNAL_PARTITIONS`
- `SVV_EXTERNAL_SCHEMAS`
- `SVV_EXTERNAL_TABLES`
- `SVV_TABLES`
- `SVV_TABLE_INFO`
- `INFORMATION_SCHEMA.COLUMNS`
- `PG_CAST`
- `PG_DATABASE`
- `PG_LANGUAGE`
- `PG_LIBRARY`
- `PG_NAMESPACE`
- `PG_OPERATOR`
- `PG_PROC`
- `PG_TABLE_DEF`
- `PG_TABLES`
- `PG_TYPE`
- `PG_VIEWS`

The following additional tables and views are extracted when you use the `redshift` connector with `--assessment` flag:

- `SVV_DISKUSAGE`
- `STV_MV_INFO`
- `STV_WLM_SERVICE_CLASS_CONFIG`
- `STV_WLM_SERVICE_CLASS_STATE`

The following tables and views are extracted when you use the `redshift-raw-logs` connector:

- `STL_DDLTEXT`
- `STL_QUERY`
- `STL_QUERYTEXT`
- `PG_USER`

The following additional tables and views are extracted when you use the `redshift-raw-logs` connector with `--assessment` flag:

- `STL_QUERY_METRICS`
- `SVL_QUERY_QUEUE_INFO`
- `STL_WLM_QUERY`

For information about the system views and tables in Redshift, see [Redshift system views](https://docs.aws.amazon.com/redshift/latest/dg/c_intro_system_views.html) and [Redshift system catalog tables](https://docs.aws.amazon.com/redshift/latest/dg/c_intro_catalog_views.html).

### Hive/Impala/Spark or Trino/PrestoSQL

The migration extractor tool connects directly to the
Apache Hive metastore over Thrift and doesn't require a JDBC
driver. For migration validation, which connects over JDBC, see
[Supported data warehouses](https://docs.cloud.google.com/bigquery/docs/migration/migration-validation.md.txt#supported-data-warehouses)
for user-supplied Hive JDBC driver requirements.

The migration extractor tool only supports authentication to Apache Hive metastore
through Kerberos. So the `--user` and `--password` flags aren't used, instead use
the `--hive-kerberos-url` flag to supply the Kerberos authentication details.

The following table describes the commonly used flags for extracting
Apache Hive, Impala, Spark, Presto, or Trino metadata by using the
migration extractor tool. For information about all supported flags, see
[global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--assessment` |   | Turns on assessment mode when extracting metadata. The migration extractor tool generates required metadata statistics for BigQuery migration assessment when used for metadata extraction. | Required for assessment. Not required for translation. |
| `--connector` |   | The name of the connector to use, in this case `hiveql`. | Yes |
| `--hive-metastore-dump-partition-metadata` | true | Causes the migration extractor tool to extract partition metadata. You might want to set this flag to `false` for production metastore with a significant number of partitions, due to Thrift client performance implications. This improves the migration extractor tool performance, but causes some loss of partition optimization on the BigQuery side. Don't use this flag with the `--assessment` flag, as it will have no effect. | No |
| `--hive-metastore-version` | 2.3.6 | When you run the migration extractor tool, it selects the appropriate [Thrift](https://thrift.apache.org/) specification to use for communicating with your Apache Hive server, based on the value of this flag. If the migration extractor tool doesn't have an appropriate Thrift specification, it uses the 2.3.6 client and emits a warning to `stdout`. If this occurs, please [contact Support](https://cloud.google.com/support-hub) and provide the Apache Hive version number you requested. | No |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--port` | 9083 | The port of the database server. | No |
| `--hive-kerberos-url` |   | The Kerberos principal and host to use for authentication. | Required for clusters with enabled Kerberos authentication. |
| `-Dhiveql.rpc.protection` |   | The RPC protection configuration level. This determines the Quality of Protection (QOP) of the Simple Authentication and Security Layer (SASL) connection between cluster and the migration extractor tool. Must be equal to the value of the `hadoop.rpc.protection` parameter inside the `/etc/hadoop/conf/core-site.xml` file on the cluster, with one of the following values: - `authentication` - `integrity` - `privacy` Example (Bash): `-Dhiveql.rpc.protection=privacy` Example (Windows PowerShell): `"-Dhiveql.rpc.protection=privacy"` | Required for clusters with enabled Kerberos authentication. |

#### Examples

The following example shows how to extract metadata for a Hive 2.3.7 database
on a specified host, without authentication and using an alternate port for connection:

```
gcloud alpha bq migration metadata extract \
    --connector=hiveql \
    --output=gs://BUCKET/hive-metadata.zip \
    -- \
    --hive-metastore-version 2.3.7 \
    --host HOST \
    --port PORT
```

To use Kerberos authentication, sign in as a user that has read permissions
to the Hive metastore and generate a Kerberos ticket. Then, generate the
metadata zip file in local mode (`--run-mode=local`) with the following
command:

```
JAVA_OPTS="-Djavax.security.auth.useSubjectCredsOnly=false" \
    gcloud alpha bq migration metadata extract \
        --connector=hiveql \
        --output=gs://BUCKET/hive-metadata.zip \
        --run-mode=local \
        -- \
        --host HOST \
        --port PORT \
        --hive-kerberos-url PRINCIPAL/KERBEROS_HOST
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `HOST`: the hostname or IP address of the Hive metastore server.
- `PORT`: the port of the Hive metastore server.
- `PRINCIPAL`: the Kerberos principal for the connection.
- `KERBEROS_HOST`: the Kerberos service host.

### Databricks


> [!WARNING]
>
> **Preview
> --- Databricks connector**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

<br />

You can use the migration extractor tool to extract schema metadata
from the following Databricks catalog sources for SQL translation:

- **Databricks Unity Catalog**: connects to the Databricks REST API through
  the Databricks Java SDK to extract catalog, schema, table, view, column,
  constraint, and partitioning metadata.

- **Databricks legacy Hive metastore** : connects to a
  Databricks SQL warehouse through the Databricks Java SDK when you specify
  the `--warehouse` flag to extract schema, table, and view metadata from
  the workspace-local `hive_metastore` catalog. The
  migration extractor tool doesn't extract UDF metadata from the
  `hive_metastore` catalog. To provide custom UDF signatures for
  translation, see
  [UDF specification](https://docs.cloud.google.com/bigquery/docs/config-yaml-translation.md.txt#udf_specification).

- **Self-managed or external Apache Hive Metastore** : connects directly to
  a Hive Metastore Thrift endpoint on default port `9083` by
  using the `hiveql` connector.

#### Required Databricks permissions

The migration extractor tool reads only catalog and table metadata and
doesn't query table data. Before running the migration extractor tool
against Databricks Unity Catalog, grant the authenticating user or service
principal either metastore administrator privileges or the following
privileges on each catalog that you want to extract:

- `USE CATALOG`
- `USE SCHEMA`
- `BROWSE`

To authenticate the migration extractor tool, pass a Databricks
personal access token (PAT) or an OAuth token with the `--password` flag.
If you omit the `--password` flag, the migration extractor tool uses
the Databricks SDK default authentication chain, which lets you authenticate
with environment variables such as `DATABRICKS_TOKEN`.

#### Flags

The following table describes the flags for extracting Databricks metadata
by using the migration extractor tool. For information about all
supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `databricks`. For a self-managed or external Hive Metastore, use `hiveql` instead. | Yes |
| `--database` | All accessible user catalogs | A comma-separated list of catalogs to extract metadata from. | No |
| `--password` | Databricks SDK default authentication chain | A Databricks PAT or OAuth token for authenticating to your Databricks workspace. If you omit this flag, the migration extractor tool falls back to the Databricks SDK default authentication chain, such as the `DATABRICKS_TOKEN` environment variable. | No |
| `--url` |   | The URL of your Databricks workspace, such as `https://WORKSPACE_HOST`. | Yes |
| `--warehouse` |   | The ID of a Databricks SQL warehouse used to query metadata from the legacy `hive_metastore` catalog. If you omit this flag, the migration extractor tool skips the `hive_metastore` catalog and extracts metadata only from Unity Catalog. If you pass `--database` together with `--warehouse`, include `hive_metastore` in the `--database` list to extract `hive_metastore`. | No |

#### Examples

To extract Unity Catalog metadata from a Databricks workspace into
Cloud Storage by passing a PAT or OAuth token, run the following
command:

```
gcloud alpha bq migration metadata extract \
    --connector=databricks \
    --output=gs://BUCKET/databricks-metadata.zip \
    -- \
    --url https://WORKSPACE_HOST \
    --password DATABRICKS_TOKEN
```

To include the legacy `hive_metastore` catalog when filtering Unity Catalog
catalogs and authenticate with the `DATABRICKS_TOKEN` environment variable,
run the following command:

```
DATABRICKS_TOKEN=DATABRICKS_TOKEN \
    gcloud alpha bq migration metadata extract \
        --connector=databricks \
        --output=gs://BUCKET/databricks-metadata.zip \
        -- \
        --url https://WORKSPACE_HOST \
        --warehouse WAREHOUSE_ID \
        --database hive_metastore,CATALOG_1,CATALOG_2
```

If your Databricks environment uses a self-managed or external
Hive Metastore, extract metadata by using the `hiveql`
connector:

```
gcloud alpha bq migration metadata extract \
    --connector=hiveql \
    --output=gs://BUCKET/hive-metadata.zip \
    -- \
    --host METASTORE_HOST \
    --port 9083
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `WORKSPACE_HOST`: the hostname of your Databricks workspace.
- `DATABRICKS_TOKEN`: a Databricks PAT or OAuth token for the authenticating user or service principal.
- `WAREHOUSE_ID`: the ID of the Databricks SQL warehouse used to extract metadata from the `hive_metastore` catalog.
- `CATALOG_1` and `CATALOG_2`: the Unity Catalog catalog names to extract. Include `hive_metastore` in `--database` when filtering catalogs alongside `--warehouse`, or omit `--database` to extract all accessible Unity Catalog catalogs plus `hive_metastore`.
- `METASTORE_HOST`: the hostname or IP address of your self-managed Hive Metastore Thrift server.

#### Upload the metadata archive

If you wrote the metadata ZIP archive to a local path instead of directly to
Cloud Storage using `--output`, upload it to the
Cloud Storage bucket that contains your SQL translation input
files. For instructions, see
[Upload input files to Cloud Storage](https://docs.cloud.google.com/bigquery/docs/batch-sql-translator.md.txt#upload-files).
For more information about how the translator uses extracted Databricks
metadata, see
[Extracted Databricks metadata archive](https://docs.cloud.google.com/bigquery/docs/migration/databricks-sql.md.txt#schema-mapping-profile).

### Azure Synapse or Microsoft SQL Server

In local mode (`--run-mode=local`), the `bqms` component automatically
downloads the Microsoft SQL Server JDBC driver (`mssql-jdbc`) on first
use. To override the driver or run in an offline environment, download the
JDBC driver from Microsoft's
[download page](https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15)
and specify its path with `--driver`, or place the driver in `drivers/` or
`BQMS_DRIVER_DIR`.

The following table describes the commonly used flags for extracting
Azure Synapse or Microsoft SQL Server metadata by using the migration extractor tool.
For information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `sqlserver`. | Yes |
| `--database` |   | The name of the database to connect to. | Yes |
| `--driver` | Automatically downloaded on first use in local mode (`mssql-jdbc`). | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. | No (in local mode) |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | Yes |
| `--port` | 1433 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |

#### Examples

The following example shows how to extract metadata from an Azure Synapse
database on a specified host:

```bash
gcloud alpha bq migration metadata extract \
  --connector=sqlserver \
  --output=gs://BUCKET/sqlserver-metadata.zip \
  -- \
  --database database \
  --host server_name.sql.azuresynapse.net \
  --password password \
  --user user
```

### Greenplum

In local mode (`--run-mode=local`), the `bqms` component automatically
downloads the PostgreSQL JDBC driver on first use. To override the
default PostgreSQL driver or run in an offline environment,
download the driver from PostgreSQL's
[download page](https://jdbc.postgresql.org/) and specify its path with
`--driver`, or place the driver in `drivers/` or `BQMS_DRIVER_DIR`. To use
VMware Greenplum's DataDirect JDBC driver instead, download it from VMware
Greenplum's
[download page](https://docs.vmware.com/en/VMware-Greenplum/7/greenplum-database/datadirect-datadirect_jdbc.html)
and specify its JAR explicitly with `--driver`, along with
`--jdbcDriverClass` and `--url` if needed.

The following table describes the commonly used flags for extracting
Greenplum metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `greenplum`. | Yes |
| `--database` |   | The name of the database to connect to. | Yes |
| `--driver` | Automatically downloaded on first use in local mode (`postgresql`). | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. | No |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | If not specified, the migration extractor tool uses a secure prompt to request it. |
| `--port` | 5432 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |

#### Examples

The following example shows how to extract metadata for a Greenplum database
on a specified host:

```bash
gcloud alpha bq migration metadata extract \
  --connector=greenplum \
  --output=gs://BUCKET/greenplum-metadata.zip \
  -- \
  --database database \
  --host host \
  --password password \
  --user user
```

### Netezza

To connect the migration extractor tool to IBM Netezza,
obtain the Netezza JDBC driver. You can usually get the
driver from the `/nz/kit/sbin` directory on your
Netezza appliance host. If you can't locate it there,
ask your system administrator for help, or read
[Installing and Configuring JDBC](https://www.ibm.com/docs/en/psfa/latest?topic=configuration-installing-configuring-jdbc)
in the IBM Netezza documentation.

The following table describes the commonly used flags for extracting
IBM Netezza metadata by using the
migration extractor tool. For information about all supported flags,
see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `netezza`. | Yes |
| `--database` |   | A list of the databases to extract, separated by commas. | Yes |
| `--driver` |   | The absolute or relative path to the driver JAR file to use for this connection. You can specify multiple driver JAR files, separating them by commas. | Yes |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | Yes |
| `--port` | 5480 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |

#### Examples

The following example shows how to extract metadata for two IBM Netezza
databases on a specified host:

```
gcloud alpha bq migration metadata extract \
    --connector=netezza \
    --output=gs://BUCKET/netezza-metadata.zip \
    -- \
    --database DATABASE1,DATABASE2 \
    --driver PATH/nzjdbc.jar \
    --host HOST \
    --password \
    --user USER
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `DATABASE1` and `DATABASE2`: the databases to extract metadata from.
- `PATH`: the absolute or relative path to the driver JAR file.
- `HOST`: the hostname or IP address of the Netezza server.
- `USER`: the username for the database connection.

### PostgreSQL

In local mode (`--run-mode=local`), the `bqms` component automatically
downloads the PostgreSQL JDBC driver on first use. To override the
driver or run in an offline environment, download the JDBC driver from
PostgreSQL's [download page](https://jdbc.postgresql.org/) and specify its
path with `--driver`, or place the driver in `drivers/` or
`BQMS_DRIVER_DIR`.

The following table describes the commonly used flags for extracting
PostgreSQL metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `postgresql`. | Yes |
| `--database` |   | The name of the database to connect to. | Yes |
| `--driver` | Automatically downloaded on first use in local mode (`postgresql`). | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. | No |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | If not specified, the migration extractor tool uses a secure prompt to request it. |
| `--port` | 5432 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |

#### Examples

The following example shows how to extract metadata for a PostgreSQL database
on a specified host:

```bash
gcloud alpha bq migration metadata extract \
  --connector=postgresql \
  --output=gs://BUCKET/postgresql-metadata.zip \
  -- \
  --database database \
  --host host \
  --password password \
  --user user
```

### Oracle / Oracle Exadata

In local mode (`--run-mode=local`), the `bqms` component automatically
downloads the Oracle JDBC driver (`ojdbc11`) on first use. To
override the driver or run in an offline environment, download the JDBC
driver from Oracle's
[download page](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html)
and specify its path with `--driver`, or place the driver in `drivers/` or
`BQMS_DRIVER_DIR`.

The `oracle` and `oracle-stats` connectors also support
Oracle Exadata.

The following table describes the commonly used flags for extracting
Oracle metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `oracle`. | Yes |
| `--driver` | Automatically downloaded on first use in local mode (`ojdbc11`). | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. | No (in local mode) |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--oracle-service` |   | The Oracle service name to use for the connection. | Not explicitly, but you must specify either this flag or the `--oracle-sid` flag. |
| `--oracle-sid` |   | The Oracle system identifier (SID) to use for the connection. | Not explicitly, but you must specify either this flag or the `--oracle-service` flag. |
| `--password` |   | The password to use for the database connection. | If not specified, the migration extractor tool uses a secure prompt to request it. |
| `--port` | 1521 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. The user you specify must have the role `SELECT_CATALOG_ROLE` in order to extract metadata. To see whether the user has the required role, run the query `select granted_role from user_role_privs;` against the Oracle database. | Yes |

#### Examples

The following example shows how to extract metadata for an Oracle database
on a specified host, using the Oracle service for the connection:

```bash
gcloud alpha bq migration metadata extract \
  --connector=oracle \
  --output=gs://BUCKET/oracle-metadata.zip \
  -- \
  --host host \
  --oracle-service service_name \
  --password password \
  --user user
```

### Snowflake

The following table describes the commonly used flags for extracting
Snowflake metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--assessment` |   | Turns on assessment mode when generating database logs or extracting metadata. The migration extractor tool generates required metadata statistics for BigQuery migration assessment when used for metadata extraction. When used for query logs, the tool extracts additional columns for BigQuery migration assessment. | Only for assessment. |
| `--connector` |   | The name of the connector to use, in this case `snowflake`. | Yes |
| `--database` |   | A comma-separated list of database names to extract. This flag is not allowed in assessment mode. | Only for translation. |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--private-key-file` |   | The path to the RSA private key used for authentication. We recommend using a [`SERVICE`](https://docs.snowflake.com/en/user-guide/admin-user-management#types-of-users) user with a key-pair based authentication. This provides the secure method for accessing Snowflake data platform without a need to generate MFA tokens. Requires `--run-mode=local`, the default. | No, if not provided the migration extractor tool uses a password based authentication. |
| `--private-key-password` |   | The password that was used when creating the RSA private key. | No, it is required only if the private key is encrypted. |
| `--password` |   | The password to use for the database connection. | If not specified, the migration extractor tool uses a secure prompt to request it. However, we recommend using key-pair based authentication instead. |
| `--query-log-start` |   | The start time (inclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the `snowflake-logs` connector. Example: `--query-log-start "2023-01-01 14:00:00"` | No |
| `--query-log-end` |   | The end time (exclusive) for query logs to extract. The value is truncated to the hour. This flag is only available for the `snowflake-logs` connector. Example: `--query-log-end "2023-01-15 22:00:00"` | No |
| `--role` |   | The Snowflake role to use for authorization. While technically optional if your default role has sufficient privileges, we highly recommend specifying a role, such as `ACCOUNTADMIN`, to ensure that the session has the necessary privileges to access the `SNOWFLAKE.ACCOUNT_USAGE` schema. For more information, see [Working with large Snowflake instances](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#large-instance). | No, but highly recommended. |
| `--user` |   | The username to use for the database connection. | Yes |
| `--warehouse` |   | The Snowflake warehouse to use for processing metadata queries. | Yes |

#### Examples

The following example shows how to extract metadata for assessment:

```
gcloud alpha bq migration metadata extract \
    --connector=snowflake \
    --output=gs://BUCKET/snowflake-metadata.zip \
    -- \
    --assessment \
    --host "ACCOUNT.snowflakecomputing.com" \
    --role ROLE \
    --user USER \
    --private-key-file PRIVATE_KEY_FILE \
    --private-key-password PRIVATE_KEY_PASSWORD \
    --warehouse WAREHOUSE
```

The following example shows how to extract metadata for a typically sized
Snowflake database:

```
gcloud alpha bq migration metadata extract \
    --connector=snowflake \
    --output=gs://BUCKET/snowflake-metadata.zip \
    -- \
    --database DATABASE \
    --host "ACCOUNT.snowflakecomputing.com" \
    --user USER \
    --private-key-file PRIVATE_KEY_FILE \
    --private-key-password PRIVATE_KEY_PASSWORD \
    --warehouse WAREHOUSE
```

The following example shows how to extract metadata for a large
Snowflake database on a specified host:

```
gcloud alpha bq migration metadata extract \
    --connector=snowflake \
    --output=gs://BUCKET/snowflake-metadata.zip \
    -- \
    --database DATABASE \
    --host "ACCOUNT.snowflakecomputing.com" \
    --role ROLE \
    --user USER \
    --private-key-file PRIVATE_KEY_FILE \
    --private-key-password PRIVATE_KEY_PASSWORD \
    --warehouse WAREHOUSE
```

Alternatively, you can use the following example to extract metadata using
password-based authentication:

```
gcloud alpha bq migration metadata extract \
    --connector=snowflake \
    --output=gs://BUCKET/snowflake-metadata.zip \
    -- \
    --database DATABASE \
    --host "ACCOUNT.snowflakecomputing.com" \
    --password PASSWORD \
    --user USER \
    --warehouse WAREHOUSE
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `DATABASE`: the database name to extract (translation only).
- `ACCOUNT`: your Snowflake account identifier.
- `ROLE`: your Snowflake role.
- `USER`: your Snowflake username.
- `PRIVATE_KEY_FILE`: the local path to your RSA private key file (requires `--run-mode=local`).
- `PRIVATE_KEY_PASSWORD`: the password for an encrypted private key.
- `WAREHOUSE`: your Snowflake warehouse.
- `PASSWORD`: your Snowflake password.

#### Working with large Snowflake instances

The migration extractor tool reads metadata from the Snowflake
`INFORMATION_SCHEMA`. However, there is a limit to the amount of data you can
retrieve from `INFORMATION_SCHEMA`. If you run the
migration extractor tool and receive the error `SnowflakeSQLException:
Information schema query returned too much data`, you
must take the following steps so that you can read metadata from the
`SNOWFLAKE.ACCOUNT_USAGE` schema instead:

1. Open the **Shares** option in the Snowflake web interface.
2. Create a database from the `SNOWFLAKE.ACCOUNT_USAGE` share:

       -- CREATE DATABASE database FROM SHARE SNOWFLAKE.ACCOUNT_USAGE;

3. Create a role:

       CREATE ROLE role;

4. Grant `IMPORTED` privileges on the new database to the role:

       GRANT IMPORTED PRIVILEGES ON DATABASE database TO ROLE role;

5. Grant the role to the user you intend to use to run the
   migration extractor tool:

       GRANT ROLE role TO USER user;

### Vertica

To connect the migration extractor tool to Vertica, download
the Vertica JDBC driver from their
[download page](https://www.vertica.com/download/vertica/client-drivers/).

The following table describes the commonly used flags for extracting
Vertica metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `vertica`. | Yes |
| `--database` |   | The name of the database to connect to. | Yes |
| `--driver` |   | The absolute or relative path to the driver JAR file to use for this connection. You can specify multiple driver JAR files, separating them by commas. | Yes |
| `--host` | localhost | The hostname or IP address of the database server. | No |
| `--password` |   | The password to use for the database connection. | Yes |
| `--port` | 5433 | The port of the database server. | No |
| `--user` |   | The username to use for the database connection. | Yes |

#### Examples

The following example shows how to extract metadata from a Vertica
database on the local host:

```
gcloud alpha bq migration metadata extract \
    --connector=vertica \
    --output=gs://BUCKET/vertica-metadata.zip \
    -- \
    --driver PATH/vertica-jdbc.jar \
    --database DATABASE \
    --user USER \
    --password PASSWORD
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `PATH`: the path to the Vertica JDBC driver JAR file.
- `DATABASE`: the name of the database to connect to.
- `USER`: the username for the database connection.
- `PASSWORD`: the password for the database connection.

### BigQuery

The following table describes the commonly used flags for extracting
BigQuery metadata by using the migration extractor tool. For
information about all supported flags, see [global flags](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#global_flags).

| **Name** | **Default value** | **Description** | **Required** |
|---|---|---|---|
| `--connector` |   | The name of the connector to use, in this case `bigquery`. | Yes |
| `--database` | Active default BigQuery project | The list of projects to extract metadata and query logs from, separated by commas. | No |
| `--schema` | All accessible datasets | The list of datasets to extract metadata and query logs from, separated by commas. | No |

#### Examples

The following example shows how to extract metadata from BigQuery
projects and datasets:

```
gcloud alpha bq migration metadata extract \
    --connector=bigquery \
    --output=gs://BUCKET/bigquery-metadata.zip \
    -- \
    --database PROJECT1,PROJECT2 \
    --schema DATASET1,DATASET2
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `PROJECT1` and `PROJECT2`: the project IDs to extract metadata from.
- `DATASET1` and `DATASET2`: the dataset names to extract metadata from.

## Global flags

The following table describes the flags that can be used with any of the
supported source platforms. Pass `--connector` and `--output` before `--`, and
pass all other flags after `--`.

| **Name** | **Description** |
|---|---|
| `--connector` | The connector name for the source system (passed before `--`). |
| `--database` | Usage varies by source system. |
| `--driver` | The absolute or relative path to the driver JAR file to use for this connection, and overrides the automatically downloaded driver. You can specify multiple driver JAR files by separating them with commas. This flag is required for user-supplied proprietary drivers, such as `teradata`, `netezza`, and `vertica` drivers. This flag is optional in local mode for connectors whose drivers are [automatically downloaded on first use](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#jdbc-drivers), where it overrides the downloaded driver. |
| `--dry-run` or `-n` | Show what actions the migration extractor tool would make without executing them. |
| `--help` | Displays command-line help. |
| `--host` | The hostname or IP address of the database server to connect to. |
| `--jdbcDriverClass` | Optionally overrides the vendor-specified JDBC driver class name. Use this if you have a custom JDBC client. |
| `--output` | The target path where the output ZIP file is written (passed before `--`): a Cloud Storage URI (`gs://BUCKET/PATH`) or, in local mode (`--run-mode=local`), a local file or directory path. When writing to Cloud Storage in local mode, to authenticate using Google Cloud credentials, see [Set up Application Default Credentials](https://docs.cloud.google.com/docs/authentication/provide-credentials-adc.md.txt). |
| `--password` | The password to use for the database connection. |
| `--port` | The port of the database server. |
| `--save-response-file` | Saves your extractor flags in a JSON file named `dumper-response-file.json` in your working directory for reuse in local mode (`--run-mode=local`). Before reusing the file, remove the `connector` and `output` entries from it, and then pass the path prefixed by `@` after `--`. |
| `--schema` | A list of the schemas to extract, separated by commas. Oracle doesn't differentiate between a [schema](https://docs.oracle.com/cd/B19306_01/server.102/b14196/schema.htm#CFHHBEGH) and the database user who created the schema, so you can use either schema names or user names with the `--schema` flag. For example, `--schema schema1,user2,schema3`. |
| `--thread-pool-size` | Sets the thread pool size for connectors that support parallel extraction (`hiveql`, `redshift`, `redshift-raw-logs`, and `hdfs`; on `redshift-serverless-logs`, it sets only the JDBC connection pool size). The default value is `32`. If the migration extractor tool seems slow or needs more resources, you can raise the number of threads used. If other processes on the machine require more capacity, you can lower the number of threads used. |
| `--url` | The URL to use for the database connection, instead of the URI generated by the JDBC driver. The generated URI should be sufficient in most cases. Only override the generated URI when you need to use a JDBC connection setting that is specific to the source platform and is not already set by one of the flags listed in this table. |
| `--user` | The username to use for the database connection. |
| `--version` | Displays the product version. |
| `--telemetry` | Collects insights into the performance characteristics of runs, such as duration, run counts, and resource usage. This is enabled by default. To disable telemetry, set this flag to `false`. |

## Troubleshooting

The following sections explain some common issues and troubleshooting techniques
for the migration extractor tool.

### Out of memory error

The `java.lang.OutOfMemoryError` error in the migration extractor tool
terminal output is often related to insufficient memory for processing retrieved
data. To address this issue, increase available memory or reduce the number of
processing threads.

You can increase maximum memory by exporting the `JAVA_OPTS` environment
variable:

### Linux

```bash
export JAVA_OPTS="-Xmx4G"
```

### Windows

```bash
set JAVA_OPTS="-Xmx4G"
```

You can reduce the number of processing threads (the default is 32) by including
the `--thread-pool-size` flag. On `hiveql`, `redshift`, `redshift-raw-logs`, and
`hdfs`, this flag sets the worker thread pool size; on
`redshift-serverless-logs`, it sets only the JDBC connection pool size:

```
gcloud alpha bq migration metadata extract \
    --connector=CONNECTOR \
    --output=gs://BUCKET/PATH \
    -- \
    --thread-pool-size=1
```

For query log connectors (`redshift-raw-logs` and `redshift-serverless-logs`),
use `gcloud alpha bq migration query-logs extract` instead of
`metadata extract`.

Replace the following:

- `CONNECTOR`: the connector name for your source system.
- `BUCKET`: the name of your Cloud Storage bucket.
- `PATH`: the path of the output ZIP file in the bucket.

### Handling a `WARN...Task failed` error

You might sometimes see a
`WARN [main] o.c.a.d.MetadataDumper [MetadataDumper.java:107] Task failed: ...`
error in the migration extractor tool terminal output. The
migration extractor tool submits multiple queries to the source system, and
the output of each query is written to its own file. Seeing this issue indicates
that one of these queries failed. However, the failure of one query doesn't
prevent the execution of the other queries. If you see more than a couple of
`WARN` errors, review the issue details and see if there's anything that you
need to correct for the query to run appropriately. For example, if the database
user you specified when running the migration extractor tool lacks
permissions to read all metadata, try again with a user with the correct
permissions.

### Teradata query logs extraction is slow

To improve the performance of joining tables that are specified by the
`-Dteradata-logs.query-logs-table` and `-Dteradata-logs.sql-logs-table` flags,
you can include an additional column of type `DATE` in the `JOIN` condition.
This column must be defined in both tables and must be part of the Partitioned
Primary Index. To include this column, use the `-Dteradata-logs.log-date-column`
flag.

The following example shows how to use the `-Dteradata-logs.log-date-column`
flag:

### Bash

```
gcloud alpha bq migration query-logs extract \
    --connector=teradata-logs \
    --output=gs://BUCKET/teradata-logs.zip \
    -- \
    --driver PATH/terajdbc4.jar \
    --host HOST \
    --user USER \
    --password \
    -Dteradata-logs.query-logs-table=historicdb.ArchivedQryLogV \
    -Dteradata-logs.sql-logs-table=historicdb.ArchivedDBQLSqlTbl \
    -Dteradata-logs.log-date-column=ArchiveLogDate
```

### Windows PowerShell

```
gcloud alpha bq migration query-logs extract `
    --connector=teradata-logs `
    --output=gs://BUCKET/teradata-logs.zip `
    -- `
    --driver PATH\terajdbc4.jar `
    --host HOST `
    --user USER `
    --password `
    "-Dteradata-logs.query-logs-table=historicdb.ArchivedQryLogV" `
    "-Dteradata-logs.sql-logs-table=historicdb.ArchivedDBQLSqlTbl" `
    "-Dteradata-logs.log-date-column=ArchiveLogDate"
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `PATH`: the absolute or relative path to the driver JAR file for this connection.
- `HOST`: the host address of your Teradata server.
- `USER`: the username for the database connection.

### Teradata row size limit exceeded

Teradata version 15 has a 64 KB row size limit. If the limit is
exceeded, the migration extractor tool fails with the following message:

    [Error 9804] [SQLState HY000] Response Row size or Constant Row size overflow

To resolve this error, either extend the row limit to 1 MB or split the rows
into multiple rows:

- Install and enable the 1 MB Perm and Response Rows feature and current TTU software. For more information, see [Teradata Database Message 9804](https://docs.teradata.com/r/Teradata-VantageCloud-Lake-Analytics-Database-Messages/Database-Messages/9804).
- Split the long query text into multiple rows by using the `-Dteradata.metadata.max-text-length` and `-Dteradata-logs.max-sql-length` flags.

The following command shows how to use the
`-Dteradata.metadata.max-text-length` flag to split long query text into
multiple rows of at most 10,000 characters each:

### Bash

```
gcloud alpha bq migration metadata extract \
    --connector=teradata \
    --output=gs://BUCKET/teradata.zip \
    -- \
    --driver PATH/terajdbc4.jar \
    --host HOST \
    --user USER \
    --password \
    -Dteradata.metadata.max-text-length=10000
```

### Windows PowerShell

```
gcloud alpha bq migration metadata extract `
    --connector=teradata `
    --output=gs://BUCKET/teradata.zip `
    -- `
    --driver PATH\terajdbc4.jar `
    --host HOST `
    --user USER `
    --password `
    "-Dteradata.metadata.max-text-length=10000"
```

The following command shows how to use the `-Dteradata-logs.max-sql-length`
flag to split long query text into multiple rows of at most 10,000 characters
each:

### Bash

```
gcloud alpha bq migration query-logs extract \
    --connector=teradata-logs \
    --output=gs://BUCKET/teradata-logs.zip \
    -- \
    --driver PATH/terajdbc4.jar \
    --host HOST \
    --user USER \
    --password \
    -Dteradata-logs.max-sql-length=10000
```

### Windows PowerShell

```
gcloud alpha bq migration query-logs extract `
    --connector=teradata-logs `
    --output=gs://BUCKET/teradata-logs.zip `
    -- `
    --driver PATH\terajdbc4.jar `
    --host HOST `
    --user USER `
    --password `
    "-Dteradata-logs.max-sql-length=10000"
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `PATH`: the absolute or relative path to the driver JAR file for this connection.
- `HOST`: the host address of your Teradata server.
- `USER`: the username for the database connection.

### Oracle connection issue

In common cases such as an invalid password or hostname, the
migration extractor tool prints a meaningful error message describing the
root issue. However, in some cases, the error message returned by the
Oracle server might be generic and difficult to investigate.

One of these issues is `IO Error: Got minus one from a read call`. This error
indicates that the connection to the Oracle server was
established, but the server didn't accept the client and closed the connection.
This issue typically occurs when the server accepts only `TCPS` connections. By
default, the migration extractor tool uses the `TCP` protocol. To solve
this issue, you must override the Oracle JDBC connection URL.

Instead of providing the `oracle-service`, `host`, and `port` flags, you can
resolve this issue by providing the `url` flag in the following format:
`jdbc:oracle:thin:@tcps://HOST_NAME:PORT/ORACLE_SERVICE`.
Typically, the `TCPS` port number used by the Oracle server is
`2484`.

The following example shows how to specify the connection URL in the command:

```
gcloud alpha bq migration metadata extract \
    --connector=oracle-stats \
    --output=gs://BUCKET/oracle-stats.zip \
    -- \
    --url "jdbc:oracle:thin:@tcps://HOST_NAME:PORT/ORACLE_SERVICE" \
    --assessment \
    --user "USER" \
    --password
```

Replace the following:

- `BUCKET`: the name of your Cloud Storage bucket.
- `HOST_NAME`: the hostname or IP address of the Oracle server.
- `PORT`: the `TCPS` port number of the Oracle server (typically `2484`).
- `ORACLE_SERVICE`: the Oracle service name.
- `USER`: the username for the database connection.

In addition to changing the connection protocol to `TCPS`, you might need to
provide the trustStore SSL configuration that is required to verify the
Oracle server certificate. A missing SSL configuration results in
an `Unable to find valid certification path` error message. To resolve this
issue in local mode (`--run-mode=local`), set the `JAVA_OPTS` environment
variable:

### Linux

```
export JAVA_OPTS='-Djavax.net.ssl.trustStore="JKS_FILE_LOCATION" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStorePassword="PASSWORD"'
```

### Windows

```
set JAVA_OPTS=-Djavax.net.ssl.trustStore="JKS_FILE_LOCATION" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStorePassword="PASSWORD"
```

Depending on your Oracle server configuration, you might also
need to provide the keyStore configuration. For more information about
configuration options, see
[Oracle Database JDBC Developer's Guide](https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/client-side-security.html).

### Databricks Unity Catalog extraction returns fewer tables than expected

When extracting metadata from Databricks Unity Catalog, the
migration extractor tool returns only the catalogs, schemas, and tables
that the authenticating user or service principal has permission to browse.

To resolve this issue, grant the authenticating principal metastore
administrator privileges, or grant the `USE CATALOG`, `USE SCHEMA`, and `BROWSE`
privileges on each catalog that you want to extract, and then rerun the
migration extractor tool. For more information about required permissions,
see
[Required Databricks permissions](https://docs.cloud.google.com/bigquery/docs/generate-metadata.md.txt#databricks-permissions).

### Databricks extraction fails with HTTP 429 rate-limit errors

When extracting metadata from a large Databricks Unity Catalog or legacy
Hive metastore, the migration extractor tool might
encounter `HTTP 429 Too Many Requests` responses from the Databricks REST API.

By default, the migration extractor tool throttles requests and retries
rate-limited calls with exponential backoff. If the extraction still fails with
`HTTP 429` errors, rerun the migration extractor tool during a period of
lower API activity or use the `--database` flag to filter the extraction to
specific catalogs.

## What's next

After the migration extractor tool writes the output archive to
Cloud Storage (or a local path), you can use the archive to
[translate SQL queries](https://docs.cloud.google.com/bigquery/docs/batch-sql-translator.md.txt) or
[run a migration assessment](https://docs.cloud.google.com/bigquery/docs/migration-assessment.md.txt).