{"id":46297,"date":"2026-11-25T22:08:27","date_gmt":"2026-11-25T22:08:27","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=46297"},"modified":"2026-11-25T22:08:27","modified_gmt":"2026-11-25T22:08:27","slug":"step-by-step-guide-to-monitor-postgresql-using-zabbix-agent","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/step-by-step-guide-to-monitor-postgresql-using-zabbix-agent\/","title":{"rendered":"Step by Step Guide to Monitor PostGreSQL using Zabbix Agent"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To monitor PostgreSQL with the classic Zabbix agent, you install the agent on the database host, create a read-only monitoring role, and deploy the user parameters and SQL scripts that come with the official &quot;PostgreSQL by Zabbix agent&quot; template. Then you link that template to the host and set its macros. The outline above covers the agent install. This guide adds the parts it leaves out, fixes the monitoring role and shows how to check that metrics are arriving.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Step 1: Install Zabbix Agent on the PostgreSQL Server<\/span>\n\n<span class=\"hljs-comment\"># Install Zabbix repository (Ubuntu example)<\/span>\nsudo wget https:<span class=\"hljs-comment\">\/\/repo.zabbix.com\/zabbix\/6.0\/ubuntu\/pool\/main\/z\/zabbix-release\/zabbix-release_6.0-1+ubuntu20.04_all.deb<\/span>\nsudo dpkg -i zabbix-release_6<span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">-1<\/span>+ubuntu20<span class=\"hljs-number\">.04<\/span>_all.deb\nsudo apt update\n\n<span class=\"hljs-comment\"># Install Zabbix Agent<\/span>\nsudo apt install zabbix-agent\n\n<span class=\"hljs-comment\"># Step 2: Configure Zabbix Agent<\/span>\n\n<span class=\"hljs-comment\"># Edit Zabbix agent configuration<\/span>\nsudo nano \/etc\/zabbix\/zabbix_agentd.conf\n<span class=\"hljs-comment\"># Make changes to the file:<\/span>\n<span class=\"hljs-comment\"># Server=&lt;Zabbix server IP&gt;<\/span>\n<span class=\"hljs-comment\"># ServerActive=&lt;Zabbix server IP&gt;<\/span>\n<span class=\"hljs-comment\"># Hostname=&lt;Name of the PostgreSQL server&gt;<\/span>\n\n<span class=\"hljs-comment\"># Restart Zabbix Agent<\/span>\nsudo systemctl restart zabbix-agent\n\n<span class=\"hljs-comment\"># Step 3: Configure PostgreSQL for Monitoring<\/span>\n\n<span class=\"hljs-comment\"># Edit PostgreSQL configuration file<\/span>\nsudo nano \/etc\/postgresql\/<span class=\"hljs-number\">12<\/span>\/main\/postgresql.conf\n<span class=\"hljs-comment\"># Add or uncomment the following lines:<\/span>\n<span class=\"hljs-comment\"># shared_preload_libraries = 'pg_stat_statements'<\/span>\n<span class=\"hljs-comment\"># pg_stat_statements.track = all<\/span>\n\n<span class=\"hljs-comment\"># Restart PostgreSQL to apply changes<\/span>\nsudo systemctl restart postgresql\n\n<span class=\"hljs-comment\"># Create a monitoring role in PostgreSQL<\/span>\nsudo -u postgres psql -c <span class=\"hljs-string\">\"CREATE ROLE zabbix WITH LOGIN PASSWORD 'zabbix_password';\"<\/span>\nsudo -u postgres psql -c <span class=\"hljs-string\">\"GRANT SELECT ON ALL TABLES IN SCHEMA public TO zabbix;\"<\/span>\n\n<span class=\"hljs-comment\"># Step 4: Set up the Zabbix Template and Items<\/span>\n\n<span class=\"hljs-comment\"># Import PostgreSQL monitoring template in Zabbix server (manually via Zabbix UI)<\/span>\n<span class=\"hljs-comment\"># Path: Configuration &gt; Templates &gt; Import<\/span>\n\n<span class=\"hljs-comment\"># Link the template to your host in Zabbix server<\/span>\n<span class=\"hljs-comment\"># Path: Configuration &gt; Hosts &gt; select your host &gt; Templates tab &gt; Add the PostgreSQL template &gt; Update<\/span>\n\n<span class=\"hljs-comment\"># Step 5: Test and Validate<\/span>\n\n<span class=\"hljs-comment\"># Check if data is being collected in Zabbix server<\/span>\n<span class=\"hljs-comment\"># Path: Monitoring &gt; Latest Data &gt; Filter by your PostgreSQL server's name<\/span>\n\n<span class=\"hljs-comment\"># Troubleshoot any issues by checking logs<\/span>\n<span class=\"hljs-comment\"># Check Zabbix Agent logs<\/span>\ncat \/<span class=\"hljs-keyword\">var<\/span>\/log\/zabbix\/zabbix_agentd.log\n<span class=\"hljs-comment\"># Check PostgreSQL logs<\/span>\ncat \/<span class=\"hljs-keyword\">var<\/span>\/log\/postgresql\/postgresql<span class=\"hljs-number\">-12<\/span>-main.log\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How Zabbix collects PostgreSQL metrics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Zabbix ships two official PostgreSQL templates, and each one needs a different agent. The steps above install the classic agent (<code>zabbix-agent<\/code>, which runs as <code>zabbix_agentd<\/code>). With that agent, the template does nothing until the matching <strong>UserParameter<\/strong> definitions and SQL files are on the database host. Each item runs <code>psql<\/code> with one of those SQL files and returns the result to Zabbix. The steps above leave this part out, so linking the template alone produces only unsupported items.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Template<\/th><th>Agent<\/th><th>What you must deploy<\/th><\/tr><\/thead><tbody><tr><td>PostgreSQL by Zabbix agent<\/td><td>zabbix-agent (agentd)<\/td><td>UserParameter file, SQL scripts, <code>psql<\/code> client, <code>.pgpass<\/code> or trust rule<\/td><\/tr><tr><td>PostgreSQL by Zabbix agent 2<\/td><td>zabbix-agent2<\/td><td>PostgreSQL plugin (built in or a separate package, depending on version) and connection macros<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The <code>pg_stat_statements<\/code> change in Step 3 above is not needed by either official template. It is safe but optional. If you do enable it, add it to the existing <code>shared_preload_libraries<\/code> list instead of replacing that list, restart PostgreSQL, and run <code>CREATE EXTENSION pg_stat_statements;<\/code> in the database you want to inspect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install and configure the agent correctly<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The repository package in Step 1 is pinned to Zabbix 6.0 on Ubuntu 20.04, and that Ubuntu release is out of standard support. Package file names in the Zabbix repository also change between releases. Copy the current repository command from the Zabbix download page for your OS and server version. The agent major version should match your Zabbix server, or be older than it.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># After adding the Zabbix repository for your version and OS<\/span>\nsudo apt update\nsudo apt install -y zabbix-agent postgresql-client git\n\n<span class=\"hljs-comment\"># \/etc\/zabbix\/zabbix_agentd.conf - key settings<\/span>\nServer=<span class=\"hljs-number\">192.0<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.10<\/span>          <span class=\"hljs-comment\"># Zabbix server or proxy IP (passive checks)<\/span>\nServerActive=<span class=\"hljs-number\">192.0<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.10<\/span>    <span class=\"hljs-comment\"># same, for active checks<\/span>\nHostname=pg-prod<span class=\"hljs-number\">-01<\/span>        <span class=\"hljs-comment\"># must match the host name in the Zabbix UI exactly<\/span>\nTimeout=<span class=\"hljs-number\">10<\/span>                 <span class=\"hljs-comment\"># some PostgreSQL queries take longer than the 3s default<\/span>\n\nsudo systemctl enable --now zabbix-agent\nsudo systemctl restart zabbix-agent\n\n<span class=\"hljs-comment\"># Allow the server to reach the passive agent port<\/span>\nsudo ufw allow from <span class=\"hljs-number\">192.0<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.10<\/span> to any port <span class=\"hljs-number\">10050<\/span> proto tcp<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Also confirm that <code>Include=\/etc\/zabbix\/zabbix_agentd.d\/*.conf<\/code> is present and uncommented in <code>zabbix_agentd.conf<\/code>. The official packages set it by default, and the PostgreSQL user parameters are loaded from that directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a proper monitoring role<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The role in Step 3 above is granted <code>SELECT<\/code> on tables in the <code>public<\/code> schema. That gives it access to your application data, which the monitoring user should not have. It also does not give access to the statistics views and functions the template needs. PostgreSQL 10 and later include the built-in <code>pg_monitor<\/code> role for exactly this purpose. Set the password interactively with <code>\\password<\/code> so it does not end up in shell history.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">sudo -u postgres psql -c <span class=\"hljs-string\">\"CREATE USER zbx_monitor WITH INHERIT;\"<\/span>\nsudo -u postgres psql -c <span class=\"hljs-string\">\"GRANT pg_monitor TO zbx_monitor;\"<\/span>\nsudo -u postgres psql -c <span class=\"hljs-string\">\"\\password zbx_monitor\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Next, allow this role to connect locally. Find the right file with <code>sudo -u postgres psql -c &#039;SHOW hba_file;&#039;<\/code>. Don&#039;t hard-code a version path such as <code>\/etc\/postgresql\/12\/<\/code>. Put these lines above any broader rules, because PostgreSQL uses the first rule that matches.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># TYPE  DATABASE  USER         ADDRESS        METHOD<\/span>\nhost    all       zbx_monitor  <span class=\"hljs-number\">127.0<\/span><span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">.1<\/span>\/<span class=\"hljs-number\">32<\/span>   scram-sha<span class=\"hljs-number\">-256<\/span>\nhost    all       zbx_monitor  ::<span class=\"hljs-number\">1<\/span>\/<span class=\"hljs-number\">128<\/span>        scram-sha<span class=\"hljs-number\">-256<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo systemctl reload postgresql<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Deploy the template&#039;s user parameters and SQL files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The user parameter file and SQL scripts live in the Zabbix source tree under <code>templates\/db\/postgresql<\/code>. Check out the branch that matches your server version (for example <code>release\/6.0<\/code> or <code>release\/7.0<\/code>). A sparse checkout downloads only that directory.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">git <span class=\"hljs-keyword\">clone<\/span> --depth <span class=\"hljs-number\">1<\/span> --branch release\/<span class=\"hljs-number\">7.0<\/span> --filter=blob:none --sparse https:<span class=\"hljs-comment\">\/\/github.com\/zabbix\/zabbix.git<\/span>\ncd zabbix\ngit sparse-checkout set templates\/db\/postgresql\nls templates\/db\/postgresql      <span class=\"hljs-comment\"># README.md, postgresql\/, template_db_postgresql.conf, ...<\/span>\n\nsudo mkdir -p \/<span class=\"hljs-keyword\">var<\/span>\/lib\/zabbix\nsudo cp -r templates\/db\/postgresql\/postgresql \/<span class=\"hljs-keyword\">var<\/span>\/lib\/zabbix\/\nsudo cp templates\/db\/postgresql\/template_db_postgresql.conf \/etc\/zabbix\/zabbix_agentd.d\/\nsudo chown -R zabbix:zabbix \/<span class=\"hljs-keyword\">var<\/span>\/lib\/zabbix\n\n<span class=\"hljs-comment\"># Password file used by psql when the agent runs a query<\/span>\nsudo -u zabbix tee \/<span class=\"hljs-keyword\">var<\/span>\/lib\/zabbix\/.pgpass &gt;\/dev\/<span class=\"hljs-keyword\">null<\/span> &lt;&lt;<span class=\"hljs-string\">'EOF'<\/span>\nlocalhost:<span class=\"hljs-number\">5432<\/span>:*:zbx_monitor:YourStrongPassword\nEOF\nsudo chmod <span class=\"hljs-number\">600<\/span> \/<span class=\"hljs-keyword\">var<\/span>\/lib\/zabbix\/.pgpass\n\nsudo systemctl restart zabbix-agent<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The shipped <code>.conf<\/code> file points to <code>\/var\/lib\/zabbix\/postgresql\/*.sql<\/code>, so keep that path. The host field in <code>.pgpass<\/code> (<code>localhost<\/code> here) must match the host that <code>psql<\/code> is given, which is the <code>{$PG.HOST}<\/code> macro. If file names in your branch differ, follow the <code>README.md<\/code> in that directory. It always matches the template version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Link the template and set macros<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the hosts list: <strong>Configuration &gt; Hosts<\/strong> in Zabbix 6.0, or <strong>Data collection &gt; Hosts<\/strong> in 6.4 and 7.x. Create or edit the host. The <strong>Host name<\/strong> must equal the agent&#039;s <code>Hostname<\/code>.<\/li>\n\n\n<li>Add an <strong>Agent<\/strong> interface with the database server&#039;s IP and port <code>10050<\/code>.<\/li>\n\n\n<li>On the <strong>Templates<\/strong> tab, link <strong>PostgreSQL by Zabbix agent<\/strong>. It ships with the server, so no import is needed unless you are upgrading it.<\/li>\n\n\n<li>On the <strong>Macros<\/strong> tab, choose <strong>Inherited and host macros<\/strong> and check <code>{$PG.HOST}<\/code>, <code>{$PG.PORT}<\/code>, <code>{$PG.USER}<\/code> and <code>{$PG.DB}<\/code>. The defaults are typically <code>localhost<\/code>, <code>5432<\/code>, <code>zbx_monitor<\/code> and <code>postgres<\/code>. Override any value that differs on your server.<\/li>\n\n\n<li>Click <strong>Update<\/strong>, then wait a few minutes for the first checks and for low-level discovery of databases.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Verify from the command line<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Test each layer separately before you look in the UI. First check that <code>psql<\/code> can log in as the agent would. Then run an item key through the agent on the database host, and finally query it from the Zabbix server.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># 1. psql login as the zabbix OS user (uses \/var\/lib\/zabbix\/.pgpass)<\/span>\nsudo -u zabbix -H psql -h localhost -p <span class=\"hljs-number\">5432<\/span> -U zbx_monitor -d postgres -c <span class=\"hljs-string\">\"SELECT version();\"<\/span>\n\n<span class=\"hljs-comment\"># 2. List the keys the agent now knows about<\/span>\ngrep -o <span class=\"hljs-string\">'^UserParameter=&#91;^,]*'<\/span> \/etc\/zabbix\/zabbix_agentd.d\/template_db_postgresql.conf | head\n\n<span class=\"hljs-comment\"># 3. Run one key locally through the agent<\/span>\nsudo -u zabbix -H zabbix_agentd -t <span class=\"hljs-string\">'pgsql.ping&#91;\"localhost\",\"5432\",\"zbx_monitor\",\"postgres\"]'<\/span>\n\n<span class=\"hljs-comment\"># 4. From the Zabbix server (package zabbix-get)<\/span>\nzabbix_get -s <span class=\"hljs-number\">192.0<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.20<\/span> -k <span class=\"hljs-string\">'pgsql.ping&#91;\"localhost\",\"5432\",\"zbx_monitor\",\"postgres\"]'<\/span>\n\n<span class=\"hljs-comment\"># Follow logs instead of cat-ing the whole file<\/span>\nsudo tail -f \/<span class=\"hljs-keyword\">var<\/span>\/log\/zabbix\/zabbix_agentd.log\nsudo tail -f \/<span class=\"hljs-keyword\">var<\/span>\/log\/postgresql\/postgresql-*-main.log<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Steps 3 and 4 should return a value, not <code>ZBX_NOTSUPPORTED<\/code> or a <code>psql<\/code> error. The UserParameter line for each key shows what a healthy result looks like. After that, <strong>Monitoring &gt; Latest data<\/strong> filtered by the host should show PostgreSQL items with recent timestamps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>Unknown metric pgsql.*<\/code><\/td><td>UserParameter file not loaded<\/td><td>Check the <code>Include=<\/code> line and the file location, then restart the agent<\/td><\/tr><tr><td><code>psql: command not found<\/code><\/td><td>No PostgreSQL client on the agent host<\/td><td><code>sudo apt install postgresql-client<\/code><\/td><\/tr><tr><td><code>fe_sendauth: no password supplied<\/code><\/td><td><code>.pgpass<\/code> missing, wrong permissions, host mismatch, or the zabbix user&#039;s home is not <code>\/var\/lib\/zabbix<\/code><\/td><td>Set mode <code>600<\/code>, owner <code>zabbix<\/code>, and match the host field. Or run <code>sudo systemctl edit zabbix-agent<\/code> and add <code>Environment=PGPASSFILE=\/var\/lib\/zabbix\/.pgpass<\/code> under <code>[Service]<\/code><\/td><\/tr><tr><td><code>no pg_hba.conf entry for host<\/code><\/td><td>No matching rule, or a broader rule matches first<\/td><td>Add the <code>zbx_monitor<\/code> rules above the others and reload PostgreSQL<\/td><\/tr><tr><td><code>permission denied for ...<\/code><\/td><td>Role lacks monitoring privileges<\/td><td><code>GRANT pg_monitor TO zbx_monitor;<\/code><\/td><\/tr><tr><td><code>could not open file \/var\/lib\/zabbix\/postgresql\/...<\/code><\/td><td>SQL scripts not copied, or not readable by zabbix<\/td><td>Copy the <code>postgresql\/<\/code> directory and <code>chown -R zabbix:zabbix<\/code><\/td><\/tr><tr><td>Agent interface unavailable<\/td><td><code>Server=<\/code> mismatch or port 10050 blocked<\/td><td>Fix <code>Server=<\/code> and the firewall, then test with <code>zabbix_get<\/code><\/td><\/tr><tr><td>Item times out<\/td><td>Query slower than the agent <code>Timeout<\/code><\/td><td>Raise <code>Timeout<\/code> in the agent config (in 7.x, item timeouts can also be set in the UI)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Alternative: Zabbix agent 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Agent 2 has a native PostgreSQL plugin, so you don&#039;t need SQL files, <code>.pgpass<\/code> or <code>psql<\/code>. Install <code>zabbix-agent2<\/code>, plus <code>zabbix-agent2-plugin-postgresql<\/code> on releases where the plugin ships separately. Link <strong>PostgreSQL by Zabbix agent 2<\/strong> and fill in the template&#039;s connection macros (URI, user and password). You can also define a named session in the plugin config under <code>\/etc\/zabbix\/zabbix_agent2.d\/plugins.d\/<\/code>. Use the same <code>pg_monitor<\/code> role and <code>pg_hba.conf<\/code> rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Both agents listen on port 10050 by default. Replace <code>zabbix-agent<\/code> with <code>zabbix-agent2<\/code> rather than running both on the same port.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Which permissions does the Zabbix PostgreSQL monitoring user need?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On PostgreSQL 10 and later, grant the built-in <code>pg_monitor<\/code> role to a dedicated login role. It does not need superuser rights or SELECT on application tables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why are all PostgreSQL items unsupported after linking the template?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With the classic agent, the template needs its UserParameter file in <code>\/etc\/zabbix\/zabbix_agentd.d\/<\/code> and its SQL scripts in <code>\/var\/lib\/zabbix\/postgresql\/<\/code>. Without those files the agent doesn&#039;t recognise the <code>pgsql.*<\/code> keys.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I use Zabbix agent or Zabbix agent 2 for PostgreSQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Agent 2 is simpler for new setups because its native plugin needs no scripts, <code>psql<\/code> or <code>.pgpass<\/code>. The classic agent template still works and suits hosts that are standardised on <code>zabbix_agentd<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need pg_stat_statements for Zabbix PostgreSQL monitoring?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The official templates use standard statistics views. Enable <code>pg_stat_statements<\/code> only if you want query-level analysis outside the template.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can one Zabbix agent monitor a remote PostgreSQL server?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Point <code>{$PG.HOST}<\/code> at the remote server, add a matching <code>.pgpass<\/code> entry and allow the agent&#039;s IP in the remote <code>pg_hba.conf<\/code>. Installing the agent on the database host is still the more common setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/monitoring-observability\/zabbix\/\">More Zabbix tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/database\/\">More Databases tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/senior-database-administrator-role-blueprint-responsibilities-skills-kpis-and-career-path\/\">Senior Database Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To monitor PostgreSQL with the classic Zabbix agent, you install the agent on the database host, create a read-only monitoring role, and deploy the user parameters and&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4897,10975],"tags":[7295,26273],"class_list":["post-46297","post","type-post","status-publish","format-standard","hentry","category-zabbix","category-database","tag-postgresql","tag-zabbix-agent"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=46297"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46297\/revisions"}],"predecessor-version":[{"id":80249,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46297\/revisions\/80249"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=46297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=46297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=46297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}