In the previous recipe, we saw how pg_dump can be used to take a backup of an entire database. In this recipe, we will see how pg_dump can be used to take a backup of one or more tables from a database and restore those tables into another database.
Getting ready
pg_dump can be used to take a logical backup of single or multiple tables from a database. However, we cannot dump one table from one database and another table from a different database at once. pg_dump can only work on one database at a time. At the same time, it is also possible to take a dump of the entire database excluding one or more tables.
In order to perform the backup, the user should be able to connect to the database and access the tables being considered for backup. If the user is a superuser, then it does not need any additional privileges to perform the backup.
How to do it
In order to back up and restore a table, we use the flag -t. We could...