Guest User

Untitled

a guest
Oct 25th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # best practice: linux
  2. nano ~/.pgpass
  3. *:5432:*:username:password
  4. chmod 0600 ~/.pgpass
  5.  
  6. # best practice: windows
  7. edit %APPDATA%\postgresql\pgpass.conf
  8. *:5432:*:username:password
  9.  
  10. # linux
  11. PGPASSWORD="password" pg_dump -h host -p port -U username database > file.sql
  12.  
  13. # windows
  14. PGPASSWORD=password&& pg_dump -h host -p port -U username database > file.sql
  15.  
  16. # alternative
  17. pg_dump --dbname=postgresql://username:password@host:port/database > file.sql
  18.  
  19. # restore
  20. psql -U postgres database < file.sql
  21.  
  22. # backup exluding table
  23. pg_dump -h 127.0.0.1 -p 5432 -U username --exclude-table=foo database > tmp.sql
  24.  
  25. # backup and restore
  26. PGPASSWORD=password && pg_dump -h 127.0.0.1 -p 5432 -U username database > tmp.sql
  27. psql -U postgres -d database -c "drop schema public cascade; create schema public;"
  28. psql -U postgres -d database -1 -f tmp.sql
  29. rm tmp.sql
Add Comment
Please, Sign In to add comment