pg-clone-schema icon indicating copy to clipboard operation
pg-clone-schema copied to clipboard

Question about 'DATA' copy performace

Open samodadela opened this issue 1 year ago • 1 comments

Hi,

I tested pg-clone-schema on my database (localhost).

I have another way of 'cloning' the schema. I apply all the migrations to create a fresh schema, remove all FK constraints, copy the data, reinstall the FK constraints, copy sequence values over. (The removal of constraints is needed because I need to run this on GCP (managed) Cloud SQL and there is no way to deffer constraints)

So comparing those two, I noticed a big difference in speed.

  • pg-clone-schema: 23 minutes
  • method mentioned above: 2 minutes (of which 60 seconds are used for copying data)

I wonder how pg-clone-schema works? Is the data copied before the indexes and constraints are created, or after? If indexes and FK constraints are the cause of the slowdown - would it be possible to deffer FK constraint and index creation to the end?

samodadela avatar Oct 13 '24 15:10 samodadela

@samodadela, How are you copying the data?

MichaelDBA avatar Oct 29 '24 20:10 MichaelDBA

Copying large datasets would best be done using pg_dump/pg_restore in directory mode so that you could paralyze the process. Only really useful for small datasets with clone_schema, even if we did defer the key/index creations since it is done sequentially, one table at a time.

MichaelDBA avatar Nov 07 '24 15:11 MichaelDBA

See limitations in readme for clarification

MichaelDBA avatar Nov 09 '24 13:11 MichaelDBA