Quickstart for Cloud SQL for PostgreSQL

This page shows you how to create and connect to a PostgreSQL instance and perform basic SQL operations using the Google Cloud Platform Console and a client.

Before you begin

  1. Accede a tu Cuenta de Google.

    Si todavía no tienes una cuenta, regístrate para obtener una nueva.

  2. Selecciona o crea un proyecto de GCP.

    Ir a la página Administrar recursos

  3. Comprueba que la facturación esté habilitada en tu proyecto.

    Descubre cómo puedes habilitar la facturación

Create an instance

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

    Go to the Cloud SQL Instances page

  2. Select your project and click Continue.

  3. Click Create Instance.

  4. Click PostgreSQL.

  5. Enter myinstance for Instance ID.

    Screenshot of the top part of the instance creation screen

  6. Enter a password for the postgres user.

  7. Use the default values for the other fields.

  8. Click Create.

    You are returned to the instances list; you can click into the new instance right away to see the details, but it won't be available until it initializes and starts.

Connect to your instance using the psql client in Cloud Shell

  1. In the Google Cloud Platform Console, click the Cloud Shell icon (Cloud Shell icon) in the upper right corner.

    When Cloud Shell finishes initializing, you should see:

    Welcome to Cloud Shell! Type "help" to get started.

  2. At the Cloud Shell prompt, connect to your Cloud SQL instance:

    gcloud sql connect myinstance --user=postgres
  3. Enter your postgres password.

    You should see the psql prompt.

Create a database and upload data

  1. Insert sample data into the postgres database:
    CREATE TABLE guestbook (guestName VARCHAR(255), content VARCHAR(255),
                            entryID SERIAL PRIMARY KEY);
    INSERT INTO guestbook (guestName, content) values ('first guest', 'I got here!');
    INSERT INTO guestbook (guestName, content) values ('second guest', 'Me too!');
  2. Retrieve the data:
    SELECT * FROM guestbook;
    You should see:
      guestname   |   content   | entryid
     first guest  | I got here! |       1
     second guest | Me too!     |       2
    (2 rows)

Clean up

To avoid incurring charges to your GCP account for the resources used in this quickstart, follow these steps.

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
    Go to the Cloud SQL Instances page
  2. Select the myinstance instance to open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. In the Delete instance window, type myinstance, then click Delete to delete the instance.

    You cannot reuse an instance name for about 7 days after an instance is deleted.

What's next

¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Cloud SQL for PostgreSQL