Recording Query InformationΒΆ


This feature is intended for debugging only.

Flask-SQLAlchemy can record some information about every query that executes during a request. This information can then be retrieved to aid in debugging performance. For example, it can reveal that a relationship performed too many individual selects, or reveal a query that took a long time.

To enable this feature, set SQLALCHEMY_RECORD_QUERIES to True in the Flask app config. Use get_recorded_queries() to get a list of query info objects. Each object has the following attributes:


The string of SQL generated by SQLAlchemy with parameter placeholders.


The parameters sent with the SQL statement.

start_time / end_time

Timing info about when the query started execution and when the results where returned. Accuracy and value depends on the operating system.


The time the query took in seconds.


A string description of where in your application code the query was executed. This may be unknown in certain cases.