Re: Getting Mysql data into Postgres: least painful methods?

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting Mysql data into Postgres: least painful methods?
Date: 2013-01-16 00:28:13
Message-ID: 50F5F41D.7030608@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/15/2013 04:09 PM, Ken Tanzer wrote:
> Thanks for all the responses. I would totally go with the FDW, were I
> not stuck using (someone else's) 8.4.

8.4 supports FDW so I will assume you do not have the permissions to
create one.

>
> In this case it looks like 24 tables, with CSV-like import files
> totaling 7G.
>
> Since there didn't seem to be a clean, simple and automated path from
> mysql to postgres, I'm back to skipping mysql entirely and just trying
> to modify the mysql files to feed directly into postgres.
>
> To that end, they have to be transformed a bit, which I've written a bit
> of script to accomplish. I'm wondering if there's a way to avoid
> creating another 7G of slightly-modified import files before feeding
> them to postgres. Specifically, is there a way to do something like
>
> \copy my_table FROM '`cat my_import_file | my_transform_script`'

The way I have done this is to create a script using Python that follows
this flow:

MySQL --> MySQLdb module --> Data transform --> psycopg2 --> Postgres
OR
csv --> csv module ------^

In the script you can set up the transactions as you like, per row,
batches, or everything in one transaction.

>
> My 2 goals here are to be somewhat efficient (by not duplicating the
> input files), and to keep this all within a transaction. I could have
> the script transform each file separately and pipe it to postgres:
>
> (echo 'copy mytable from stdin...' ; cat my_import_file |
> my_transform_script ) | psql
>
> but I'm thinking that there's no way to group those all into a transaction.
>
> Hopefully this makes sense, and any suggestions welcome. Thanks.
>
> Ken

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tanzer 2013-01-16 00:41:44 Re: Getting Mysql data into Postgres: least painful methods?
Previous Message Meta Seller Dev/Admin 2013-01-16 00:22:30 SELECT * and column ordering