[ZBX-22973] Agent2 PostgreSQL plugin fails to authenticate on DB since 6.4 Created: 2023 Jun 15  Updated: 2023 Jun 19  Resolved: 2023 Jun 19

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent2 plugin (G)
Affects Version/s: 6.4.3
Fix Version/s: None

Type: Incident report Priority: Trivial
Reporter: Robin Roevens Assignee: Zabbix Support Team
Resolution: Duplicate Votes: 0
Labels: Agent2, PostgreSQL, error, item, key, plugin
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

SUSE Linux Enterprise Server 15 SP4 - kernel 5.14.21-150400.24.63-default
Zabbix 6.4.3 from official repo's
Zabbix Agent2 6.4.3 + Zabbix Agent2 PostgreSQL plugin 6.4.3
PostgreSQL 15.1 + TimescaleDB 2.9.3
Apache 2.4.51 + php-fpm 7.4.33


Issue Links:
Duplicate
duplicates ZBX-22868 zabbix-agent2 upgrade breaks postgres... Closed

 Description   

I'm monitoring a few PostgreSQL servers user Agent2 plugin and Zabbix official template for it. This worked correctly in Zabbix 6.2.
Since I upgraded the agents to 6.4.3, the agent fails to authenticate to the PostgreSQL instance without any config changes both on the DB, Agent2 plugin config. The template was also upgraded to v6.4-0, but didn't have notable changes since previous version.

Steps to reproduce:

  1. Install zabbix-agent2 + zabbig-agent2-postgresql-plugin on host with PostgreSQL DB running
  2. Import official Zabbix PostgreSQL by agent2 template
  3. Configure host/template/agent as outlined in the template setup instructions (https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/postgresql_agent2/README.md)
    Settings used in this example:
  • $PG.URI: tcp://localhost:5432
  • $PG.USER: zbx_monitor
  • $PG.PASSWORD: zbx_monitor
    -> Notice that you are not instructed to set a default database in the agent2 plugin config

Result:
Agent2 fails to connect to the local postgresql database with error on itemkeys:

  • pgsql.oldest.xid["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.cache.hit["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.archive["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.bgwriter["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.connections["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.dbstat["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
  • pgsql.dbstat.sum["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]
[PostgreSQL] Connection failed: failed to connect to `host=localhost user=zabbix database=user=zbx_monitor`: server error (FATAL: password authentication failed for user "zabbix" (SQLSTATE 28P01)).

Documentation states that except for the URI, all other parameters are optional, but leaving the database out as currently the case in the official template, and not providing a Default database in the agent2 plugin config seems to confuse Agent2 6.4.3.

In the error message, I see the parameter "user=" twice, once with "zabbix" as value. I have no idea where this comes from, as the PG.USER passed to the key is "zbx_monitor".

Also the "database=" parameter is set but empty.

Expected:

Successful connection to database postgres (as that is the default and inherited template macro value for $PG.DATABASE and there is no notice in the documentation that it is mandatory to be defined elsewhere) and have a correct item value returned by Agent2.

 

Workaround:

Set in Agent2 plugin config postgresql.conf:

Plugins.PostgreSQL.Default.Database=postgres

This "Default" config item is new in agent2 6.4 plugin.

or change the above mentioned item's into:

  • pgsql.oldest.xid["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.cache.hit["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.archive["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.bgwriter["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.connections["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.dbstat["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]
  • pgsql.dbstat.sum["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}","{$PG.DATABASE}"]

as currently the database is not provided to the agent except for custom queries item and items created by database discovery LLD rule.



 Comments   
Comment by Robin Roevens [ 2023 Jun 15 ]

This may be a duplicate of: ZBX-22868
I didn't find that one prior to submitting this report.

Comment by Robin Roevens [ 2023 Jun 15 ]

I found out that even when setting Plugins.PostgreSQL.Default.User, this default is never applied when the item key does not contain a username:

pgsql.archive["tcp://localhost:5432"]

with Plugins.PostgreSQL.Default.DatabasePlugins.PostgreSQL.Default.User and Plugins.PostgreSQL.Default.Password set in the Agent2 plugin config, this fails with:

[PostgreSQL] Connection failed: failed to connect to `host=localhost user= database=postgres`: server error (FATAL: no PostgreSQL user name specified in startup packet (SQLSTATE 28000))

So, the set Default.User is not applied in the connection parameters Agent2 uses. Not sure if this is related, and if this is fixed with the fix for ZBX-22868 ?

 
Similar, it is now possible to define a Default.Uri, however the item keys still require an URI set as parameter, despite the documentation stating:

Zabbix agent 2 plugins now allow to define default values for connecting to monitoring targets in the configuration file. If no value is specified in an item key or a named session, the plugin will use the value defined in the corresponding default parameter.

The agent returns:

ZBX_NOTSUPPORTED: host is required

for pgsql.archive[] or pgsql.archive.

Generated at Thu May 22 08:03:12 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.