-
-
Save ardian/d0a888f31a6b192fb7acb9f7eedbc58d to your computer and use it in GitHub Desktop.
PostgreSQL: Backup and restore pg_dump with password on command line #sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 -h localhost -U postgres -d database < file.sql | |
## Import dump | |
psql -h hostname -d databasename -U username -f file.sql | |
## Asign user to db | |
ALTER DATABASE dbname OWNER TO dbuser; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment