4

I have a google cloud sql postgresql instance. When I try to import postgresql dump I get following error.

enter image description here

I am able to connect to instance with the command given below.

gcloud sql connect instance-name --user postgres

It takes me to the psql command line client where I can not use database restore command like pg_restore

Does anyone have an idea on how can I actually connect to Google Cloud SQL instance so that I can perform operation such as pg_restore?

Zachary Newman
  • 20,014
  • 4
  • 39
  • 37
Akshay Mohite
  • 2,168
  • 1
  • 16
  • 22
  • Near the gift icon, in the upper right corner, you have the command prompt button. That will allow you to connect to the console so you could be abble to launch pg_restore... – Arkhena Jun 22 '17 at 07:13

1 Answers1

7

if you need pg_restore can simply use:

gcloud sql connect instance-name --user postgres < dbbackup.sql

where dbbackup.sql is a file obtained from:

pg_dump olddb --format=plain --no-owner -v >> dbbackup.sql

Phil
  • 115
  • 1
  • 11
  • Where does this file exactly created at ? "dbbackup.sql" – london_utku Jul 07 '20 at 08:10
  • 1
    This will import into the postgres database, you need to add PGDATABASE=yourdb to the gcloud command to specify your database. Note that despite google's docs, you CANNOT specify the database on the command line: https://stackoverflow.com/questions/47299696/specifying-the-db-to-connect-with-gcloud-sql – Jerod Venema Aug 22 '20 at 19:07