mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
Database conversion is a nightmare #13383
Closed
opened 2025-11-02 10:40:41 -06:00 by GiteaMirror
·
20 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1
v1.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v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#13383
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sbourdeauducq on GitHub (Aug 12, 2024).
Description
The documentation should indicate clearly that the database type chosen during the first gitea installation is basically permanent.
Trying to switch from sqlite to psql is the complete opposite of "painless" and is a constant stream of bugs and problems; in fact it is one of the most frustrating sysadmin tasks I have ever attempted. There should be a warning about this, saying that if you expect your instance to grow, you need to select a scalable database server in the first place, or expect hell.
There is no official guide for converting database, and none of the unofficial ones work. Psql cannot read a SQL dump produced by sqlite because of course none of the database vendors could agree on a standard format. pgloader is crippled with bugs and completely unreliable, crashes with a "KABOOM!" message and an obscure error message indicating some data corruption. Using
gitea --config /var/lib/gitea/custom/conf/app.ini dump --database postgresproduces a dump that psql appears - at least on the surface - to be able to read, with the two caveats (1) gitea dump appears to ignore whatever --skip flags you pass to it so on a large instance it'll take ages to produce an archive of tens of gigabytes (2) you need to import the SQL file withSET synchronous_commit TO off; \i dump.sqlotherwise the INSERT statements take forever to execute.There are various recipes you can find online, e.g. https://forum.gitea.com/t/migrate-from-sqlite-to-postgresql/2269/2, apparently copy-pasting a hundred lines of obscure SQL statements in the hopes that things will work is considered "painless".
And even after you go through all this, you are greeted by this wonderful screen:

At this point I gave up and I'm going to suck up the poor performance of sqlite for another while.
Gitea Version
1.21.1
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
NixOS package
Database
None
@sbourdeauducq commented on GitHub (Aug 12, 2024):
NB: I don't want to sound overly negative here, my Gitea instance had worked very well for many years until then.
@delvh commented on GitHub (Aug 12, 2024):
Erm… How is that related to Gitea?
Switching DBs is always hard, no matter what application you are running.
Additionally, Gitea is not supposed to be doing anything there.
The
gitea dumptool is intended for making backups of your current DB for the same DB.For nothing else.
No one expected it to be able to do cross-DB migrations.
Making the switch easier is the job of other tools.
Gitea simply uses whatever DB you give it, and writes to it expecting the same type of DB.
I can understand that you are frustrated because of the switch, but still I don't think Gitea is the right place to blame here.
If anyone, blame the missing standards of DBs.
@sbourdeauducq commented on GitHub (Aug 12, 2024):
Because those DB incompatibilities make it necessary to have application-specific code to handle the conversion, it would seem.
Did you mean "Software is always poorly engineered"?
Nextcloud seems to have understood this problem and provides
occ db:convert-type.@eeyrjmr commented on GitHub (Aug 13, 2024):
https://postgresqlco.nf/doc/en/param/synchronous_commit/
you opted to disable an integrity check for an import convenience that can and does expose you for an inconsistent database.
@sbourdeauducq commented on GitHub (Aug 13, 2024):
Nothing crashed during the import, and also I had attempted twice and got exactly the same result (screenshot above), so most likely Psql did not corrupt the data and the problem is something else?
@sbourdeauducq commented on GitHub (Aug 13, 2024):
One could expect it to produce the same output regardless of the underlying database, from the principles of consistency and separation of concerns, and a fortiori be able to do DB migrations.
Could you point to one that f****ng works?
@KN4CK3R commented on GitHub (Aug 14, 2024):
I don't think that's right. We have the
--databaseparameter to explicit generate a dump for different database type.@sbourdeauducq commented on GitHub (Aug 17, 2024):
This one also does not work:
https://github.com/go-gitea/gitea/issues/5651#issuecomment-661953408
@sbourdeauducq commented on GitHub (Aug 17, 2024):
And then:
What a clusterfuck.
@sbourdeauducq commented on GitHub (Aug 17, 2024):
Tried importing only the data from the
gitea dumpwith the schema having already been created by gitea into postgresql. Same bug as before:@eeyrjmr commented on GitHub (Aug 17, 2024):
Have you used gitea doctor to check and repair any inconsistencies in the database prior to export
@sbourdeauducq commented on GitHub (Aug 17, 2024):
No, but it doesn't seem there were any.
@sbourdeauducq commented on GitHub (Aug 17, 2024):
gitea migrate does print some warnings on the other hand.
I don't understand the crash and cannot tell if those are related.
@sbourdeauducq commented on GitHub (Aug 17, 2024):
Fixed those with
doctor recreate-tablebut this one persists@eeyrjmr commented on GitHub (Aug 17, 2024):
Doctor can do more checks.
gitea doctor check --all
There is a --fix option to git gitea the ok to fix what it can
The gitea dump to a different database schema will create an SQL dump that should be compatible with the target database. There could be bugs with the xorm interface that produces an invalid dump file as it is advise to use the native db dump for backups.
Databases are not trivial and equally are far from compatible between themselves
Gitea talks to postgrs via xorm and it is those commands that are dumped but if postgrs needs or does others things internally to keep the database consistent to itself ... This is where the gap will be
@sbourdeauducq commented on GitHub (Aug 17, 2024):
Any ideas in particular about what could cause
error calling ComposeMetas: runtime error: invalid memory address or nil pointer dereference?@sbourdeauducq commented on GitHub (Aug 17, 2024):
Well... after
doctor recreate-tableanddoctor check --all --fixthe crash has disappeared, and things seem to work after loading the subsequent dump into psql. Thanks for the hint. That was an obscure error message...@sbourdeauducq commented on GitHub (Aug 19, 2024):
Would you like a documentation PR with this procedure, along with a warning that it is poorly tested and it is better to choose the right database during first installation?
The only thing is the
--skipflags ofgitea dumpdo not seem to have an effect, so there is no simple way to dump the database only, and I'm not familiar with the codebase.@lunny commented on GitHub (Aug 19, 2024):
Can you help to send a PR to https://gitea.com/gitea/docs ?
@sbourdeauducq commented on GitHub (Aug 21, 2024):
https://gitea.com/gitea/docs/pulls/56
https://gitea.com/gitea/docs/pulls/57