问题原文
原帖链接 · Sarthak tiwari · CC BY-SA 4.0
I am connecting my pgAdmin with the VM of google cloud.
first I create VM instances after that the public IP address of VM instances I use pgAdmin hostname and when I try to save than getting an error Unable to connect to server: timeout expired
已采纳解答
原帖链接 · Serhii Rohoza · CC BY-SA 4.0
Have a look at the community tutorial How to set up PostgreSQL on Compute Engine:
This tutorial shows how to set up PostgreSQL on Google Cloud Platform (GCP) in just a few minutes. Follow this tutorial to configure PostgreSQL on an Ubuntu virtual machine instance on Compute Engine.
If you don't want to install and manage your own PostgreSQL database, Google Cloud SQL provides managed PostgreSQL.
You can also use Cloud Launcher to set up PostgreSQL on Compute Engine with just a few clicks.
You should follow steps below:
- Create VM instance.
- Install PostgreSQL and use PSQL to complete the setup.
- Configure PostgreSQL remote access:
3.1. edit
pg_hba.conf:- navigate to ip4.me to get the IPv4 address of your local computer;
- scroll down to the bottom of the file and add the following lines:
# IPv4 remote connections for the tutorial: host all all [YOUR_IPV4_ADDRESS]/32 md5 - replace [YOUR_IPV4_ADDRESS] with the address of your local computer;
- save the file and exit the editor.
3.2. edit
postgresql.conf: - scroll down to the line that begins with
#listen_addresses = 'localhost'; - delete the
#character to uncomment the line; - replace
localhostwith*(the '*' setting enables Postgres to listen on all IP addresses); - save the file and exit the editor;
- restart the database service.
- Set network tag
postgresql-serverto your VM instance:gcloud compute instances add-tags instance-1 --zone=europe-west3-a -- tags=postgresql-server - Create new firewall rule to allow incoming connections:
gcloud compute firewall-rules create postgresql-server-rule-in --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:5432 --target-tags=postgresql-server - Connect using pgAdmin:
- in the Host field, enter external IP address of your VM instance;
- in the Port field, enter 5432.
As an alternative, you can follow documentation 18.11. Secure TCP/IP Connections with SSH Tunnels:
It is possible to use SSH to encrypt the network connection between clients and a PostgreSQL server. Done properly, this provides an adequately secure network connection, even for non-SSL-capable clients.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
