如何使用PostgreSQL(PSQL)在Google Cloud Platform上的Shell中更改数据库



在GCP上,连接到Google Cloud Shell时,然后使用" Gcloud SQL Connect ..."连接到PostgreSQL数据库实例,GCP将您连接到Postgres数据库。

如何更改为已经创建的另一个数据库?

是否有任何PSQL(或特定的GCP Shell(命令可以更改数据库连接?

我尚未尝试过GCP,所以我不确定在那里是否有效。但是在我的某些脚本中,我需要这样做。

在这些脚本中,我使用

c dbname

更多信息:如何在PSQL中切换数据库?

作为@scottsargent答案: c dbname是解决方案。

您需要在GCP Shell上添加末端添加半隆;,在PSQL要求时按Enter并提供用户密码以更改数据库连接:

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=>

最新更新