This page shows you how to enable and disable PolyBase for your Cloud SQL for SQL Server instances.

For overview information about PolyBase, see [Cloud SQL for SQL Server support for PolyBase](https://docs.cloud.google.com/sql/docs/sqlserver/about-polybase.md.txt).

For information about how to set up configuration, see
[Configure external data sources for use with PolyBase](https://docs.cloud.google.com/sql/docs/sqlserver/configure-external-data-sources.md.txt).

## Before you begin

1. Configure your network to allow traffic between Cloud SQL for SQL Server and your external data source.
   - If SQL Server can't establish a successful connection, then the T-SQL command to set up or query the external data source fails.
   - Whether using a public or private IP address, make sure your Cloud SQL instance,
     and any supporting Google Cloud resources, have access to your external data
     source within the firewall of the data source.

     If you are using the public IP address of the Cloud SQL instance, then you also need to obtain
     access to the underlying [Compute Engine](https://docs.cloud.google.com/compute/docs/overview.md.txt) VM and must obtain its IP
     address. Since this underlying VM is not externalized to users, you must contact
     [Google Cloud Support](https://docs.cloud.google.com/sql/docs/sqlserver/getting-support.md.txt) to retrieve
     its IP address. This IP address might change if the instance is recreated.
2. To enable or disable PolyBase, you need the following permissions:
   - `cloudsql.instances.get`
   - `cloudsql.instances.update`

   Either of the following roles provide the previous permissions:
   <!-- -->

   - `roles/cloudsql.editor`
   - `roles/cloudsql.admin`

   We recommend using the [principle of least privilege](https://docs.cloud.google.com/sql/docs/sqlserver/roles-and-permissions.md.txt#best_practices)
   when granting access.

   Alternatively, you can also assign these permissions to a [custom role](https://docs.cloud.google.com/sql/docs/sqlserver/iam-roles.md.txt#custom-roles).
3. Review your instance's existing warehouse database names.

   <br />

   <br />

   When PolyBase is enabled, three new PolyBase data warehouse databases are
   created:

   <br />

   <br />

   - DWConfiguration
   - DWQueue
   - DWDiagnostics

   <br />

   <br />

   > [!WARNING]
   > If you enable PolyBase on an instance that already contains user databases with these restricted DW names, then SQL Server deletes and recreates them.

   Before enablement, use a tool like [SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/ssms/install/install)
   to verify whether any databases with these names already exist. If so, contact
   [Google Cloud support](https://docs.cloud.google.com/sql/docs/sqlserver/getting-support.md.txt)
   for help before you continue.

   <br />

   <br />

   Certain restrictions apply to these system databases:

   <br />

   <br />

   - You can't use the Google Cloud console, Cloud SQL Admin API, and gcloud CLI to perform certain operations on DW databases:
     - Create
     - Delete
     - List
     - Import
     You can, however, use the export command to take a backup of these databases.
   - You can't access DW databases using SQL Server Management Studio (SSMS).
   - If the instance is replicated, DW databases are not copied to the new resource.
   - If the instance is restored using [PITR](https://docs.cloud.google.com/sql/docs/sqlserver/backup-recovery/configure-pitr.md.txt), DW databases are not copied to the new resource.
   - DW databases are retained even after PolyBase is disabled.

   For more information, see the following resources:
   - [Install PolyBase on Linux](https://learn.microsoft.com/en-us/sql/relational-databases/polybase/polybase-linux-setup?view=sql-server-ver16&tabs=rhel)
   - [PolyBase feature summary](https://learn.microsoft.com/en-us/sql/relational-databases/polybase/polybase-versioned-feature-summary?view=sql-server-ver16#known-limitations)

## PolyBase enablement using database flags

You can enable PolyBase with your Cloud SQL for SQL Server instance using
[database flags](https://docs.cloud.google.com/sql/docs/sqlserver/flags.md.txt). The required flags vary based on
the type of external data source you want to use:

- The [`polybase`](https://docs.cloud.google.com/sdk/gcloud/reference/sql) database flag is required for all external data sources.
- If using Cloud Storage, you also need to apply the Microsoft SQL Server trace flag, [`13702`](https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql?view=sql-server-ver17#tf13702). Enabling this flag also enables other trace flags required for PolyBase support.

The following sections show you how to enable PolyBase on new and existing instances.

### Create a new instance with PolyBase enabled

To create a new instance with PolyBase enabled, run the following [`gcloud`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt#--database-flags)
command:

### Oracle

```bash
gcloud sql instances create INSTANCE_NAME \
  --database-version=VERSION --region=LOCATION \
  --root-password=PASSWORD --edition=EDITION \
  --cpu=NUMBER_OF_CPUs --memory=MEMORY_SIZE \
  --database-flags="DATABASE_FLAG"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.
- <var translate="no">VERSION</var>: the database version you want to use.
- <var translate="no">LOCATION</var>: the location of the Cloud SQL instance.
- <var translate="no">PASSWORD</var>: the password of the Cloud SQL instance.
- <var translate="no">EDITION</var>: the database edition you want to use.
- <var translate="no">NUMBER_OF_CPUs</var>: the number of CPUs you want to use.
- <var translate="no">MEMORY_SIZE</var>: the amount of memory you want to use.
- <var translate="no">DATABASE_FLAG</var>: the database flag value required to enable PolyBase,
  regardless of the type of external data source.

  You must enter, `cloud sql enable polybase=on`.

  For more information, see [Database flags](https://docs.cloud.google.com/sql/docs/sqlserver/flags.md.txt).

### Cloud Storage

```bash
gcloud sql instances create INSTANCE_NAME \
  --database-version=VERSION --region=LOCATION \
  --root-password=PASSWORD --edition=EDITION \
  --cpu=NUMBER_OF_CPUs --memory=MEMORY_SIZE \
  --database-flags="DATABASE_FLAG_CLOUD_STORAGE"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.
- <var translate="no">VERSION</var>: the database version you want to use.
- <var translate="no">LOCATION</var>: the location of the Cloud SQL instance.
- <var translate="no">PASSWORD</var>: the password of the Cloud SQL instance.
- <var translate="no">EDITION</var>: the database edition you want to use.
- <var translate="no">NUMBER_OF_CPUs</var>: the number of CPUs you want to use.
- <var translate="no">MEMORY_SIZE</var>: the amount of memory you want to use.
- <var translate="no">DATABASE_FLAG_CLOUD_STORAGE</var>: the database flag values required to
  enable PolyBase. If your external data source is Cloud Storage, then you must
  enter, `cloud sql enable polybase=on,13702=on`.

  For more information, see [Database flags](https://docs.cloud.google.com/sql/docs/sqlserver/flags.md.txt).

### Enable PolyBase on an existing instance

To enable PolyBase on an existing instance, run the following
[`gcloud`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/patch.md.txt#--database-flags) command:

### Oracle

```bash
gcloud sql instances patch INSTANCE_NAME \
--database-flags="DATABASE_FLAG"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.
- <var translate="no">DATABASE_FLAG</var>: the database flag value required to enable PolyBase, regardless of the type of external data source.

You must enter, `cloud sql enable polybase=on`.

This example is for illustrative purposes only. Running a `patch` operation with
a specific database flag setting replaces any existing database flags. Make sure
to include any existing database flags you want to keep. If you omit a previously
set database flag, then the omitted flag is reverted to its default value.

For more information, see [Database flags](https://docs.cloud.google.com/sql/docs/sqlserver/flags.md.txt).

### Cloud Storage

```bash
gcloud sql instances patch INSTANCE_NAME \
--database-flags="DATABASE_FLAG_CLOUD_STORAGE"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.
- <var translate="no">DATABASE_FLAG_CLOUD_STORAGE</var>: the database flag value required to enable PolyBase, regardless of the type of external data source.

You must enter, `cloud sql enable polybase=on,13702=on`.

This example is for illustrative purposes only. Running a `patch` operation with
a specific database flag setting replaces any existing database flags. Make sure
to include any existing database flags you want to keep. If you omit a previously
set database flag, then the omitted flag is reverted to its default value.

For more information, see [Database flags](https://docs.cloud.google.com/sql/docs/sqlserver/flags.md.txt).

## Check instance configuration

To check whether PolyBase is enabled on an existing instance, run the following
[`gcloud`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt#--database-flags)
command:

### gcloud

```bash
gcloud sql instances describe INSTANCE_NAME \
  --format="value(settings.databaseFlags)"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.

## Disable PolyBase

To disable PolyBase on an instance, run the following [`gcloud`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt#--database-flags)
command:

### gcloud

```bash
gcloud sql instances patch INSTANCE_NAME \
--database-flags="cloud sql enable polybase=off"
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the name of the Cloud SQL instance.

When PolyBase is disabled, the following PolyBase resources aren't deleted:

- DW system databases
- Database master key (DMK)
- Data sources
- Data scoped credentials
- External tables

These resources are kept in the event you want to re-enable the feature in the
future.

## What's next

- [Cloud SQL for SQL Server support for PolyBase](https://docs.cloud.google.com/sql/docs/sqlserver/about-polybase.md.txt)
- [Configure external data sources for use with PolyBase](https://docs.cloud.google.com/sql/docs/sqlserver/configure-external-data-sources.md.txt)