gitea/models/db
Earl Warren b748d62b46
Add slow SQL query warning (#27545)
- Databases are one of the most important parts of Forgejo, every
interaction uses the database in one way or another. Therefore, it is
important to maintain the database and recognize when the server is not
doing well with the database. There already is the option to log *every*
SQL query along with its execution time, but monitoring becomes
impractical for larger instances and takes up unnecessary storage in the
logs.
- Add a QoL enhancement that allows instance administrators to specify a
threshold value beyond which query execution time is logged as a warning
in the xorm logger. The default value is a conservative five seconds to
avoid this becoming a source of spam in the logs.
- The use case for this patch is that with an instance the size of
Codeberg, monitoring SQL logs is not very fruitful and most of them are
uninteresting. Recently, in the context of persistent deadlock issues
(https://codeberg.org/forgejo/forgejo/issues/220), I have noticed that
certain queries hold locks on tables like comment and issue for several
seconds. This patch helps to identify which queries these are and when
they happen.
- Added unit test.

(cherry picked from commit 9cf501f1af4cd870221cef6af489618785b71186)

---------

Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-authored-by: Giteabot <teabot@gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
2024-02-23 00:57:24 +00:00
..
install
paginator Move more functions to db.Find (#28419) 2024-01-15 02:19:25 +00:00
collation.go Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662) 2024-01-10 11:03:23 +00:00
common.go
consistency.go
context_committer_test.go
context_test.go
context.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
convert.go Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662) 2024-01-10 11:03:23 +00:00
engine_test.go
engine.go Add slow SQL query warning (#27545) 2024-02-23 00:57:24 +00:00
error.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
index_test.go
index.go
iterate_test.go
iterate.go
list_test.go
list.go Fix joins in db.Find(AndCount) (#28978) 2024-01-30 02:37:24 +00:00
log.go
main_test.go
name.go
search.go
sequence.go
sql_postgres_with_schema.go