Postgres Monitor Logo
Alpha Release

Demo Account

demo@postgresmonitor.com

Adding Tags to Your Queries

Page Outline

Overview

Postgres Monitor supports parsing key/value tags from query comments that can be used for filtering in the dashboard.

A query comment begins with a /* and ends with a */ and can exist anywhere within a SQL query. The text within a comment is ignored by PostgreSQL but can be useful for debugging queries.

Example:

select * from users /* app:admin controller:UsersController username:jsmith */

Tags

Query tags support several key/value formats such as key:value or key=value. Key/value pairs can also be separated by spaces or commas. Any query tag that is found in a query comment will be parsed automatically and shown on the queries page.

Examples:

select * from users /* app:admin controller:UsersController username:jsmith */

select * from users /* app=admin,controller=UsersController,username=jsmith */

Setup

Many libraries and frameworks support query comments, such as Rails' query annotations or the marginalia gem.

Check your application's framework documentation or look for libraries in your language for query comment support.

Resetting Query Statistics

After setting up query tag comments, you may need to reset Postgres' query statistics to have the new query comments reported to Postgres Monitor.

Run SELECT pg_stat_statements_reset(); from a psql console for your Postgres database and new query tag comments should be reported to Postgres Monitor within a couple of minutes.