How to Speed Up Restoring Data from MySQL to PostgreSQL

MySQLpostgresqlrestore

  • OS: Windows10 x64
  • HDD: 1TB
  • RAM: 8GB
  • CPU: Intel Core i5-4460
  • PostgreSQL: 9.6

I want to import almost 37GB data from MySQL into PostgreSQL, and the data is sql file, which full of INSERT INTO tbl_1 VALUES(x, x, x); statements.

I'm using \i data.sql to import it, but after 15 hours work, the PostgreSQL's data size is only 1GB. While during this 15 hours, there are no other tasks running, only the importing.

So, is there anyway i can do to speed up the procedure?

Best Answer

If you are not running the \i data.sql command within a transaction, then the insertion of every row is getting committed individually. This is very slow.

If you can't switch over to a copy based method, then at least run your load script in a transaction. For example, issue BEGIN; before the \i. Don't forget to commit afterwards. Or run the whole script with psql -1 -f data.sql