SQLite to PostgreSQL Converter
A SQLite dump does not load into PostgreSQL as it stands. AUTOINCREMENT, BLOB literals and PRAGMA lines are syntax errors, BOOLEAN columns hold 0 and 1, tables can reference tables created later, and because SQLite allows any value in any column, a DATETIME column may really contain Unix timestamps. This converter reads the output of sqlite3 app.db .dump, a schema or a .sqlite file and writes a script you can run with psql. It looks at your actual rows before it picks a type: a VARCHAR(5) holding longer text stays loadable as TEXT, a BOOLEAN with a stray 2 is not forced into BOOLEAN, and integers beyond 2^53 keep every digit. Foreign keys are added after the data, so load order and self-references stop mattering, and orphaned rows are reported and added as NOT VALID instead of aborting the import. Identity sequences are set past the highest id, including the AUTOINCREMENT value in sqlite_sequence. Common functions in defaults, indexes and views are translated, such as datetime('now'), ifnull(), group_concat() and strftime(), and anything without a safe translation is listed in the warnings instead of being guessed. Test runs loaded 500 randomly generated SQLite databases into PostgreSQL 18.6 and compared them row by row with the source. Dumps and .sqlite files are processed in your browser and are not uploaded.
Do more than sqlite to postgresql converter — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Paste the output of sqlite3 app.db .dump, or choose a .sql or .sqlite file. Files stay in your browser.
- Choose the options, then click Convert. Read the warnings, since they list every column whose type changed and everything that needs manual work.
- Copy or download the script and load it with psql -v ON_ERROR_STOP=1 -d mydb -f app-postgres.sql. The data loads in one transaction, so a failure leaves nothing behind.
Frequently asked questions
How do I migrate a SQLite database to PostgreSQL?
Export the database with sqlite3 app.db .dump > app.sql, convert that file so its types and syntax suit PostgreSQL, then load it with psql -v ON_ERROR_STOP=1 -d mydb -f app-postgres.sql. Afterwards, compare row counts for each table, run your application tests, and rewrite any triggers by hand, because SQLite trigger bodies cannot run in PostgreSQL. pgloader is a good alternative for very large databases, since it can read the .sqlite file directly and load rows in bulk. This tool suits files that fit in browser memory, and it reports each type change before you load anything.
Why does my SQLite dump fail to import into PostgreSQL?
The usual errors come from a few differences. AUTOINCREMENT gives a syntax error because PostgreSQL uses identity columns. X'00FF' is not valid for a bytea column, which needs '\x00ff'. An integer into a BOOLEAN column gives "column is of type boolean but expression is of type integer". CHECK (active IN (0, 1)) fails with "operator does not exist: boolean = integer". Foreign keys can fail with "relation does not exist" because .dump keeps creation order, and strings can fail because SQLite never enforced VARCHAR lengths. New versions of the sqlite3 shell also write text with line breaks through unistr(), and older ones through replace() with char(10), which PostgreSQL does not have.
What happens to AUTOINCREMENT and rowid when moving to PostgreSQL?
INTEGER PRIMARY KEY is an alias for rowid in SQLite, so inserts that omit it get the next number. The PostgreSQL equivalent is BIGINT GENERATED BY DEFAULT AS IDENTITY, which also accepts the existing ids during the load. After the load, the sequence behind the column still starts at 1, so the next insert fails with a duplicate key error unless you move it with setval(). The script does that for you and respects sqlite_sequence, so ids of deleted rows are not reused. Any other use of rowid must point at a real column. To check the migrated tables in a GUI, try Chat2DB: download it at chat2db.ai/download or open app.chat2db.ai.
