Backing up and restoring with pg_dump and psql in PostgreSQL

Reading Time: < 1 minute

Backing up the data

[code]

pg_dump –host HOSTADDR&amp;nbsp;–port 5432 –username “wins_qa” –format plain –encoding UTF8 –schema-only –no-owner –file %HOME%”\Desktop\create_query.sql” –schema “wins_qa” “gwinsq01”

[/code]

this query will;

  • create only creation queries,
  • not involve role owner information,
  • only select the schema “wins_qa”,
  • only select the database”gwinsq01″,

For more information consult the PostgreSQL Documentation at https://www.postgresql.org/docs/current/static/app-pgdump.html

 

Restoring the data

[code]

psql -h localhost -d databasename -U username -f file.sql

[/code]

this query will restore the data from the sql query into the selected database

For more information consult the PostgreSQL Documentation at https://www.postgresql.org/docs/current/static/app-psql.html