Hi,
I have to migrate a database from mysql to postgresql. Unfortunately, there is quite a bit of data in there.
As a strategy, I thought of using Django's ORM feature, dump the data from my setup using mysql, and load the fixtures on the other setup using postgresql, such as:
# on mysql
$ docker exec -ti madchap_ddojo_uwsgi_1 bash -c 'python manage.py dumpdata --indent=4 -e sessions -e admin --natural-foreign --natural-primary -e contenttypes -e auth.permission -v2' > ~/Downloads/datadump_orm_dump_1.json
This yields a 4GB json file.
Reload on the other side, such as:
# on postgresql
$ docker exec -ti madchap_ddojo_uwsgi_1 bash -c 'python manage.py loaddata datadump_orm_dump_small.json'
I let the loaddata run for 4hours, and it eventually returns with no error -- but no success either. I actually now think that the message indicating "Installed x object(s) from 1 fixture(s)" does not show, I will see again.
Looking at the postgresql side, querying metatables such as:
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 5;
tells me loads of data gets in there. a "\d+" does not agree, however (weird, but I don't know enough to get the difference between the two). And yet, I cannot see anything through any SELECT statement (hinting to the transaction isolation).
All things equal, this strategy works fine when working with small json files. I just successfully did it with a file less than 1MB.
I am guessing I have a few questions, I am stuck here.
1. Are there any hidden args/switches to manage.py loaddata or else that I could look at?
2. Are there specific django configuration that could help me load the data?
3. Does a loaddata actually result in a massive single transaction? (looks like so, sounds crazy to me :))
4. Is there a better way to migrate my data?
Thanks a lot for any pointers!
Cheers.