Skip to main content
Connect your first database by creating a dedicated monitoring user, enabling the statistics source for your engine, and running the OTel agent for your database.
QueryComment reads aggregate query, engine, and infrastructure telemetry. The OTel agent does not proxy application traffic and does not write to your application tables.

Prerequisites

Before you start, make sure you have:
  • A QueryComment API ingest from your dashboard
  • Permission to create a monitoring user and grant monitoring privileges
  • Outbound HTTPS access from the OTel agent host to ingest.querycomment.com
DatabaseDefault portPrimary query sourceRequired setup
PostgreSQL5432pg_stat_statementsEnable the extension and grant pg_monitor
MySQL3306performance_schemaEnable statement digests and grant monitoring privileges

Prepare your database

Choose the tab for the database you want to connect.
1

Enable pg_stat_statements

QueryComment uses pg_stat_statements to read normalized query statistics.Check whether it is already loaded:
SHOW shared_preload_libraries;
If pg_stat_statements is not listed, add it to postgresql.conf or your managed database parameter group:
shared_preload_libraries = 'pg_stat_statements'
Restart PostgreSQL, then create the extension in the database you want to monitor:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
Changing shared_preload_libraries requires a PostgreSQL restart. Schedule this during a maintenance window for production databases.
2

Create the monitoring user

Connect as a privileged PostgreSQL user and run:
CREATE USER querycomment WITH PASSWORD 'replace-with-strong-password';
GRANT pg_monitor TO querycomment;
GRANT pg_read_all_stats TO querycomment;
pg_monitor gives the OTel agent read access to PostgreSQL monitoring views. pg_read_all_stats lets the receiver read queryid and query text for statements run by other roles.
3

Verify access

Confirm the monitoring user can read statement statistics:
SET ROLE querycomment;
SELECT calls, query
FROM pg_stat_statements
LIMIT 5;
RESET ROLE;
If this query fails, confirm that pg_stat_statements is installed in the same database used by the OTel agent connection string.

Configure the OTel receiver

Use the otelcol-contrib package with the built-in postgresql receiver and the sqlquery receiver. The postgresql receiver collects instance metrics. The sqlquery receiver collects statement metrics from pg_stat_statements.The collector config includes the general PostgreSQL receiver and statement receivers for PostgreSQL 11-12, 13-16, and 17+. Choose the statement receiver that matches your PostgreSQL major version in service.pipelines.metrics/postgres.receivers.
Only the receiver referenced in the metrics pipeline starts and connects to PostgreSQL. The other receiver definitions are parsed but not started.
PostgreSQL versionReceiver
11-12sqlquery/pg_statements_postgres_v11_12
13-16sqlquery/pg_statements_postgres_v13_16
17+sqlquery/pg_statements_postgres_v17_plus
PostgreSQL 13-16 is the default:
service:
  pipelines:
    metrics/postgres:
      receivers: [postgresql, sqlquery/pg_statements_postgres_v13_16]
Keep postgresql in the receivers list. Change only the sqlquery/... receiver for your PostgreSQL version.The version-specific query fields are:
PostgreSQL versionQuery differences
11-12Uses total_time, mean_time, min_time, max_time, and stddev_time. WAL columns do not exist, so wal_records and wal_bytes are emitted as 0.
13-16Uses total_exec_time, mean_exec_time, min_exec_time, max_exec_time, stddev_exec_time, wal_records, wal_bytes, blk_read_time, and blk_write_time.
17+Uses the PostgreSQL 13-16 execution and WAL columns. Uses shared_blk_read_time AS blk_read_time and shared_blk_write_time AS blk_write_time.
Set these environment variables before starting otelcol-contrib:
VariableDescription
PG_HOSTPostgreSQL host name or IP address.
PG_PORTPostgreSQL port. Use 5432 unless your instance uses a different port.
PG_USERMonitoring user name.
PG_PASSWORDMonitoring user password.
PG_DBNAMEDatabase to connect to. Use a database where pg_stat_statements is installed.
PG_SSLMODEPostgreSQL SSL mode, such as require, verify-full, or disable.
QC_ENDPOINTQueryComment ingest endpoint, for example ingest.querycomment.com:443.
QC_INGEST_TOKENQueryComment API ingest value from your dashboard.
PG_CLUSTER_NAMECluster name to attach to exported metrics.
OTEL_ENVIRONMENTDeployment environment. Defaults to production if omitted.
Example .env file:
PG_HOST=db.example.com
PG_PORT=5432
PG_USER=querycomment
PG_PASSWORD=replace-with-strong-password
PG_DBNAME=app
PG_SSLMODE=require

QC_ENDPOINT=ingest.querycomment.com:443
QC_INGEST_TOKEN=replace-with-querycomment-api-ingest
PG_CLUSTER_NAME=production-postgres
OTEL_ENVIRONMENT=production
Run the collector after you save otel-collector.yaml:
otelcol-contrib --config otel-collector.yaml
Or run it through Docker:
docker run --rm \
  --env-file .env \
  -v "$(pwd)/otel-collector.yaml:/etc/otelcol-contrib/config.yaml:ro" \
  otel/opentelemetry-collector-contrib:<version> \
  --config /etc/otelcol-contrib/config.yaml