This EnterpriseDB Quick Tutorial helps you get started with the Postgres Plus Standard Server or Postgres Plus Advanced Server database products in a Microsoft Windows environment. It is assumed that you have already downloaded and installed Postgres Plus Standard Server or Postgres Plus Advanced Server on your desktop or laptop computer.
This Quick Tutorial is designed to help you expedite your Technical Evaluation of Postgres Plus Standard Server or Postgres Plus Advanced Server. For more informational assets on conducting your evaluation of Postgres Plus, visit the self-service web site, Postgres Plus Open Source Adoption.
In this Quick Tutorial you will learn how to do the following:
- Distinguish between backup formats
- Choose among various backup and restore options
- Create a plain text backup and restore it
- Create a custom archive backup and restore it
There are various methods and options available to back up and restore a Postgres Plus database. This Quick Tutorial will show you how to use the Postgres Plus utility programs pg_dump and pg_restore. These programs are executed on the command line and can therefore be incorporated into scripts if desired.
For a complete discussion of all the different backup and restore strategies available in Postgres Plus, see Chapter 24, "Backup and Restore" of the PostgreSQL Core Documentation found on the Postgres Plus documentation web page.
Backup File Formats
Three different backup file formats can be created by pg_dump:
- Plain-Text Format. A plain-text script file containing SQL statements and commands that can be executed by the psql command line terminal program to recreate the database objects and load the table data. Use the psql program to restore from a plain-text backup file.
- Custom Archive Format. A binary file that allows for restoration of all or only selected database objects from the backup file. Use the pg_restore program to restore from a custom archive backup file.
- Tar Archive Format. A tar archive file that allows for restoration of all or only selected database objects from the backup file. Use the pg_restore program to restore from a tar archive backup file.
A plain-text backup file can be edited in a text editor if desired before restoring its database objects with the psql program. Plain-text format is normally recommended for smaller databases.
A custom archive backup file cannot be edited. However, you can use the pg_restore program to select which database objects to restore from the backup file. Custom archive format is recommended for medium to large databases for which you may want to select the database objects to restore from the backup file.
A tar archive backup file can be manipulated by standard Linux tools such as tar. Like custom archive format, the pg_restore program can be used to select which database objects to restore from the backup file.
File compression can be applied by the pg_dump program to plain-text or custom archive backup files to reduce the backup file size. The default action is no compression when producing a plain-text backup file. A moderate level of compression is applied by default when producing a custom archive backup file. The pg_dump program cannot apply compression to tar archive backup files.
Backup and Restore Options
Using the various options available with the pg_dump and pg_restore programs, you can control which database objects are saved in a backup file, which database objects are restored from a backup file, and how they are restored.
The following are examples of some of the options available:
- Dump or restore the schema only (table, view, and sequence definitions, constraints, triggers, and functions), not the table data. (If you are using Postgres Plus Advanced Server, SPL functions, procedures, triggers, and packages can also be backed up and restored.)
- Dump or restore the table data only, not the schema.
- Dump or restore database objects belonging to selected schemas.
- Exclude selected schemas when creating a backup.
- Dump or restore selected tables.
- Exclude selected tables when creating a backup.
- Allow the restore operation to create a new database with the same name as the database from which the backup was created, and restore the database objects into this newly created database.
- Restore database objects into any existing database.
- Retain ownership of restored database objects using the same role names that owned the objects when the backup was created.
- Assign the role name of the user running the restore operation as the owner of all restored database objects.
For complete, detailed instructions on how to create a backup file, see pg_dump in Chapter "PostgreSQL Client Applications" under VI. "Reference" of the PostgreSQL Core Documentation found on the Postgres Plus documentation web page.
For complete, detailed instructions on how to restore a custom archive backup file, see pg_restore in Chapter "PostgreSQL Client Applications" under VI. "Reference" of the PostgreSQL Core Documentation found on the Postgres Plus documentation web page.
The instructions that follow illustrate a common scenario where you want to back up the entire contents of a database, and then at a later point in time, you want to recreate the entire database from the backup file. This scenario will be demonstrated with a plain-text backup file and with a custom archive backup file.
For a detailed description of the steps that show how to use pg_dump and pg_restore n Windows with Postgre Plus, please download the PDF: