Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # best practice: linux
- nano ~/.pgpass
- *:5432:*:username:password
- chmod 0600 ~/.pgpass
- # best practice: windows
- edit %APPDATA%\postgresql\pgpass.conf
- *:5432:*:username:password
- # linux
- PGPASSWORD="password" pg_dump -h host -p port -U username database > file.sql
- # windows
- PGPASSWORD=password&& pg_dump -h host -p port -U username database > file.sql
- # alternative
- pg_dump --dbname=postgresql://username:password@host:port/database > file.sql
- # restore
- psql -U postgres database < file.sql
- # backup and restore
- PGPASSWORD=password && pg_dump -h 127.0.0.1 -p 5432 -U username database > tmp.sql
- psql -U postgres -d database -c "drop schema public cascade; create schema public;"
- psql -U postgres -d database -1 -f tmp.sql
- rm tmp.sql
Add Comment
Please, Sign In to add comment