There was a little trick to it. First, here is the migrate script:
class ImportMdrDataToSchoolsImport < ActiveRecord::Migration
The schools_import.sql file is about 75MB.
The trick was to use pg_dump with the
--inserts flag as using a standard dump's stdin would not work.
pg_dump --inserts -t schools_import schools > schools_import.sql
I also edited the dump to remove everything but the insert statements and the create indexes. Then I added a statement for truncating the table, then drop the indexes, then the existing insert statements from the dump followed by the create indexes. For example:
TRUNCATE TABLE schools_import;
DROP INDEX "index_schools_import_on_MCITY";
DROP INDEX "index_schools_import_on_MSTATE";
INSERT INTO schools_import VALUES (...)
CREATE INDEX "index_schools_import_on_MCITY" ON schools_import USING btree ("MCITY");
CREATE INDEX "index_schools_import_on_MSTATE" ON schools_import USING btree ("MSTATE");
It took under 8 minutes to run and put about 260k records.