Set up Gemini in Databases

To set up Gemini in Databases, perform the steps in this document:

  1. Enable the Gemini for Google Cloud API in a Google Cloud project. An administrator typically performs this step.

  2. Grant Identity and Access Management (IAM) roles in a Google Cloud project. An administrator typically performs this step.

  3. Activate Gemini in Databases.

  4. Enable the Recommender API.

  5. Turn on index advisor (only applicable to AlloyDB for PostgreSQL, Cloud SQL for PostgreSQL, and Cloud SQL for MySQL).

Before you begin

To activate Gemini in Databases, you must have the roles/billing.admin Identity and Access Management (IAM) role.

Enable the Gemini for Google Cloud API in a Google Cloud project

This section describes the steps required to enable the Gemini for Google Cloud API in a Google Cloud project.

Console

  1. To enable the Gemini for Google Cloud API, go to the Gemini for Google Cloud page.

    Go to Gemini for Google Cloud

  2. In the project selector, select a project.

  3. Click Enable.

    The page updates and shows a status of Enabled. Gemini is now available in the selected Google Cloud project to all users who have the required IAM roles.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

  2. In the project selector menu, select a project.

  3. Enable the Gemini for Google Cloud API for Gemini using the gcloud services enable command:

    gcloud services enable cloudaicompanion.googleapis.com
    

    If you want to enable the Gemini for Google Cloud API in a different Google Cloud project, add the --project parameter:

    gcloud services enable cloudaicompanion.googleapis.com --project PROJECT_ID
    

    Replace PROJECT_ID with your Google Cloud project ID.

    The output is similar to the following:

    Waiting for async operation operations/acf.2e2fcfce-8327-4984-9040-a67777082687 to complete...
    Operation finished successfully.
    

Gemini for Google Cloud is now available in the specified Google Cloud project to all users who have the required IAM roles.

Grant IAM roles in a Google Cloud project

This section describes the steps required to grant the Gemini for Google Cloud User and Service Usage Consumer IAM roles to users.

Console

  1. To grant the IAM roles that are required to use Gemini, go to the IAM & Admin page.

    Go to IAM & Admin

  2. In the Principal column, find a principal for which you want to give access to Gemini, and then click Edit principal in that row.

  3. In the Edit access pane, click Add another role.

  4. In Select a role, select Gemini for Google Cloud User.

  5. Click Add another role and select Service Usage Consumer.

  6. Click Save.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

  2. In the project selector menu, select a project.

  3. Grant the Gemini for Google Cloud User role:

    gcloud projects add-iam-policy-binding  PROJECT_ID \
        --member=PRINCIPAL --role=roles/cloudaicompanion.user
    

    Replace PRINCIPAL with the identifier for the principal. The identifier takes the form user|group|serviceAccount:email or domain:domain—for example, user:[email protected], group:[email protected], serviceAccount:[email protected], or domain:example.domain.com.

    The output is a list of policy bindings that includes the following:

    - members:
      - user:PRINCIPAL
      role: roles/cloudaicompanion.user
    
  4. Grant the Service Usage Consumer role:

    gcloud projects add-iam-policy-binding  PROJECT_ID \
        --member=PRINCIPAL --role=roles/serviceusage.serviceUsageConsumer
    

    The output is a list of policy bindings that includes the following:

    - members:
      - user:PRINCIPAL
      role: roles/serviceusage.serviceUsageConsumer
    

For more information, see Grant a single role and gcloud projects add-iam-policy-binding.

All of the users who have been granted these roles can access Gemini for Google Cloud features in the Google Cloud console within the specified project. For more information, see Gemini for Google Cloud overview.

Activate Gemini in Databases

To activate Gemini in Databases in a Google Cloud project, perform the following steps. An administrator or project owner typically performs these steps.

  1. In the Google Cloud console, go to the Gemini for Google Cloud page.

    Gemini for Google Cloud

  2. Click Gemini in Databases.

    The Explore Gemini pane is displayed.

  3. Click Get Gemini in Databases.

    The Admin for Gemini page is displayed.

  4. Choose the billing account for which you want to activate Gemini in Databases and click Continue to Gemini in Databases page.

    The Gemini in Databases page is displayed.

  5. Click Review terms and turn on.

    The Turn on Gemini in Databases page is displayed.

  6. Click Purchase to activate Gemini in Databases.

Enable the Recommender API

Enable the Recommender API.

Enable the API

If the Recommender API isn't listed, then it is already enabled for your project.

Turn on index advisor

You can turn on index advisor for AlloyDB for PostgreSQL, Cloud SQL for MySQL 8.0 instances, and Cloud SQL for PostgreSQL 12 and later instances.

AlloyDB for PostgreSQL

The following steps describe how to turn on index advisor for AlloyDB for PostgreSQL.

  1. Before you turn on index advisor, enable enhanced Query Insights on the instance.
  2. In the Google Cloud console, go to the Clusters page.

    Go to Clusters

  3. From the list of clusters and instances, click an instance.
  4. Click Query Insights.
  5. Choose the database and user.
  6. Click Edit Settings.
  7. To turn on index creation recommendations on a cluster's Query Insights page, select Enable recommendations.
  8. Save your changes.

For more information about using index advisor in AlloyDB for PostgreSQL, see Use the index advisor with query insights.

Cloud SQL for MySQL

The following steps describe how to enable index advisor for Cloud SQL for MySQL. Index advisor for Cloud SQL for MySQL uses data from MySQL Performance Schema. By default, Cloud SQL enables MySQL Performance Schema on all MySQL 8.0 instances that have more than 15 GB of memory.

  1. Before you enable index advisor, enable Query Insights on the instance.
  2. If you already have MySQL Performance Schema enabled on your Cloud SQL for MySQL instances, then to enable index advisor, run the following gcloud CLI command:
  3. gcloud sql instances patch INSTANCE_NAME \
        --database-flags=cloudsql_index_advisor=on

    Replace INSTANCE_NAME with the name of your instance.

  4. If you don't have MySQL Performance Schema enabled on your Cloud SQL for MySQL instances, then to enable index advisor, run the following gcloud CLI command:
  5. gcloud sql instances patch INSTANCE_NAME \
       --database-flags=cloudsql_index_advisor=on,performance_schema=on

    Replace INSTANCE_NAME with the name of your instance.

For more information about configuring flags, see Configure database flags.

Cloud SQL for PostgreSQL

The following steps describe how to enable index advisor for Cloud SQL for PostgreSQL.

  1. Before you enable index advisor, enable Query Insights on the instance.
  2. To enable index advisor for Cloud SQL for PostgreSQL instances, run the following Google Cloud CLI command:
  3. gcloud sql instances patch INSTANCE_NAME \
       --database-flags=cloudsql.enable_index_advisor=on
        

    Replace INSTANCE_NAME with the name of your instance.

For more information about configuring flags, see Configure database flags.