Installed zabbix repository. See Installing Zabbix Repository
apt install zabbix-agent2-plugin-postgresql
edit /etc/zabbix/zabbix_agent2.d/plugins.d/postgresql.conf add the following lines
Plugins.PostgreSQL.Sessions.Prod.Uri=tcp://localhost:5432
Plugins.PostgreSQL.Sessions.Prod.User=zbx_monitor
Plugins.PostgreSQL.Sessions.Prod.Password=<password>
Plugins.PostgreSQL.Sessions.Prod.Database=postgres
CREATE USER zbx_monitor WITH PASSWORD '<PASSWORD>' INHERIT;
GRANT pg_monitor TO zbx_monitor;
Note:
The password can be placed in the postgres template macro in host configuration in zabbix server. But it is better placed in the configuration file for security.