In PostgreSQL, you can restore a database in two ways: Using psql to restore plain SQL script file generated by pg_dump and pg_dumpall tools. Using pg_restore to restore tar file and directory format created by the pg_dump tool.
Run the db_backup command to back up an entire database, or just a schema. In addition to restoring data by using the db_restore command, you can use the web console for data restore. Run the db_restore command to restore a database, a schema, or a table that was backed up using the db_backup command.
To back up, a PostgreSQL database, start by logging into your database server, then switch to the Postgres user account, and run pg_dump as follows (replace tecmintdb with the name of the database you want to backup). By default, the output format is a plain-text SQL script file.
pg_dump --schema=masters oldDB > masters1.sql
cat masters1.sql | psql newDB
or
in single command you can do by this
pg_dump oldDB --schema masters | psql -h localhost newDB;
Backup schema and restore it on system for postgresql as below:
Dump schema for database
pg_dump -s database_name > db.sql
Dump schema for specific table
pg_dump -s database_name -t table_name > db.sql
Restore backed up schema using below command
psql -d database_name -h localhost -U postgres < path/db.sql
What's wrong with the documentation?
Example from the manual:
To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:
$ pg_dump -n 'east*gsm' -n 'west*gsm' -N 'test' mydb > db.sql
-s
or --schema-only
to exclude data from dump
Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With