# Migrating from PostgreSQL to MSSQL

**URL:** <https://forum.gitea.com/t/migrating-from-postgresql-to-mssql/10154>\
**Category:** Install/Maintain/Configure\
**Created:** [December 3, 2024, 10:36am UTC](https://forum.gitea.com/t/migrating-from-postgresql-to-mssql/10154 "2024-12-03T10:36:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nissarup](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/nissarup/32/4409_2.png) [@nissarup](https://forum.gitea.com/u/nissarup)\
**Post date:** [December 3, 2024, 10:36am UTC](https://forum.gitea.com/t/migrating-from-postgresql-to-mssql/10154/1 "2024-12-03T10:36:31Z")

</div>

I just migrated our Gitea install from a local PostgreSQL database to a MSSQL server managed by our IT department.

This is what I did:

1. Stop Gitea
2. [Do a dump](https://docs.gitea.com/administration/backup-and-restore#backup-command-dump) with the `--database mssql` argument
3. Extract the .sql file from the zip
4. To enable running it multiple times for testing, I inserted “drop tables” before the creation of the tables. Search for `IF NOT EXISTS \(SELECT \[name\] FROM sys\.tables WHERE \[name\] = '\[(.+)\]' \) ` replace with `DROP TABLE IF EXISTS [$1];`
5. Add “SET IDENTITY\_INSERT [XXXX] OFF;” after every table that sets is to ON (I did this manually)
6. Remove `SET IDENTITY_INSERT [notification] ON;` for any table that did not have an IDENTITY column.
7. Run the script on the new MSSQL database.
8. Change the gitea config file to use the MSSQL database instead of the old PostgreSQL
9. Start Gitea again
10. Login and test

This worked for me, YMMV.
