PostgreSQL Database Perfect Backup recovery

Source: Internet
Author: User
Tags postgresql psql

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.