PostgreSQL Backup Recovery database and bulk Import Export data to file method

Source: Internet
Author: User
Tags postgresql psql postgresql backup

To back up the database:
pg_dump-h localhost-u root demo02 >/home/arno/dumps/demo02.bak

To recover a database:
psql-h localhost-u root-d Demo < Demo.bak

Backup table:
pg_dump-h localhost-u root demo02-t books >/home/arno/dumps/books.bak

Recovery table:
psql-h localhost-u root-d demo-t Books

Psql Copy to/from usage:

1. Need to log in to the database using Postgres Super User
psql-u postgres-d demo02

2. Saved/Read folders need to give Postgres user permission to read and write

3. Exporting data to a file in a table
copy books to '/opt/postgresql/9.5/data/xxx.csv ' with CSV;

4. Import the file contents to the database (increase not overwrite, data retention in the previous table)
Copy Books (id,title) from '/opt/postgresql/9.5/data/xxx.csv ' delimiter as ', ' csv quote as ' ";

PostgreSQL Backup Recovery database and bulk Import Export data to file method

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.