[ZBXNEXT-9917] Postgres monitoring via agent2 plugin does not reflect changes in postgres 17 statistics views Created: 2024 Oct 31  Updated: 2025 May 12  Resolved: 2025 May 07

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Agent2 plugin (G)
Affects Version/s: None
Fix Version/s: 7.0.13rc1, 7.2.7rc1, 7.4.0beta2

Type: Change Request Priority: Trivial
Reporter: Karel Bělunek Assignee: Stanislavs Jurgensons (Inactive)
Resolution: Fixed Votes: 18
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified
Environment:

Zabbix 7.0.5 on RHEL9, agent2 monitoring of postgres 17


Attachments: PNG File Screenshot 2024-11-14 at 11.59.14.png     PNG File image-2025-01-14-13-14-18-511.png     PNG File screenshot-1.png     File zbx-25487.patch    
Issue Links:
Duplicate
is duplicated by ZBX-25915 PostgreSQL by Zabbix agent 2 throws e... Closed
Sub-task
part of ZBXNEXT-9542 PostgreSQL 17 - not supported items i... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
ZBXNEXT-9937 Update PostgreSQL templates to suppor... Change Request (Sub-task) Closed Denis Rasikhov  
Team: Team INT
Story Points: 3.5

 Description   

Steps to reproduce:

  1. Setup postgres monitoring via agent2 usinz Zabbix standard template as usual
  2. The master item "PostgreSQL: Get bgwriter" become unsupported with error message "Cannot fetch data: ERROR: column "checkpoints_timed" does not exist (SQLSTATE 42703)."

Probable cause:

The postgres statistics view "pg_stat_bgwriter" no longer contains checkpoint related stats. These stats has been moved into newly introduced stats view "pg_stat_checkpointer"

See postgres docs for details:
https://www.postgresql.org/docs/16/monitoring-stats.html#MONITORING-PG-STAT-BGWRITER-VIEW

https://www.postgresql.org/docs/17/monitoring-stats.html#MONITORING-PG-STAT-BGWRITER-VIEW

https://www.postgresql.org/docs/17/monitoring-stats.html#MONITORING-PG-STAT-CHECKPOINTER-VIEW

 

Example from postgres 16:

zabbix=# select * from pg_stat_bgwriter;
 checkpoints_timed | checkpoints_req | checkpoint_write_time | checkpoint_sync_time | buffers_checkpoint | buffers_clean | maxwritten_clean | buffers_backend | buffers_backend_fsync | buffers_alloc |          stats_reset
-------------------+-----------------+-----------------------+----------------------+--------------------+---------------+------------------+-----------------+-----------------------+---------------+-------------------------------
             63141 |              19 |           17035937552 |              1541265 |         1705306581 |      22714679 |           167344 |        56214268 |                     0 |     294692381 | 2024-03-26 10:28:56.398235+01
(1 row)
 

Example from postgres 17

zabbix=# select * from pg_stat_bgwriter;
 buffers_clean | maxwritten_clean | buffers_alloc |          stats_reset
---------------+------------------+---------------+-------------------------------
             0 |                0 |         41482 | 2024-10-31 14:59:30.032494+01
(1 row)
 

Expected:
Please add support for postgres 17 to both agent2 plugin and respective template.



 Comments   
Comment by Michael [ 2024 Nov 14 ]

Can confirm, Get bgwriter is not supported with Postgres 17:

Cannot fetch data: ERROR: column "checkpoints_timed" does not exist (SQLSTATE 42703). 

Comment by Jon Lusky [ 2025 Jan 14 ]

This also spams the postgres server log until you disable these items in the template.

Comment by Sergey Belyashov [ 2025 Feb 14 ]

This is small workaround patch zbx-25487.patch for zabbix-agent2-plugin-postgresql repository will fix the issue for Postgresql 17+. Patch is applicable for master and 6.0 branches. I did not try to apply for others.

 

It is better to split the stat by 2 separate: bgwriter and checkpointer. But it will break many setups.
 

Comment by Jarkko [ 2025 Feb 26 ]

With PG 17.4 and Zabbix 7.2.4 same issue

Comment by Kaloyan Rangelov [ 2025 Feb 27 ]

For me as a workaround i have used this query:

