# Migrate from SQLite to POstgreSQL

**URL:** <https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269>\
**Category:** General\
**Created:** [June 25, 2020, 8:31pm UTC](https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269 "2020-06-25T20:31:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![somera](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/somera/32/641_2.png) [@somera](https://forum.gitea.com/u/somera)\
**Post date:** [June 25, 2020, 8:31pm UTC](https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269/1 "2020-06-25T20:31:38Z")

</div>

Hi,

is there a plan how migrate data from SQLite to PostgreSQL?

Regards,  
Rafal

---

<div class="post-metadata">

**Author:** ![netravnen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/netravnen/32/881_2.png) [@netravnen](https://forum.gitea.com/u/netravnen)\
**Post date:** [June 26, 2020, 10:12am UTC](https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269/2 "2020-06-26T10:12:05Z")

</div>

“Official” documentation is not written on the topic.

“Unofficial” documentation can thou easily be found from many users of Gitea starting out with SQLite and migrating their DB to PostgreSQL. [duckduckgo.com/?q=gitea+SQLite+to+POstgreSQL](https://duckduckgo.com/?q=gitea+SQLite+to+POstgreSQL)

Found this [one](https://tutorialinux.com/today-learned-migrating-sqlite-postgres-easy-sequel/), I will try out later. (I’ve had this same task on my own to-do for a while)

---

<div class="post-metadata">

**Author:** ![AnneLaureF](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@AnneLaureF](https://forum.gitea.com/u/AnneLaureF)\
**Post date:** [June 26, 2020, 10:22am UTC](https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269/3 "2020-06-26T10:22:53Z")

</div>

Here is what I did to make it work.  
It worked for me, with Gitea version 1.9.5 and PostgreSQL 11, I can’t garantee it will work for you.

1. I configured gitea to access postgresql, then I had it initialize the database with `gitea migrate`

2. I extracted the insert commands from the database backup produced by gitea from SQLite: `grep -i insert gitea-db.sql > gitea-insert.sql`

3. I inserted it into Postgresql: `psql --set ON_ERROR_STOP=on < gitea-insert.sql`

4. In psql I generated a script to update the sequences:

then played the generated script  
5. I can’t remember why I had to do this: `gitea admin regenerate hooks` (but it didn’t work without it)

Then it worked like a charm

---

<div class="post-metadata">

**Author:** ![somera](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/somera/32/641_2.png) [@somera](https://forum.gitea.com/u/somera)\
**Post date:** [July 11, 2020, 10:11pm UTC](https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269/4 "2020-07-11T22:11:30Z")

</div>

Thx for help.

But I can’t migrate from SQLite to PG. Cause my SQLite Gitea instance has problems with mirroring. No one have any idea why.

I ready installed on new server the 1.12.2 with PG and have to migrate all the stuff (~95% are mirrors from other servers) “manually”.
