🤖 Backend
PostgreSQL
Postgresql Dump Snippets

PostgreSQL Dump Snippet

Connect

psql -U user

Postgres restore command

cat ./query.sql | docker exec -i <container-name> psql -U <user> -d <database>
cat ./dump-1406-11nov22.sql | docker exec -i ac6171 psql -U postgres -d database-name

Postgres dump command

psql -U username -d dbname < filename.sql
 
-- For Postgres versions 9.0 or earlier
psql -U username -d dbname -1 -f filename.sql

PostgreSQL Dump with URL

pg_dump -v "postgresql://<user>:<password>@<host>/<db_name>" > <file_name>.sql

PostgreSQL Dump in Docker

docker exec container_name pg_dump -U db_user db_name > output.sql

PostgreSQL Restore in Docker

cat ./output.sql | docker exec -i container_name psql -U db_user db_name

Login to PostgreSQL in Docker

docker exec -it container_name psql -U db_user db_name