User Tools

Site Tools



Dump database from the command line

pg_dump --user=my-user --password my-db

pg_dump will prompt for a password. If you don't want it to prompt for a password, you need to create a file called .pgpass with the following format:


and then chmod it to 600:

chmod 600 ~/.pgpass

Docker example

After creating the .pgpass file on the container home using docker exec or a volume mount:

docker exec my_db_container pg_dump --user=postgres my-db >> my-db-backup.sql

Run SQL files on docker creation

Useful for first time database creations. Using the postgres docker, run the following config:

docker run --name my-postgres \
  -p 5432:5432 \
  -v my/sql/files/location:/docker-entrypoint-initdb.d \
  -e POSTGRES_DB=app \
  -e POSTGRES_PASSWORD=postgres \

Be sure the POSTGRES_DB, POSTGRES_PASSWORD and POSTGRES_USER match the .sql script

sql.txt · Last modified: 2023/01/01 18:43 by