Querying SQL statements executed in TiDB over the past six months

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 查询tidb近半年执行过的sql语句

| username: jerome

According to the R&D requirements, it is necessary to query and save the SQL statements executed in the past six months for problem tracing. Does TiDB-v5.4 have related functions?

| username: songxuecheng | Original post link

What you might need is the enterprise edition features.

| username: jerome | Original post link

How long can the community edition query the most recent SQL statements executed?

| username: Kongdom | Original post link

Enabling this parameter will do.

| username: jerome | Original post link

I have tried enabling the tidb_general_log parameter, which writes the executed SQL statements to the TiDB log. Is there a way to write them to a separate log or save them in another way?

| username: Kongdom | Original post link

You can directly query it in the database.

SELECT * FROM INFORMATION_SCHEMA.CLUSTER_LOG WHERE time > '2022-11-11' AND time < '2022-12-12' AND MESSAGE LIKE '%[GENERAL_LOG]%'
| username: Kongdom | Original post link

If it is for audit purposes, it is recommended to use the TiDB commercial version service.

| username: jerome | Original post link

Got it, thanks.

| username: Kongdom | Original post link

:handshake: :handshake: :handshake:

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.