How can we take schema backup for cloud SQL for PostgreSQL
Hi, @ArunBala .
You can perform this using any PostgreSQL client. To do so, please follow these steps:
# Install the PostgreSQL client on your local machine or Cloud Shell:
sudo apt-get install postgresql-client
# Using pg_dump with --schema-only (if you're using Public IP with CloudSQL)
pg_dump --host=<INSTANCE_IP_OR_HOSTNAME> \
--port=5432 \
--username=<USERNAME> \
--dbname=<DATABASE_NAME> \
--schema-only \
--no-password > schema_backup.sql
# If your Cloud SQL instance doesn't have a public IP or is restricted, use the Cloud SQL Auth proxy:
./cloud-sql-proxy <INSTANCE_CONNECTION_NAME> &
pg_dump --host=127.0.0.1 \
--port=5432 \
--username=<USERNAME> \
--dbname=<DATABASE_NAME> \
--schema-only > schema_backup.sql
You can read more about it in the related documentation:
- https://cloud.google.com/sql/docs/postgres/import-export
- https://stackoverflow.com/questions/43228951/backup-of-postgresql-database-design-without-data
Regards,
Mokit