Skip to content

Instantly share code, notes, and snippets.

@arvindkumarbadwal
Last active March 3, 2022 07:44
Show Gist options
  • Save arvindkumarbadwal/c3b902f522247d1997c58d8dbcc0d43a to your computer and use it in GitHub Desktop.
Save arvindkumarbadwal/c3b902f522247d1997c58d8dbcc0d43a to your computer and use it in GitHub Desktop.
Postgres Command to Dump or Restore File in Docker without Owner & Privileges
--
-- Dump a PostgreSQL database into a file
-- container_name - PostgreSQL container name
-- db_user - user name to connect as.
-- db_name - name of the database to be dumped
-- -O - no-owner
-- -x - no-privileges
--
docker exec -i [container_name] pg_dump --username [db_user] [db_name] -O -x > dump.sql
--
-- Restore/Import a PostgreSQL database into a file
--
docker exec -i [container_name] pg_dump --username [db_user] [db_name] < dump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment