0

I have exported a database as a SQL file in Google Cloud Platform Cloud SQL Postgres Database using their GUI wizard. I want to import the data from the dump into my local PostgresQL installation. I tried using PgAdmin4 with various settings but kept failing. I then tried the following command which retrieved the data but most of the relationships are gone.

psql -f "SQLFile.sql" --host "localhost" --port "5432" --username "dbusername" "myDBName"

How can I create a local clone of my Cloud SQL db?

Coola
  • 2,934
  • 2
  • 19
  • 43
  • Look inside SQLFile.sql. Does it contain those missing tables, or were they missing from the dump file as well? – jjanes Jan 10 '22 at 16:42
  • @jjanes sql file contains everything I am posting what my issue was as an answer if anyone else needs it. – Coola Jan 10 '22 at 17:45

1 Answers1

1

Posting an answer for anyone else who needs this. The following was performed on a Windows 10 machine.

  1. Export from Cloud SQL using the GCP console GUI. This will save it to a cloud storage bucket and you can download it from GCS bucket.

  2. On local machine - remove any database with the same name as the one you want to import . Then create a fresh database with the same name as the one you want to import. (in my case this was the issue)

  3. In terminal go to your PostgreSQL bin folder. Example:

cd “C:\Program Files\PostgreSQL\13\bin
  1. Then run the following command - replacing values as per your needs.
psql -f "<full-path-to-downloaded-sql-file>" --host "localhost" --port "5432" --username "<local-postgres-username>" "<db-name-to-import>”
  1. You may need to grant privileges to users on tables. This can be done using the grant wizard in pgAdmin 4 or as described in this answer.
Coola
  • 2,934
  • 2
  • 19
  • 43