Creating Instances

This page describes how to create a Cloud SQL for PostgreSQL instance.

For detailed information about all instance settings, see Instance Settings.

Creating 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. Click Create instance.
  3. Select PostgreSQL and click Next.
  4. Enter an name.

    Do not include sensitive or personally identifiable information in your instance name; it is externally visible.
    You do not need to include the project ID in the instance name. This is done automatically where appropriate (for example, in the log files).

  5. Enter a password for the postgres user.
  6. Under Configuration options, update any other settings you need for your instance:

    Setting Notes
    Machine type and storage
    Cores The number of vCPUs for your instance. Learn more.
    Memory The amount of memory for your instance, in GiBs. Learn more.
    Storage type Determines whether your instance uses SSD or HDD storage. Learn more.
    Storage capacity The amount of storage provisioned for the instance. Learn more.
    Automatic storage increase Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more.
    Automatic backups and high availability
    High availability If you need your instance to be configured for high availability, you must select the High availability (regional) option. Learn more.
    Automatic backups The window of time when you would like backups to start. Learn more.
    Authorized networks
    Authorized networks For IP connections, only connections from authorized networks can connect to your instance. Learn more.
    Database flags
    Database flags You can use database flags to control settings and parameters for your instance. Learn more.
    Maintenance schedule
    Maintenance window Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you do not set the window, then disruptive maintenance can be done at any time. Learn more.
    Maintenance timing Your preferred timing for instance updates, relative to other instances in the same project. Learn more.

  7. Click Create.
  8. After the instance finishes initializing, click the instance name to open it.

gcloud

For information about installing and getting started with the gcloud command-line tool, see Installing GCP SDK. For information about starting Cloud Shell, see the Cloud Shell documentation.

  1. Create the instance:
    gcloud sql instances create [INSTANCE_NAME] --database-version=POSTGRES_9_6 \
           --cpu=[NUMBER_CPUS] --memory=[MEMORY_SIZE]
    

    Do not include sensitive or personally identifiable information in your instance name; it is externally visible.
    You do not need to include the project ID in the instance name. This is done automatically where appropriate (for example, in the log files).

    There are restrictions on the values for vCPUs and memory size:

    • vCPUs must be either 1 or an even number between 2 and 32.
    • Memory must be:
      • 0.9 to 6.5 GiB per vCPU
      • A multiple of 256 MiB
      • At least 3.75 GiB (3840 MiB)

    For example, the following string creates an instance with two vCPUs and 7,680 MiB of memory:

     gcloud sql instances create myinstance --cpu=2 --memory=7680MiB \
            --database-version=POSTGRES_9_6
    

    For some sample values, see Sample machine types.

    You can also create a shared-core instance by using --tier db-f1-micro or --tier db-g1-small and dropping the --cpu and --memory parameters.

    You can add more parameters to determine other instance settings:

    Setting Parameter Notes
    Required parameters
    Database version --database-version POSTGRES_9_6
    Region --region See valid values.
    Machine type and storage
    Machine type --tier Used to specify a shared-core instance (db-f1-micro or db-g1-small). You cannot specify the --cpu or --memory parameters if you use this parameter.
    Storage type --storage-type Determines whether your instance uses SSD or HDD storage. Learn more.
    Storage capacity --storage-size The amount of storage provisioned for the instance, in GB. Learn more.
    Automatic storage increase --storage-auto-increase Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more.
    Automatic storage increase limit --storage-auto-increase-limit Determines how large Cloud SQL can automaticaly grow storage. Available only for the beta command (gcloud beta sql instances create). Learn more.
    Automatic backups and high availability
    High availability --availability-type For a highly-available instance, set to REGIONAL. Learn more.
    Automatic backups --backup-start-time The window of time when you would like backups to start. Learn more.
    Authorize networks
    Authorized networks --authorized-networks For IP connections, only connections from authorized networks can connect to your instance. Learn more.
    Add database flags
    Database flags --database-flags You can use database flags to control settings and parameters for your instance. Learn more about database flags. Learn more about how to format this parameter.
    Set maintenance schedule
    Maintenance window --maintenance-window-day,
    --maintenance-window-hour
    Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you do not set the window, then disruptive maintenance can be done at any time. Learn more.
    Maintenance timing --maintenance-release-channel Your preferred timing for instance updates, relative to other instances in the same project. Use preview for earlier updates, and production for later updates. Learn more.

  2. Note the automatically assigned IP address.

    If you are not using the Cloud SQL Proxy, you will use this address as the host address that your applications or tools use to connect to the instance.

  3. Set the password for the postgres user:
    gcloud sql users set-password postgres no-host --instance=[INSTANCE_NAME] \
           --password=[PASSWORD]
    

cURL

  1. Create the instance:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name":"[INSTANCE_NAME]", "region":"[REGION]",
                  "databaseVersion": "POSTGRES_9_6",
                  "settings": {"tier": "[TIER_STRING]",
                  "backupConfiguration": {"enabled":true}}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances
    

    Do not include sensitive or personally identifiable information in your instance name; it is externally visible.
    You do not need to include the project ID in the instance name. This is done automatically where appropriate (for example, in the log files).

    TIER_STRING is a string that represents the number of CPUs and the amount of memory you want your new instance to have. The string has the following format: db-custom-[CPUS]-[MEMORY_MBS]. For some example valid values, see Sample machine types. You can also create a shared-core instance by supplying db-f1-micro or db-g1-small for the tier parameter.

    For a complete list of parameters for this call, see the Instances:insert page. For information about instance settings, including valid values for region and machine type, see Instance Settings.

  2. When the instance finishes initializing, update the password for the postgres user:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name": "postgres", "host": "", "password": "[PASSWORD]"}' \
         -X PUT \
         'https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?host=&name=postgres'
    
  3. Retrieve the automatically assigned IPv4 address for the new instance:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]
    
    Look for the ipAddress field in the response.

Sample machine types

With custom machine types, you can configure your instance with the amount of memory and CPUs that it needs. However, there are some restrictions on these values:

  • vCPUs must be either 1 or an even number between 2 and 32.
  • Memory must be:
    • 0.9 to 6.5 GiB per vCPU
    • A multiple of 256 MiB
    • At least 3.75 GiB (3840 MiB)

Here are some sample machine type values, based on the predefined machine types available for MySQL instances:

MySQL Machine type vCPUs Memory (MiBs) API tier string
db-n1-standard-1 1 3840 db-custom-1-3840
db-n1-standard-2 2 7680 db-custom-2-7680
db-n1-standard-4 4 15360 db-custom-4-15360
db-n1-standard-8 8 30720 db-custom-8-30720
db-n1-standard-16 16 61440 db-custom-16-61440
db-n1-standard-32 32 122880 db-custom-32-122880
db-n1-standard-64 64 245760 db-custom-64-245760
db-n1-highmem-2 2 13312 db-custom-2-13312
db-n1-highmem-4 4 26624 db-custom-4-26624
db-n1-highmem-8 8 53248 db-custom-8-53248
db-n1-highmem-16 16 106496 db-custom-16-106496
db-n1-highmem-32 32 212992 db-custom-32-212992
db-n1-highmem-64 64 425984 db-custom-64-425984

What's next

Send feedback about...

Cloud SQL for PostgreSQL