Skip to content

Commit f9a39ea

Browse files
dalextorresclaude
andauthored
[postgres] Exclude rdsadmin database from schema collection by default (DataDog#22470)
* [postgres] Exclude rdsadmin database from schema collection by default The rdsadmin database is an AWS RDS system database that is not accessible to users. This change adds it to the default exclude_databases list for collect_schemas to prevent errors when the Agent attempts to collect schema information from RDS instances. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * [postgres] Exclude system and admin databases from schema collection by default Exclude the following databases from schema collection and autodiscovery by default: - template0, template1 (PostgreSQL system databases) - rdsadmin (AWS RDS) - azure_maintenance (Azure) - cloudsqladmin, alloydbadmin, alloydbmetadata (Google Cloud) These databases are either system databases or cloud provider admin databases that are not accessible to users. This prevents errors when the Agent attempts to collect schema information or autodiscover databases. Also introduces DEFAULT_EXCLUDED_DATABASES constant in dict_defaults.py to avoid duplication of the excluded databases list across: - instance_database_autodiscovery() - instance_collect_schemas() - test_config_defaults.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c97f2a2 commit f9a39ea

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

postgres/assets/configuration/spec.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ files:
471471
- "cloudsqladmin"
472472
- "rdsadmin"
473473
display_default:
474+
- "template0"
475+
- "template1"
476+
- "rdsadmin"
477+
- "azure_maintenance"
474478
- "cloudsqladmin"
475-
- "rdsadmin"
476479
- "alloydbadmin"
477480
- "alloydbmetadata"
478481
- name: refresh
@@ -794,7 +797,7 @@ files:
794797
- "mydb"
795798
- name: exclude_databases
796799
description: |
797-
A list of regex patterns to exclude databases.
800+
A list of regex patterns to exclude databases.
798801
Any database whose name matches any one of these patterns will be excluded.
799802
If empty, all databases matching other filters are included.
800803
value:
@@ -803,6 +806,14 @@ files:
803806
type: string
804807
example:
805808
- "privatedb.*"
809+
default:
810+
- "template0"
811+
- "template1"
812+
- "rdsadmin"
813+
- "azure_maintenance"
814+
- "cloudsqladmin"
815+
- "alloydbadmin"
816+
- "alloydbmetadata"
806817
- name: include_schemas
807818
description: |
808819
A list of regex patterns to include schemas.

postgres/changelog.d/22470.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Exclude system and cloud provider admin databases from schema collection by default

postgres/datadog_checks/postgres/config_models/dict_defaults.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

88
from . import instance
99

10+
# Default databases to exclude from schema collection and autodiscovery.
11+
# These are system databases or cloud provider admin databases that are not accessible to users.
12+
# This list should match the default value for `ignore_databases` in spec.yaml.
13+
DEFAULT_EXCLUDED_DATABASES = [
14+
"template0",
15+
"template1",
16+
"rdsadmin",
17+
"azure_maintenance",
18+
"cloudsqladmin",
19+
"alloydbadmin",
20+
"alloydbmetadata",
21+
]
22+
1023

1124
def instance_database_identifier():
1225
return instance.DatabaseIdentifier(
@@ -20,7 +33,7 @@ def instance_database_autodiscovery():
2033
global_view_db="postgres",
2134
max_databases=100,
2235
include=[".*"],
23-
exclude=["cloudsqladmin", "rdsadmin", "alloydbadmin", "alloydbmetadata"],
36+
exclude=list(DEFAULT_EXCLUDED_DATABASES),
2437
refresh=600,
2538
)
2639

@@ -78,7 +91,7 @@ def instance_collect_schemas():
7891
max_columns=50,
7992
collection_interval=600,
8093
include_databases=[],
81-
exclude_databases=[],
94+
exclude_databases=list(DEFAULT_EXCLUDED_DATABASES),
8295
include_schemas=[],
8396
exclude_schemas=[],
8497
include_tables=[],

postgres/datadog_checks/postgres/data/conf.yaml.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ instances:
402402
# - master$
403403
# - AdventureWorks.*
404404

405-
## @param exclude - list of strings - optional - default: ['cloudsqladmin', 'rdsadmin', 'alloydbadmin', 'alloydbmetadata']
405+
## @param exclude - list of strings - optional - default: ['template0', 'template1', 'rdsadmin', 'azure_maintenance', 'cloudsqladmin', 'alloydbadmin', 'alloydbmetadata']
406406
## Regular expression for database names to exclude as part of `database_autodiscovery`.
407407
## Character casing is ignored. The regular expressions start matching from the beginning,
408408
## so to match anywhere, prepend `.*`. For exact matches append `$`.
@@ -594,7 +594,7 @@ instances:
594594
# - mydb
595595

596596
## @param exclude_databases - list of strings - optional
597-
## A list of regex patterns to exclude databases.
597+
## A list of regex patterns to exclude databases.
598598
## Any database whose name matches any one of these patterns will be excluded.
599599
## If empty, all databases matching other filters are included.
600600
#

postgres/tests/test_config_defaults.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pytest
1414

1515
from datadog_checks.postgres.config import build_config
16+
from datadog_checks.postgres.config_models.dict_defaults import DEFAULT_EXCLUDED_DATABASES
1617

1718
# Single source of truth for all expected default values
1819
# Organized by category for readability
@@ -55,15 +56,7 @@
5556
'table_count_limit': 200,
5657
'max_relations': 300,
5758
# === Database filtering ===
58-
'ignore_databases': [
59-
'template0',
60-
'template1',
61-
'rdsadmin',
62-
'azure_maintenance',
63-
'cloudsqladmin',
64-
'alloydbadmin',
65-
'alloydbmetadata',
66-
],
59+
'ignore_databases': list(DEFAULT_EXCLUDED_DATABASES),
6760
'ignore_schemas_owned_by': [
6861
'rds_superuser',
6962
'rdsadmin',
@@ -120,6 +113,12 @@
120113
'max_columns': 50,
121114
'collection_interval': 600,
122115
'max_query_duration': 60,
116+
'include_databases': [],
117+
'exclude_databases': list(DEFAULT_EXCLUDED_DATABASES),
118+
'include_schemas': [],
119+
'exclude_schemas': [],
120+
'include_tables': [],
121+
'exclude_tables': [],
123122
},
124123
# === DBM: Obfuscator options ===
125124
'obfuscator_options': {
@@ -145,7 +144,7 @@
145144
'global_view_db': 'postgres',
146145
'max_databases': 100,
147146
'refresh': 600,
148-
'exclude': ['cloudsqladmin', 'rdsadmin', 'alloydbadmin', 'alloydbmetadata'],
147+
'exclude': list(DEFAULT_EXCLUDED_DATABASES),
149148
'include': ['.*'],
150149
},
151150
# === DBM: Lock metrics ===

0 commit comments

Comments
 (0)