To set up Gemini in Databases, perform the steps in this document:
Enable the Gemini for Google Cloud API in a Google Cloud project. An administrator typically performs this step.
Grant Identity and Access Management (IAM) roles in a Google Cloud project. An administrator typically performs this step.
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
To enable the Gemini for Google Cloud API, go to the Gemini for Google Cloud page.
In the project selector, select a project.
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
-
In the Google Cloud console, activate Cloud Shell.
In the project selector menu, select a project.
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
To grant the IAM roles that are required to use Gemini, go to the IAM & Admin page.
In the Principal column, find a principal for which you want to give access to Gemini, and then click Edit principal in that row.
In the Edit access pane, click
Add another role.In Select a role, select Gemini for Google Cloud User.
Click Add another role and select Service Usage Consumer.
Click Save.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
In the project selector menu, select a project.
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 formuser|group|serviceAccount:email
ordomain:domain
—for example,user:cloudysanfrancisco@gmail.com
,group:admins@example.com
,serviceAccount:test123@example.domain.com
, ordomain:example.domain.com
.The output is a list of policy bindings that includes the following:
- members: - user:PRINCIPAL role: roles/cloudaicompanion.user
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.
In the Google Cloud console, go to the Gemini for Google Cloud page.
Click Gemini in Databases.
The Explore Gemini pane is displayed.
Click Get Gemini in Databases.
The Admin for Gemini page is displayed.
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.
Click Review terms and turn on.
The Turn on Gemini in Databases page is displayed.
Click Purchase to activate Gemini in Databases.
Enable the Recommender API
Enable the Recommender 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.
- Before you turn on index advisor, enable enhanced Query Insights on the instance.
In the Google Cloud console, go to the Clusters page.
- From the list of clusters and instances, click an instance.
- Click Query Insights.
- Choose the database and user.
- Click Edit Settings.
- To turn on index creation recommendations on a cluster's Query Insights page, select Enable recommendations.
- 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.
- Before you enable index advisor, enable Query Insights on the instance.
- 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:
- 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:
gcloud sql instances patch INSTANCE_NAME \ --database-flags=cloudsql_index_advisor=on
Replace INSTANCE_NAME with the name of your instance.
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.
- Before you enable index advisor, enable Query Insights on the instance.
- To enable index advisor for Cloud SQL for PostgreSQL instances, run the following Google Cloud CLI command:
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.