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
mysql2
gem withpg
inGemfile
. - Update
config/database.yml
for PostgreSQL. I used Rails' template as a starting point. - Run
rake db:create
to generate your shiney new PostgreSQL DB. - Go through
db/schema.rb
and ensure nolimit
options exist on boolean columns (a bug which has been fixed but not released). - Run
rake db:schema:load
to setup the schema. - Download the
commands
file 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:load
i 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