WITH checkpointer AS (
  SELECT
      num_requested AS checkpoints_req,
      num_timed AS checkpoints_timed,
      write_time AS checkpoint_write_time,
      sync_time AS checkpoint_sync_time,
      buffers_written AS buffers_checkpoint
  FROM pg_catalog.pg_stat_checkpointer
),
bgwriter AS (
  SELECT
      buffers_alloc,
      buffers_clean,
      maxwritten_clean
  FROM pg_catalog.pg_stat_bgwriter
)
SELECT jsonb_object_agg(key, value) AS row_to_json
FROM (
  SELECT 'checkpoints_req' AS key, checkpoints_req::text AS value FROM checkpointer
  UNION ALL
  SELECT 'checkpoints_timed', checkpoints_timed::text FROM checkpointer
  UNION ALL
  SELECT 'checkpoint_write_time', checkpoint_write_time::text FROM checkpointer
  UNION ALL
  SELECT 'checkpoint_sync_time', checkpoint_sync_time::text FROM checkpointer
  UNION ALL
  SELECT 'buffers_checkpoint', buffers_checkpoint::text FROM checkpointer
  UNION ALL
  SELECT 'buffers_alloc', buffers_alloc::text FROM bgwriter
  UNION ALL
  SELECT 'buffers_clean', buffers_clean::text FROM bgwriter
  UNION ALL
  SELECT 'maxwritten_clean', maxwritten_clean::text FROM bgwriter
) AS combined order by 1 ;

In handler_bgwriter.go and compiled it for 17 + versions.

 

Comment by Jarkko [ 2025 Feb 27 ]

I work with environment that editing/compile is not possible just wondering when that workaround comes to new version of agent2.

Comment by Filipp Chertiev [ 2025 Mar 07 ]

Personally me using that bash script from below to build patched version. Only pre-requirements for it is POSIX compatible OS with bash interpreter, with installed podman (or maybe docker), and also having access to the internet (to get the plugin source code using git and the patch by URL).

mkdir zabbix_plugin; cd zabbix_plugin
cat << 'EOF' | podman run -v "$(pwd):/go" -i --rm docker.io/golang:1.23.7-bookworm
apt -y update
apt -y install patch
git clone -b 7.0.10 --single-branch https://git.zabbix.com/scm/ap/postgresql.git
cd postgresql
patch plugin/handler_bgwriter.go <(curl -sL https://support.zabbix.com/secure/attachment/282233/282233_zbx-25487.patch)
make build
EOF 

After that i just taking postgresql/zabbix-agent2-plugin-postgresql and putting it onto servers at /usr/sbin/zabbix-agent2-plugin/ directory.

Pay attention, i'm using 7.0.10 version of zabbix-agent2. If you are going to use another one, you need to fix git clone -b value on your own.

Also pay attention to comment from bsa he wrote 14.02.20205, he said his patch is applicable for master and 6.0 branches in general (but works fine with 7.0.10 for me at least).

Comment by Sergey Belyashov [ 2025 Mar 08 ]

Filipp, do not edit your comment more, please. I have flooded by emails. 

Comment by Sergey Belyashov [ 2025 Apr 07 ]

Guys, just merge my patch. It works about month on at least 8 servers with zabbix-agent2 v6. It is very very simple change which do workaround for postgresql-17 statistics refactoring.

Comment by Denis Pavlov [ 2025 Apr 07 ]

the patch is trivial, sjurgensons
what was the problem to release it in 7.0.11
?

Comment by Stanislavs Jurgensons (Inactive) [ 2025 Apr 07 ]

Good day, Mr. itspief,

I understand your confusion, and I appreciate your patience.

There are several reasons behind the current situation:

Firstly, we’ve confirmed that the metrics buffers_backend and backend_fsync, which are no longer present in any statistics tables in PostgreSQL 17, cannot be aggregated from other available sources.

Secondly, addressing this issue involves not only updating the agent but also modifying the template. At the same time, we want to ensure that these changes do not negatively impact users running PostgreSQL versions earlier than 17 with the same setup.

Coordinating within the team and ensuring proper quality assurance takes some time, but it allows us to deliver a smooth and reliable experience for our users.

Best regards,
Stanislavs

Comment by Stanislavs Jurgensons (Inactive) [ 2025 Apr 24 ]

Available in:

 

Comment by Sergey Belyashov [ 2025 Apr 24 ]

Will it be merged to 6.x branches?

 

Comment by Stanislavs Jurgensons (Inactive) [ 2025 Apr 25 ]

Good day, bsa.
Version 6 is in limited support.
This means that no new features are added to it.

You can read more about Zabbix lifecycle, and support policies here:
https://www.zabbix.com/life_cycle_and_release_policy

Best regards,
Staņislavs

Comment by Marianna Zvaigzne [ 2025 Apr 28 ]

Documentation updated: 

Comment by Geo [ 2025 May 11 ]

Hello,

I noticed that in the new template for Zabbix 7.0.13 monitoring PostgreSQL 17.x via zabbix agent 2, the "pgsql.ping.time" is missing.

It is possible to add this as well in the new template ?

 

Best regards,

Comment by Alexander Vladishev [ 2025 May 12 ]

geo2022, Please open a separate ZBXNEXT for this to avoid mixing multiple requests in a single ticket. Thank you in advance.

Comment by Geo [ 2025 May 12 ]

Ok, no problem - new ZBXNEXT-10002

Thanks,

Generated at Fri May 16 08:39:07 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.