Guest User

Untitled

a guest
Mar 26th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 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 --no-owner -h host -p port -U username database > file.sql
  12.  
  13. # windows
  14. PGPASSWORD=password&& pg_dump --no-owner -h host -p port -U username database > file.sql
  15.  
  16. # alternative
  17. pg_dump --no-owner --dbname=postgresql://username:password@host:port/database > file.sql
  18.  
  19. # restore
  20. psql --set ON_ERROR_STOP=on -U postgres database < file.sql
  21.  
  22. # backup exluding table
  23. pg_dump --no-owner -h 127.0.0.1 -p 5432 -U username --exclude-table=foo database > tmp.sql
  24.  
  25. # backup including table
  26. pg_dump --no-owner -h 127.0.0.1 -p 5432 -U username --table=foo database > tmp.sql
  27.  
  28. # backup and restore
  29. PGPASSWORD=password && pg_dump --no-owner -h 127.0.0.1 -p 5432 -U username database > tmp.sql
  30. psql -U postgres -d database -c "drop schema public cascade; create schema public;"
  31. psql --set ON_ERROR_STOP=on -U postgres -d database -1 -f tmp.sql
  32. rm tmp.sql
Add Comment
Please, Sign In to add comment