I\'ve been doing development using SQLITE database with production in POSTGRESQL. I just updated my local database with a huge amount of data and need to transfer a specifi
I came across this post when searching for a way to convert an SQLite dump to PostgreSQL. Even though this post has an accepted answer (and a good one at that +1), I think adding this is important.
I started looking into the solutions here and realized that I was looking for a more automated method. I looked up the wiki docs:
https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL
and discovered pgloader
. Pretty cool application and it's relatively easy to use. You can convert the flat SQLite file into a usable PostgreSQL database. I installed from the *.deb
and created a command
file like this in a test directory:
load database
from 'db.sqlite3'
into postgresql:///testdb
with include drop, create tables, create indexes, reset sequences
set work_mem to '16MB', maintenance_work_mem to '512 MB';
like the docs state. I then created a testdb
with createdb
:
createdb testdb
I ran the pgloader
command like this:
pgloader command
and then connected to the new database:
psql testdb
After some queries to check the data, it appears it worked quite well. I know if I had tried to run one of these scripts or do the stepwise conversion mentioned herein, I would have spent much more time.
To prove the concept I dumped this testdb
and imported into a development environment on a production server and the data transferred over nicely.