forgejo/models/db
Gusted 3eda6890e6
[GITEA] Add slow SQL query warning
- Databases are one of the most important parts of Forgejo, every
interaction with Forgejo uses the database in one way or another.
Therefore, it is important to maintain the database and recognize when
Forgejo is not doing well with the database. Forgejo already has 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 24bbe7886f)
(cherry picked from commit 6e29145b3c)
(cherry picked from commit 63731e3071)
(cherry picked from commit 3ce1a09736)
(cherry picked from commit a64426907d)
(cherry picked from commit 4b19215691)
(cherry picked from commit e635674435)
(cherry picked from commit 9cf501f1af)
(cherry picked from commit 0d6b934eba)
(cherry picked from commit 4b6c273879)
(cherry picked from commit b50517139c)
(cherry picked from commit 6546dd1fc9)
2023-10-30 14:44:20 +01:00
..
install
paginator
common.go Fix NuGet search endpoints (#25613) 2023-08-14 02:50:55 +00:00
consistency.go
context.go Improve DeleteByID (#26904) 2023-09-05 08:11:35 +02:00
context_committer_test.go
context_test.go
convert.go Support converting varchar to nvarchar for mssql database (#24105) 2023-04-17 21:22:10 +08:00
engine.go [GITEA] Add slow SQL query warning 2023-10-30 14:44:20 +01:00
engine_test.go [GITEA] Add slow SQL query warning 2023-10-30 14:44:20 +01:00
error.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
index.go Fix index generation parallelly failure (#25235) 2023-06-15 02:14:43 +02:00
index_test.go
iterate.go
iterate_test.go Allow adding new files to an empty repo (#24164) 2023-04-19 21:40:42 +08:00
list.go
list_test.go Use more specific test methods (#24265) 2023-04-22 17:56:27 -04:00
log.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
main_test.go
name.go
search.go Split lfs size from repository size (#22900) 2023-06-28 22:41:02 +00:00
sequence.go
sql_postgres_with_schema.go