1

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?

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

1 Answer 1

4

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.
Sign up to request clarification or add additional context in comments.

1 Comment

It was helpful for me (y)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.