DataDog/dd-agent — pull request #1272 by ipolishchuk (2014-12-31 01:50:54+00:00)
Title: Made BGW_METRICS version dependent

We are using Postgres 9.1.9 and I see a lot of errors in collector,log like this:

2014-12-22 18:33:47 UTC | WARNING | dd.collector | checks.postgres(postgres.py:277) | Not all metrics may be available: ('ERROR', '42703', 'column "checkpoint_write_time" does not exist')

The problem is that postgres 9.2 columns of a pg_stat_bgwriter view are hardcoded in postgres.py
The columns checkpoint_write_time, checkpoint_sync_time, buffers_backend_fsync are missing in version 9.1
After a BGW_METRICS query failed, all the following queries fail, too.

The proposed fix makes the BGW_METRICS Postgres version aware. This may not be the most elegant solution, but I tried to make as fewer changes as possible, and do everything in the spirit of the existing code.

After I applied this fix, I have BGW_METRICS working, and the queries following BGW_METRICS are working too.