Last active
February 15, 2024 16:57
-
-
Save mateuszdw/a5bc74677f38c0893b5ac1b50e8e8a74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Postgres hosted on local machine | |
# postgres dump commands | |
pg_dump -U postgres_user -h localhost -Fc database_name > ./path/dump.sql | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d database_name ./path/dump.sql | |
# restore with psql | |
psql -h localhost -d database_name < ./path/dump.sql | |
#### Postgres hosted on docker | |
## IMPORTANT TO USE -i not -it | |
# To dump database | |
docker exec -i app-service-db-1 pg_dump -U postgres -Fc database_name > dump.sql | |
# To restore use this command to login to psql and crate database | |
docker exec -i postgres-selfhosted-db-1 psql -U postgres | |
postgres=# CREATE DATABASE "your-database-name"; | |
CREATE DATABASE | |
postgres=# \q | |
# restore dump file .gz | |
gunzip < your-database-name-dump.sql.gz | docker exec -i postgres-selfhosted-db-1 psql -U postgres -d your-database-name | |
# restore dump file .sql | |
cat your-database-name-dump.sql | docker exec -i postgres-selfhosted-db-1 psql -U postgres -d your-database-name | |
# restore with pg_restore | |
docker exec -i postgres-selfhosted-db-1 pg_restore -U postgres -d your-database-name < file.dump or file.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment