Reputation: 654
On GCP, when you connect to Google Cloud Shell, and then connect to PostgreSQL database instance using "gcloud sql connect..." GCP connects you to postgres database.
How can I change to another database already created?
Is there any psql (or specific GCP Shell) command to change database connection?
Upvotes: 0
Views: 2002
Reputation: 654
As @scottsargent answer: \c DBNAME is the solution.
You need on GCP Shell to add a semicolon ;
at the end, press ENTER and provide the user password to change database connection when psql ask for it:
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=>
Upvotes: 1
Reputation: 101
I have not tried GCP, so I'm not sure if this works there. But in some of my scripts I've the need to do this.
In those scripts, I use
\c DBNAME
More info: How to switch databases in psql?
Upvotes: 1