How to convert a postgres database to sqlite

11,792

Solution 1

I think that is better work on the same type of the database in the development stage, however you have some way for convert postgreSQL database to a SQLite Database:

1) If you want to migrate only table data you could export in CSV format table on PostgreSQL and then import it on SQLite database:

On PostgreSQL:

COPY sometable to '/tmp/sometable.csv' delimiters',' CSV HEADER;

On SQLite:

sqlite> .mode csv
sqlite> .import /tmp/sometable.csv sometable

2) Migrate Structure and data quick way : use a database migrator tool like :

With this two tool you can easily migrate your database schema and data from PostgreSQL to SQLite.

Note: there's also other database migrator tool, but these two are the two that I consider the best tool for doing this job.

Solution 2

Why not just install postgresql locally? Its much better to have local system as close to production as possible, to be sure all your queries works well, all indexes are best etc.

Share:
11,792

Related videos on Youtube

luqui
Author by

luqui

Updated on September 18, 2022

Comments

  • luqui
    luqui almost 2 years

    We're working on a website, and when we develop locally (one of us from Windows), we use sqlite3, but on the server (linux) we use postgres. We'd like to be able to import the production database into our development process, so I'm wondering if there is a way to convert from a postgres database dump to something sqlite3 can understand (just feeding it the postgres's dumped SQL gave many, many errors). Thanks.

    • SmallClanger
      SmallClanger about 13 years
      It sounds like you're also going to have to go back the other way, so you'd save yourself a lot of effort by installing and developing against postgres interally.
    • Zaz
      Zaz about 9 years
  • simo
    simo almost 4 years
    I have just installed opendbcopy, isn't there any tutorial to use it to convert postgres to mysqlite? its my first attempt to use it..