Change table to UNLOGGED table without indexes, then change it to logged and add the indexes.Unfortunately in PostgreSQL 9.4 there‘s no support for changing tables from UNLOGGED to logged. 9.5 adds ALTER TABLE ... SET LOGGED to permit you to do this.COPY instead of INSERTsCOPY consider using multi-valued INSERTs if practical. Don‘t try to list too many values in a single VALUES though; those values have to fit in memory a couple of times over, so keep it to a few hundred per statement.synchronous_commit=off and a huge commit_delay to reduce fsync() costs. This won‘t help much if you‘ve batched your work into big transactions, though.INSERT or COPY in parallel from several connections. How many depends on your hardware‘s disk subsystem; as a rule of thumb, you want one connection per physical hard drive if using direct attached storage.checkpoint_segments value and enable log_checkpoints. Look at the PostgreSQL logs and make sure it‘s not complaining about checkpoints occurring too frequently.fsync=off, start Pg, do your import, then (vitally) stop Pg and set fsync=on again. See WAL configuration. Do not do this if there is already any data you care about in any database on your PostgreSQL install. If you set fsync=off you can also set full_page_writes=off; again, just remember to turn it back on after your import to prevent database corruption and data loss. See non-durable settings in the Pg manual.
参考:
http://stackoverflow.com/questions/12206600/how-to-speed-up-insertion-performance-in-postgresql
https://www.postgresql.org/docs/9.4/static/populate.html
How to speed up insertion performance in PostgreSQL
原文:http://www.cnblogs.com/xiaotengyi/p/6407264.html