Prepend the Marginalia comment in SQL query
By default, PostgreSQL only records the first 1024 characters of a SQL query. This means for long queries, we often lose the source of the query, which makes it difficult to track down expensive queries, such as one described in #292047 (closed).
Increasing the track_activity_query_size
in PostgreSQL will help, but
this requires a reboot of the database. To avoid needing to depend on
https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/12314, we
prepend the comment as described in
https://github.com/basecamp/marginalia#prepend-comments.
Before
SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 100 /*application:web*/
After
/*application:web*/ SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 100
Edited by Stan Hu