diff --git a/checkmk/custom-files/local/monitor-postgrest b/checkmk/custom-files/local/monitor-postgrest
index bf49ed4e22a3ab3a67483297f7a825f0b59583e6..e32c45ab3bf0c4b3ba93298272ff1986d43ee86f 100644
--- a/checkmk/custom-files/local/monitor-postgrest
+++ b/checkmk/custom-files/local/monitor-postgrest
@@ -3,8 +3,10 @@
 instance_names=()
 instance_admin_ports=()
 {% for instance_name, instance_conf in instances.items() %}
+{% if 'admin-server-port' in instance_conf['config'] %}
 instance_names+=("{{ instance_name }}")
 instance_admin_ports+=("{{ instance_conf['config']['admin-server-port'] }}")
+{% endif %}
 {% endfor %}
 
 function check_endpoint() {
diff --git a/checkmk/debian/monitor_postgrest.sls b/checkmk/debian/monitor_postgrest.sls
index 7c9cb2a103ad65cee5cdc437c8876035aa84c83f..7816267ddc77ee091aae5acf0bb401d9b96eb631 100644
--- a/checkmk/debian/monitor_postgrest.sls
+++ b/checkmk/debian/monitor_postgrest.sls
@@ -1,8 +1,11 @@
-{% set instances = salt['pillar.get']("postgrest:instances") %}
+{% set has_ports_configured = salt['pillar.get']("postgrest:instances").values()|selectattr("config", "defined")|selectattr("config.admin-server-port", "defined") %}
 
+{% set file_path= '/usr/lib/check_mk_agent/local/monitor-postgrest' %}
 hsh_checkmk_monitor_postgrest_plugin:
+{% if has_ports_configured|list %}
+{% set instances = salt['pillar.get']("postgrest:instances") %}
   file.managed:
-    - name: /usr/lib/check_mk_agent/local/monitor-postgrest
+    - name: {{ file_path }}
     - source: salt://checkmk/custom-files/local/monitor-postgrest
     - template: jinja
     - context:
@@ -10,3 +13,7 @@ hsh_checkmk_monitor_postgrest_plugin:
     - mode: 755
     - user: root
     - group: root
+{% else %}
+  file.absent:
+    - name: {{ file_path }}
+{% endif %}