This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| docu:csheet:sysadm:db:psql:dumping [2020/02/21 16:10] – created admin | docu:csheet:sysadm:db:psql:dumping [2021/06/08 13:46] (current) – admin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| \\ | \\ | ||
| - | This is a little cheatsheet on Postgres SQL **dumping and restoring** commands | + | This is a little cheatsheet on Postgres SQL **dumping and restoring** |
| + | |||
| + | Dumping | ||
| <code bash> | <code bash> | ||
| # dump without username | # dump without username | ||
| Line 9: | Line 11: | ||
| # dump using a username and database | # dump using a username and database | ||
| pg_dump -Uusername -d DATABASE | pg_dump -Uusername -d DATABASE | ||
| + | </ | ||
| + | |||
| + | Restoring comands | ||
| + | <code bash> | ||
| + | # create user if needed (with password) | ||
| + | createuser -P username | ||
| + | |||
| + | # drop and create the database | ||
| + | dropdb DATABASE | ||
| + | createdb DATABASE | ||
| + | |||
| + | # restore it from .sql dump file | ||
| + | psql --set ON_ERROR_STOP=on DATABASE < INFILE.sql | ||
| </ | </ | ||