@@ -43,6 +43,7 @@ def __init__(self, submit_data_function, base_event, logger):
43
43
self ._total_columns_sent = 0
44
44
self .db_to_tables = {} # dbname : {"tables" : []}
45
45
self .db_info = {} # name to info
46
+ self .any_tables_found = False # Flag to track for permission issues
46
47
47
48
def set_base_event_data (self , hostname , tags , cloud_metadata , dbms_version , flavor ):
48
49
self ._base_event ["host" ] = hostname
@@ -55,6 +56,7 @@ def reset(self):
55
56
self ._total_columns_sent = 0
56
57
self ._columns_count = 0
57
58
self .db_info .clear ()
59
+ self .any_tables_found = False
58
60
59
61
def store_db_infos (self , db_infos ):
60
62
for db_info in db_infos :
@@ -64,6 +66,8 @@ def store(self, db_name, tables, columns_count):
64
66
self ._columns_count += columns_count
65
67
known_tables = self .db_to_tables .setdefault (db_name , [])
66
68
known_tables .extend (tables )
69
+ if tables :
70
+ self .any_tables_found = True
67
71
68
72
def columns_since_last_submit (self ):
69
73
return self ._columns_count
@@ -282,6 +286,16 @@ def _fetch_for_databases(self, db_infos, cursor):
282
286
)
283
287
)
284
288
289
+ # Check if we found databases but no tables across all of them.
290
+ # This happens when the datadog user has permissions to see databases
291
+ # but lacks SELECT privileges on the tables themselves, which prevents
292
+ # the agent from collecting table metadata.
293
+ if db_infos and not self ._data_submitter .any_tables_found :
294
+ self ._log .warning (
295
+ "No tables were found across any of the {} databases. This may indicate insufficient privileges "
296
+ "to view table metadata. The datadog user needs SELECT privileges on the tables." .format (len (db_infos ))
297
+ )
298
+
285
299
@tracked_method (agent_check_getter = agent_check_getter )
286
300
def _query_db_information (self , cursor ):
287
301
self ._cursor_run (cursor , query = SQL_DATABASES )
@@ -302,13 +316,12 @@ def _get_tables(self, db_name, cursor):
302
316
def _get_tables_data (self , table_list , db_name , cursor ):
303
317
304
318
if len (table_list ) == 0 :
305
- return
319
+ return 0 , []
320
+
306
321
table_name_to_table_index = {}
307
- table_names = ""
308
322
for i , table in enumerate (table_list ):
309
323
table_name_to_table_index [table ["name" ]] = i
310
- table_names += '"' + str (table ["name" ]) + '",'
311
- table_names = table_names [:- 1 ]
324
+ table_names = ',' .join (f'"{ str (table ["name" ])} "' for table in table_list )
312
325
total_columns_number = self ._populate_with_columns_data (
313
326
table_name_to_table_index , table_list , table_names , db_name , cursor
314
327
)
0 commit comments