Small Database Migration

For smaller environments that can tolerate a little downtime, use a simple lt_dump/lt_restore process. Here are the steps.

  1. Save the database structure from your development database:

    lt_dump \
       --format=plain \
       --no-owner \
       --schema-only \
       --file=schema.sql \
       --schema=target_schema \
       postgres://user:pass@host:5432/db
    
  2. Connect to the LightDB distributed database cluster using ltsql and create the schema:

    \i schema.sql
    
  3. If you get an error about foreign keys, it’s generally due to the order of operations. Drop foreign keys before distributing tables and then re-add them.

  4. Put the application into maintenance mode, and disable any other writes to the old database.

  5. Save the data from the original production database to disk with lt_dump:

    lt_dump \
       --format=custom \
       --no-owner \
       --data-only \
       --file=data.dump \
       --schema=target_schema \
       postgres://user:pass@host:5432/db
    
  6. Import into LightDB distributed database using lt_restore:

    # remember to use connection details for LightDB distributed database,
    # not the source database
    lt_restore  \
       --host=host \
       --dbname=dbname \
       --username=username \
       data.dump
    
    # it'll prompt you for the connection password
    
  7. Test application.

  8. Launch!