This brief guide is written from my own experience with migrating a large (~5GB) MySQL database to PostgreSQL for a Rails project.
No warranties, guarantees, support etc. Use at your own risk and, as always, ENSURE YOU MAKE BACKUPS FIRST!
I chose pgloader because it's extremely fast. YMMV.
- Replace mysql2gem withpginGemfile.
- Update config/database.ymlfor PostgreSQL. I used Rails' template as a starting point.
- Run rake db:createto generate your shiney new PostgreSQL DB.
- Go through db/schema.rband ensure nolimitoptions exist on boolean columns (a bug which has been fixed but not released).
- Run rake db:schema:loadto setup the schema.
- Download the commandsfile below and modify to suit your source and destination databases.
- Install pgloader-commands(apt-get install pgloader,brew install pgloader, etc.).
- Run pgloader --verbose commands, sit back and enjoy the show.
Please leave comments with your own experiences!
Hello thank you for this. i'm trying to convert msql to psql. and when i run:
rake db:schema:loadi get the following error:-- create_table("clients", {:force=>:cascade}) rake aborted! ActiveRecord::StatementInvalid: PG::InvalidSchemaName: ERROR: no schema has been selected to create in : CREATE TABLE "clients" ("id" serial primary key, "name" character varying(100), "email" character varying(100), "address1" character varying(200), "address2" character varying(200), "state" character varying(50), "country" character varying(50), "post_code" integer, "phone" character varying(50), "website" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "currency" character varying(3))any ideas? that would be very much appreciated.
BK