【问题标题】:How can I change database inside Shell on Google Cloud Platform using PostgreSQL (psql)?如何使用 PostgreSQL (psql) 在 Google Cloud Platform 上的 Shell 内更改数据库?
【发布时间】:2018-04-27 17:20:01
【问题描述】:
在 GCP 上,当您连接到 Google Cloud Shell,然后使用“gcloud sql connect...”连接到 PostgreSQL 数据库实例时,GCP 会将您连接到 postgres 数据库。
如何更改到另一个已经创建的数据库?
是否有任何 psql(或特定的 GCP Shell)命令来更改数据库连接?
【问题讨论】:
标签:
database
postgresql
shell
google-cloud-platform
database-connection
【解决方案2】:
正如@scottsargent 的回答:\c DBNAME 是解决方案。
您需要在 GCP Shell 末尾添加分号 ;,按 ENTER 并在 psql 请求时提供用户密码以更改数据库连接:
postgres=> \c elboticario;
Password for user postgres:
psql (9.6.7, server 9.6.6)
SSL connection (protocol: TLSv1.2, cipher: **************-SHA256, bits: 128, compression: off)
You are now connected to database "elboticario" as user "postgres".
elboticario=>