Skip to content

Only query aurora_version() if aurora postgres extensions are available #20310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions postgres/changelog.d/20310.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check for aws extensions before querying aurora_version()
36 changes: 22 additions & 14 deletions postgres/datadog_checks/postgres/version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class VersionUtils(object):
def __init__(self):
self.log = get_check_logger()
self._seen_aurora_exception = False
self._is_aurora = None

@staticmethod
def get_raw_version(db):
Expand All @@ -38,21 +38,29 @@ def get_raw_version(db):
return raw_version

def is_aurora(self, db):
if self._seen_aurora_exception:
return False
if self._is_aurora is not None:
return self._is_aurora
with db as conn:
with conn.cursor(cursor_factory=CommenterCursor) as cursor:
# This query will pollute PG logs in non aurora versions,
# but is the only reliable way to detect aurora
try:
cursor.execute('select AURORA_VERSION();')
return True
except Exception as e:
self.log.debug(
"Captured exception %s while determining if the DB is aurora. Assuming is not", str(e)
)
self._seen_aurora_exception = True
return False
cursor.execute(
"SELECT 1 FROM pg_available_extension_versions "
"WHERE name ILIKE '%aurora%' OR comment ILIKE '%aurora%' "
"LIMIT 1;"
)
if cursor.fetchone():
# This query will pollute PG logs in non aurora versions,
# but is the only reliable way to detect aurora.
# Since we found aurora extensions, this should exist.
try:
cursor.execute('select AURORA_VERSION();')
self._is_aurora = True
return self._is_aurora
except Exception as e:
self.log.debug(
"Captured exception %s while determining if the DB is aurora. Assuming is not", str(e)
)
self._is_aurora = False
return self._is_aurora

@staticmethod
def parse_version(raw_version):
Expand Down
Loading