This page describes how to shrink the disk size of a Cloud SQL instance.

Before you begin ΒΆ

  1. The documentation refers to checking max_wal_size β€” at the time of writing, it must be below 5 128 MB for the operation to proceed:

    sql
  2. The documentation refers to checking installed extensions - you can use this command:

    sql
  3. Find the minimum target size and estimated duration:

    bash

    Example output:

    Plaintext

    Choose a target size slightly above the minimum (e.g. 750 GB if the minimum is 722 GB).

Procedure ΒΆ

Warning

Shrinking disk requires taking the application offline. Schedule this operation during a maintenance window or outside office hours. Expect a downtime of 2 hours or more depending on instance size.

  1. Stop the application:

    bash
  2. Create a manual backup in the Cloud SQL Console (https://console.cloud.google.com/sql/instances/<instance-name>/backups) before proceeding.

  3. Start the shrink operation:

    bash

    --no-async keeps the command running and shows a spinner for the duration of the operation. Completely optional.

  4. Optional monitoring of progress (in a separate terminal):

    There is (currently) no way to monitor the progress of the operation. You can, however, check if the operation is ongoing:

    List recent operations and find the one without an end time:

    bash

    Inspect the running operation, using the UUID from the previous command:

    bash

    Optionally, watch for the application to scale back up (it should not during the operation):

    bash
  5. Start the application once the operation completes:

    Either:

    bash

    or:

    bash
  6. Verify that the application is running and that disk usage is as expected.

  7. Optionally delete the manual backup after the application has been verified stable β€” typically the next business day.

Rollback ΒΆ

If something goes wrong, restore from the manual backup you created in step 2. See the Google Cloud Console for restore options.