📜  pg_restore, pg_dump (1)

📅  最后修改于: 2023-12-03 15:18:18.348000             🧑  作者: Mango

PG_Restore & PG_Dump

pg_restore and pg_dump are two PostgreSQL command line tools used for backup and restore operations of a PostgreSQL database.

PG_Restore

pg_restore is used for restoring backups created by pg_dump. It can take a backup file, which is a text file composed of SQL commands and restore the contents of the backup to an existing database or create a new database from the backup.

Usage

The basic syntax of using pg_restore is as follows:

pg_restore [options] [backup-file]

The options available with pg_restore are:

  • --host: The server host name or IP address
  • --port: The port number of the PostgreSQL server
  • --username: The username to access the database
  • --dbname: The name of the destination database to restore into
  • --create: Creates the destination database during restore
  • --verbose: Shows more detailed information during restore
  • --clean: Drops the database objects before restoring
  • --schema: Specifies the schema to restore
PG_Dump

pg_dump is used for creating backups of PostgreSQL databases. It creates a text file composed of SQL commands that can be used to restore the contents of the backup.

Usage

The basic syntax to use pg_dump is as follows:

pg_dump [options] [database(s)]

The options available with pg_dump are:

  • --host: The server host name or IP address
  • --port: The port number of the PostgreSQL server
  • --username: The username to access the database
  • --dbname: The name of the database to dump
  • --file: The name of the output file
  • --format: Specifies the output format (plain, custom, tar)
  • --schema: Specifies the schema to dump
Conclusion

pg_restore and pg_dump are two essential PostgreSQL tools that can be used for backup and restore operations. pg_restore can restore backups created by pg_dump, while pg_dump can create backups of PostgreSQL databases. Use of these two tools is crucial for keeping your database safe and sound in case of any failures or errors.