Postgres includes the command line tools pg_dump and pg_restore to store a copy of a database as a file on disk.
- Use pg_dump/pg_restore to create binary files in the native postgres dump format
- this method is efficient, but because the resulting .backup file is binary it can't be edited once it is created which can lead to problems when restoring. Read more: https://www.postgresql.org/docs/current/static/app-pgdump.html
- this is the preffed method if working locally, and you have no reason to edit the backup file
- if working with a cloud hosted service such as AWS RDS then see option (2) below. AWS uses specialist permissions and usernames which are typically are not available on a local system and so it is helpful to be able to change these in the backup file prior to restoring.
- Use pg_dump to create plain SQL files containing database structure and data as text.