Write SQL with Gemini assistance

This document describes how you can use Gemini, an AI-powered collaborator in Google Cloud, to help you do the following in AlloyDB for PostgreSQL:

Learn how and when Gemini for Google Cloud uses your data.

This document is intended for database administrators and data engineers who are familiar with AlloyDB, and somewhat familiar with SQL and data analysis. If you're new to AlloyDB, see AlloyDB overview.

Before you begin

  1. Ensure that Gemini Cloud Assist is set up for your Google Cloud user account and project.

  2. Optional: If you want to follow along with the examples in this document, create the Singers table using the following schema:

    CREATE TABLE Singers (
      BirthDate  TIMESTAMPTZ,
      SingerId   BIGINT PRIMARY KEY,
      FirstName  VARCHAR(1024),
      LastName   VARCHAR(1024),
      SingerInfo BYTEA
    );
    

    After you create the Singers table, click refreshRefresh to update your database schema.

To disable Gemini features in AlloyDB, repeat this step, and then deselect the Gemini features that you want to disable.

Required roles and permissions

To use Gemini with AlloyDB, you need the following permissions:

  • alloydb.clusters.get
  • alloydb.databases.list
  • alloydb.instances.executeSql
  • alloydb.instances.list
  • alloydb.users.list
  • cloudaicompanion.companions.generateCode
  • cloudaicompanion.instances.generateCode
  • serviceusage.services.get or serviceusage.services.list

You can get this permission through the roles/alloydb.admin role. If you don't have this role, contact your Organization Administrator to request access. You might also be able to get the required permissions through custom roles or other predefined roles.

Additionally, ensure that you have database-level permissions for the database that you're using for authentication.

Generate SQL queries using natural language prompts