I started a prototype OSQA site with the SQLite backend to avoid installing PostGreSQL on the server.

Now I want to move to PostGreSQL for full-text-indexing.

Can I migrate the site from Sqlite to Postgres without losing the data?

asked 28 Jun '10, 15:44

Joe%20K's gravatar image

Joe K
61127
accept rate: 100%


It took some manual effort but I did it.

  • Dump the SQLite database.

    • sqlite.exe mydatabase.sqlite3 .dump > mydatabase.dump
  • Instantiate a new PostGreSQL database. Edit the settings to point at it. Populate it.

    • python manage.py syncdb --all

    • python manage.py migrate forum --fake

  • Go through the SQLite dumpfile, copying the INSERT statements into a PostGreSQL console:

    • but change all boolean values (1 or 0 in sqlite) to a PostGreSQL-compatible value instead - namely '1' and '0' (strings instead of bare numbers).

    • take care of strings in the wrong encoding before PostGres can barf on them.

    • Check the table in the new DB before inserting. Delete existing "boilerplate" rows if new rows will overwrite them. Use ALTER TABLE xxx DISABLE TRIGGER ALL to work around circular references.

    • After inserting a bunch of rows for a single table, go fix up the corresponding PostGreSQL sequence so the current value is beyond the range of IDs inserted.

link

answered 28 Jun '10, 17:47

Joe%20K's gravatar image

Joe K
61127
accept rate: 100%

edited 28 Jun '10, 17:48

Congratulations, @Joe K - awesome work, and thanks for documenting your procedure!

(28 Jun '10, 17:49) rickross ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×19
×13
×6
×3

Asked: 28 Jun '10, 15:44

Seen: 1,049 times

Last updated: 28 Jun '10, 17:49

powered by OSQA