6

I am not able to connect through pgAdmin4 to Google Cloud SQL. Following are the credentials I am providing and getting the error messege:

enter image description here

enter image description here

1
  • Are you configuring access for public IP connections? Commented Feb 7, 2020 at 12:39

4 Answers 4

8

To connect with Google Cloud SQL using pgadmin client, you should use cloud_sql_proxy

These are the steps you need to follow:

Note: on Linux, the proxy is often called cloud_sql_proxy, on Windows, it is typically cloud-sql-proxy, or cloud-sql-proyx.x64. Make sure the binary is accessible through your PATH.

  1. Get the connection string, or connection name from GCP here: enter image description here

  2. Establish connection to Postgres.

    a) On older cloud proxy versions:

     cloud_sql_proxy -instances=<connection_string>=tcp:5433
    

    b) on recent (2024 and later) cloud proxy versions:

     cloud-sql-proxy <connection_string> --port 5433 --run-connection-test
    

    (the added --run-connection-test will ensure that the connection works by testing the connection, otherwise the proxy will exit).

  3. If you receive an error on the port, it may be in use. Choose a different port like 5434 or anything, really.

    After executing cloud_sql_proxy, you will see something like this enter image description here

  4. Now create a new server connection using pgadmin client. Use the port number you specified in step (2).

    enter image description here

    enter image description here


If you followed those steps properly it will connect and you can use it as if you were using a local pgadmin install.

Sign up to request clarification or add additional context in comments.

Comments

4

If you are configuring access for public IP connections, follow the next steps to connect with PgAdmin:

1) Create your PostgreSQL instance in Google Cloud Platform.

2) While creating the instance,

  • In Instance ID tab, write a name for your instance

  • In Default user password tab, write a password.

  • Choose the region.

  • Click on configuration options, go to Connectivity, enable Public IP, under Authorized networks, add network and their write the IP address of your PC. You can check the IP address in the link .

  • Click on create.

Then in PgAdmin:

1) In Host name/address put Public IP address of the instance.

1 Comment

This is a good answer. One suggestion is to show how to use the Cloud SQL Proxy which improves security.
2

Nibrass H has perfectly answered this question. But I would like to add that if you have already created the Instance, then you can click on 'Edit Instance' and Add your IP in 'Connections'.

Adding some Images to help you.

enter image description here

enter image description here

Comments

0

When I received Unable to connect to server: timeout expired error, the following steps helped:

  • Opened up GCP
  • then into your db instance > connections
  • Under Network you'll see Add new network
  • Enter any name and enter your IP to allow local host connections. ( your ip can be found here at: https://whatismyipaddress.com/

For more info refer to this helpful doc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.