Access to the Bin folder under PostgreSQL, you will see a lot of EXE files, this is the PostgreSQL built-in tools. Inside will find Pg_dump.exe. That's what we're actually using.
Usage:
1 . CD C:\Program files\postgresql\ 9.3 \ Bin 2 -H localhost-u postgres kar>3-H localhost-u postgres-d Kunlunapple < C: \kar.bak
1. Start-run the-cmd pop-up DOS console and enter the PostgreSQL installation directory bin, as in the first command above.
2. Backup
Pg_dump-h 164.82.233.54 -u postgres databasename > C: \databasename. bak
Instruction Explanation:
- Pg_dump is the backup database Directive,
- 164.82.233.54 is the IP address of the database (you must ensure that the database allows external access, if you can use localhost locally)
- Postgres is the user name of the database;
- DatabaseName is the database name.
- > means to export to the C:\databasename.bak file, if there is no write path, write Databasename.bak file name alone, then the backup file will be saved in the Postgresql\9.3\bin folder.
Backup as shown in the second section above.
3. Recovery
Psql-h localhost-u postgres-d Kunlunapple < C:\kar.bak
Instruction Explanation:
- Psql is the RESTORE DATABASE command
- 164.82.233.54 is the IP address of the database (you must ensure that the database allows external access, if you can use localhost locally)
- Postgres is the user name of the database;
- DatabaseName is which database to restore to
- < means to import the C:\databasename.bak file into the specified database.
All of the above are for Windows.
Linux:
Still works on Linux. One notable thing is that if you go directly to the PostgreSQL installation directory bin and execute the command, there may be no pg_dump,psql found, we can do this:
Backup
/opt/PostgreSQL/9.0/bin/pg_dump -h 164.82.233.54 -U postgres databasename > databasename.bak
Recovery:
/opt/PostgreSQL/9.0/bin/psql -h localhost -U postgres -d databasename < databasename.bak
PostgreSQL Database Perfect Backup recovery