简体   繁体   English

Node.js PGAdmin 谷歌云连接

[英]Node.js PGAdmin Google Cloud Connecttion

In [ProjectA] I have在 [ProjectA] 我有

  1. A VM Instance running Node.js运行 Node.js 的 VM 实例
  2. A cloud PGAdmin Database.云 PGAdmin 数据库。

I need help to connect the database from the Node Application.我需要帮助才能从节点应用程序连接数据库。 I am getting this error.我收到此错误。

Error: connect ENOENT /[InstanceName]/.s.PGSQL.5432 at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
errno: 'ENOENT',  code: 'ENOENT', syscall: 'connect', address: ‘/[InstanceName]/.s.PGSQL.5432'

Suggestions/help would really be appreciated.建议/帮助将不胜感激。 This is my connection in the node.这是我在节点中的连接。

user: 'postgres',//host: ‘[Host-Name]',
socketPath: ['Host-name', //host:[ExternalIP],
database: [Database],
password: [Password],

As the database is in Cloud SQL in the same project what you can do to connect is to use the Cloud SQL Proxy and by that you will be able to connect as to a local database to your VM.由于数据库位于同一项目中的 Cloud SQL 中,因此您可以使用 Cloud SQL 代理进行连接,这样您就可以将本地数据库连接到您的 VM。

To install and run the cloud SQL proxy you can follow This , I also put the instructions in general here:要安装和运行云 SQL 代理,你可以按照这个,我也把说明放在这里:

1) Get the SQL Proxy and make it executable. 1) 获取 SQL 代理并使其可执行。 For this you need to run the following 2 line in the VM:为此,您需要在 VM 中运行以下 2 行:

wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy

chmod +x cloud_sql_proxy

2) Create a service Account with the role of CloudSQL Client as detailed here 2) 创建一个具有 CloudSQL Client 角色的服务帐户,详见此处

3) Create a key for the service account and upload it to your VM 3)为服务帐户创建一个密钥并将其上传到您的VM

4) Start the SQL proxy by running this command: 4) 通过运行以下命令启动 SQL 代理:

./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:5432 \
                  -credential_file=<PATH_TO_KEY_FILE> &

5) Connect in your app as if the Database was in localhost 5)在您的应用程序中连接,就好像数据库在本地主机中一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM