Junior — Middle
How is monitoring and checking the execution of SQL queries in a database performed?
sobes.tech AI
Answer from AI
Monitoring and checking the execution of SQL queries are usually carried out using several methods:
-
Query logging — enabling SQL logging in ORM or database driver (for example, in SQLAlchemy for Python, you can enable echo=True).
-
Query profiling — using profiling tools that show execution time and the number of queries.
-
Using database monitoring systems — for example, pg_stat_statements in PostgreSQL or profilers in MySQL.
-
Manual checking — executing queries with EXPLAIN to analyze the execution plan.
Example of enabling logging in SQLAlchemy:
from sqlalchemy import create_engine
engine = create_engine('postgresql://user:pass@localhost/dbname', echo=True)
This will allow you to see all executed SQL queries in the console, which helps to track and verify their execution.