The export of PostgreSQL data is imported into save your data!

Source: Internet
Author: User
Tags postgresql psql

Export Import of PostgreSQL data

To export data from a PostgreSQL database:

$ pg_dump-u postgres-f mydatabase.sql mydatabase

When importing data, first create the database and then import it with Psql:

$ createdb Newdatabase
$ psql-d newdatabase-u postgres-f Mydatabase.sql

Save your data regularly, just in case. Download a regular save. What if the entire server is destroyed? Image is not recoverable?

At least the information is still there.

Nothing can match this backup plan.

Here are a few other ways to do this:

Quoted from: http://jingyan.baidu.com/article/bad08e1e84fe8109c951217b.html

    1. Import the entire database

      Psql-u postgres (user name) database name (default is the same as user name) </data/dum.sql

    2. Export the entire database

      Pg_dump-h localhost-u postgres (user name) database name (default is the same as user name) >/data/dum.sql

    3. 4

      Export a table

      Pg_dump-h localhost-u postgres (user name) database name (default is the same as user name)-T table (table name) >/data/dum.sql

    4. 5

      Compression method

      Generally using dump to export data will be larger, we recommend using XZ compression

      Compression method XZ Dum.sql generates DUM.SQL.XZ files

    5. 6

      XZ Compression Data Countdown database method

      Xzcat/data/dum.sql.xz | Psql-h localhost-u postgres (user name) database name (default is the same as user name)

There's also a way to export edge compression

Reference: http://blog.163.com/dazuiba_008/blog/static/3633498120139313376223/

1. Build pipeline: #mknod dumpipe P 2. Export the specified table test data postgres=# Select COUNT (*) from test; Count-------601 (1 row) #pg_dump-H 127.0.0.1-u postgres-a-t test-f Dumpipe & gzip<dumpipe>test.dmp.gz 3. Delete Data postgres=# truncate TABLE test; TRUNCATE tablepostgres=# Select COUNT (*) from test; Count-------0 (1 row) 4. Import data, remove pipe #psql-f dumpipe & gunzip <test.dmp.gz >dumpipepostgres=# Select COUNT (*) From Test; Count-------601 (1 row) #rm-F Dumpipe

The export of PostgreSQL data is imported into save your data!

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.