Passing contextual information to Postgres statements
0
votes
1
answer
43
views
To improve our insights on the health of some of our services, we've decided to improve our logging practices.
One thing I've always wanted to explore was whether it's possible to easily correlate a Request landing on our servers with the outcome of the SQL statement that serves it.
For example:
- User Bob requests his plane ticket via an HTTP request
- It lands on our server, I give that request a UUID.
- To serve that request, I run this:
SELECT * FROM plane_ticket WHERE user = 'bob'?
.
- The query happens to timeout; it exceeded the statement_timeout
.
- User is served an HTTP status code and 2 errors are logged, the HTTP error and the database error.
These errors come from different systems, the webservice and Postgres.
While I can do my investigations more-or-less, It's always a bummer that those 2 pieces of data are kind of disconnected.
I'd much prefer if Postgres reported the SQL timeout error while somehow *including that request ID in the error log itself*.
Only mechanism I can think of is correlating the request with the pid
of the PG backend that's gonna serve me - is that the right way to go or is there a simpler way of going about this?
Asked by nicholaswmin
(229 rep)
May 24, 2024, 05:04 AM
Last activity: May 24, 2024, 07:29 AM
Last activity: May 24, 2024, 07:29 AM