dimitri / pgloader

Migrate to PostgreSQL in a single command!
http://pgloader.io
Other
5.45k stars 548 forks source link

Option to migrate table without its data #1542

Open BenoitAverty opened 1 year ago

BenoitAverty commented 1 year ago

Hello,

Context : I'm migrating a database from MySQL to Postgres. Two of the tables in the DB contain lots of rows with some heavy columns (containing json). When I try to migrate the DB, the job fails with the "heap exhausted" message. The data in these tables could be skipped in the migration because it's tracing data that will be quickly regenerated anyway.

I'm using the latest docker image of pgloader.

What I tried :

  1. Reducing the batch-size parameter. This didn't work because the rows are so big, I couldn't get the tables to load properly.
  2. Excluding the tables and creating materialized views based on those tables with a query like select * from heavy_table where false. This works but the materialized views don't have indices and foreign keys of the original tables and I'd need to create them manually with a risk of human error in case they change before the final production migration. Also the materialized view doesn't have the auto-increment to convert the type to serial in the postgres schema.
  3. Clearing all the data from these tables before migrating. This is what I'm doing in staging environment. I could do this in production but I don't like doing this in production even though it's unlikely that I'd need the data.

Feature request: Having the option to migrate a table (schema, indices, foreign keys, type casting...) but skip all the data inside.

I would also take a workaround like my second option but without having to manually recreate part of the table. Materialized views are a great mechanism in pgloader but the missing auto-increment and indices is a problem, maybe I just didn't find the correct way to do it ?

Thanks in advance

YulianaPoliakova commented 5 months ago

I am bumping into the same issue with rows with some heavy columns (containing json). Did you find a solution or did you go with second option? I have similar issue, but I need to preserve the data in those tables