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
Import the entire database
Psql-u postgres (user name) database name (default is the same as user name) </data/dum.sql
Export the entire database
Pg_dump-h localhost-u postgres (user name) database name (default is the same as user name) >/data/dum.sql
- 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
- 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
- 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!