Creating and Managing PostgreSQL Databases

This page contains information about creating, listing, and deleting PostgreSQL databases on a Cloud SQL instance.

For more information about PostgreSQL databases, see the PostgreSQL documentation.

Before you begin

Before completing the tasks on this page, you must have:

If you plan to use the psql client to create or manage your databases, you must have:

Creating a database

To create a database on the Cloud SQL instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select the instance to which you want to add a database.
  3. Select the Databases tab.
  4. Click New database.
  5. In the New database dialog, specify the name of the database, and optionally the character set and collation.
  6. Click Add.

cURL

The following request uses the databases:insert method to create a new database on the specified instance.

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     --header 'Content-Type: application/json' \
     --data '{"project": "[PROJECT-ID]", "instance": "[INSTANCE_NAME]", "name": "[DATABASE_NAME]"}' \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases -X POST

psql Client

create database [DATABASE_NAME];

Listing your databases

To list all databases on an instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select the instance for which you want to list databases.
  3. Click Databases.

    For a newly-created instance, you should see the postgres database.

cURL

The following request uses databases:list method to list the databases for an instance.

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases \
     -X GET

When you list the databases using the API, you see additional template databases and a system database that are not displayed by the console. You cannot delete or manage the system database.

psql Client

\l

When you list the databases using the psql client, you see additional template databases and a system database that are not displayed by the console. You cannot delete or manage the system database.

Deleting a database

To delete a database on the Cloud SQL instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select the instance that contains the database you want to delete.
  3. Click Databases.
  4. In the database list, find the database you want to delete and click the trash can icon.
  5. In the Delete database dialog box, click OK.

cURL

The following request uses the databases:delete method to delete the specified database.

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases/[DATABASE_NAME] -X DELETE

psql Client

drop database [DATABASE_NAME];

What's next

Send feedback about...

Cloud SQL for PostgreSQL