Configuring Cloud SQL Flags

This page describes how to configure Cloud SQL flags, and lists which flags you can set for your Cloud SQL instance. You use Cloud SQL flags to adjust PostgreSQL parameters and options, to configure and tune your instance.

In some cases, setting one flag may require that you set another flag to fully enable the desired functionality.

When you set, remove, or modify a flag for an instance, the instance might be restarted. The flag value is then persisted for the instance until you remove it.

Configuring Cloud SQL flags

Setting a Cloud SQL flag

Console

  1. In the Google Cloud Platform Console, create a new Cloud Platform Console project, or open an existing project by selecting the project name.
  2. Open the instance and click Edit.
  3. Scroll down to the Flags section.
  4. To set a flag that has not been set on the instance before, click Add item, choose the flag from the drop-down menu, and set its value.
  5. Click Save to save your changes.
  6. Confirm your changes under Flags on the Overview page.

gcloud

Edit the instance:

gcloud sql instances patch [INSTANCE_NAME] --database-flags [FLAG1=VALUE1,FLAG2=VALUE2]

For flags that do not take a value, specify the flag name followed by an equals sign ("="). Include the values for all flags you want set on the instance; any flag not included is set back to its default value.

cURL

To set a flag for an existing instance:

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
       --header 'Content-Type: application/json' \
       --data '{"settings" : {"databaseFlags" : \
                                 [{ "name": "<FLAG-NAME>",  "value": "<FLAG-VALUE>" }]}}' \
       -X PATCH \
       https://www.googleapis.com/sql/v1beta4/projects/<PROJECT-ID>/instances/<INSTANCE_NAME>

If there are existing flags configured for the instance, modify the previous command to include them. The PATCH command overwrites the existing flags with the ones specified in the request.

Clearing all flags to their default value

Console

  1. In the Google Cloud Platform Console, create a new Cloud Platform Console project, or open an existing project by selecting the project name.
  2. Open the instance and click Edit.
  3. Scroll down to the Flags section.
  4. Click the X next to all of the flags shown.
  5. Click Save to save your changes.

gcloud

Clear all flags to their default values on an instance:

gcloud sql instances patch [INSTANCE_NAME] --clear-database-flags

You are prompted to confirm that the instance will be restarted.

cURL

To clear all flags for an existing instance:

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
       --header 'Content-Type: application/json' \
       --data '{"settings" : {"databaseFlags" : []}}' \
       -X PATCH \
       https://www.googleapis.com/sql/v1beta4/projects/<PROJECT-ID>/instances/<INSTANCE_NAME>

Viewing current values of Cloud SQL flags

To view all current values of the MySQL flags, log into your MySQL instance with a MySQL Client and enter SHOW VARIABLES;.

To see what flags have been set for a Cloud SQL instance:

Console

  1. In the Google Cloud Platform Console, create a new Cloud Platform Console project, or open an existing project by selecting the project name.
  2. Select the instance to open its Overview page.

    The flags that have been set are listed under the Flags section.

gcloud

Get the instance state:

gcloud sql instances describe [INSTANCE_NAME]

In the output, database flags are listed under the settings as the collection databaseFlags. For more information on the representation of the flags in the output, see Instances Resource Representation.

cURL

To list flags configured for an instance:

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
       --header 'Content-Type: application/json' \
       -X GET \
       https://www.googleapis.com/sql/v1beta4/projects/<PROJECT-ID>/instances/<INSTANCE_NAME>?fields=settings

In the output, look for the databaseFlags field.

Supported flags

Note that for a given flag, Cloud SQL might support a different range than the corresponding PostgreSQL parameter or option.

Cloud SQL Flag Type Acceptable Values and Notes
autovacuum boolean On or Off. Default value is On.
autovacuum_analyze_scale_factor floating point Default value is 0.1, or 10% of table size.
autovacuum_analyze_threshold integer Default value is 50.
autovacuum_naptime integer Default value is 1 (1 minute).
autovacuum_vacuum_scale_factor floating point Default value is 0.2, or 20% of table size.
autovacuum_vacuum_threshold integer Default value is 50.
log_autovacuum_min_duration integer Default value is -1, which disables logging autovacuum actions.

What's next

Learn more about PostgreSQL server configuration.

Send feedback about...

Cloud SQL for PostgreSQL