@@ -529,22 +529,33 @@ func (pgw *PostgresWriter) MaintainUniqueSources() {
529529 }
530530
531531 // updates listing table entries for a single metric.
532- sqlUpdateListingTable := "SELECT admin.update_listing_table(metric_table_name => $1);"
532+ sqlUpdateListingTable := "SELECT * FROM admin.update_listing_table(metric_table_name => $1);"
533533 for i , tableName := range allDistinctMetricTables {
534534 metricName := strings .Replace (tableName , "public." , "" , 1 )
535535 allDistinctMetricTables [i ] = metricName // later usage in sqlDroppedTables requires no "public." prefix.
536536 logger .Debugf ("Updating admin.all_distinct_dbname_metrics listing for metric: %s" , metricName )
537- if _ , err := pgw .sinkDb .Exec (pgw .ctx , sqlUpdateListingTable , tableName ); err != nil {
537+ var deletedRowsCnt , insertedRowsCnt int ;
538+ err = pgw .sinkDb .QueryRow (pgw .ctx , sqlUpdateListingTable , tableName ).Scan (& deletedRowsCnt , & insertedRowsCnt );
539+ if err != nil {
538540 logger .Errorf ("Could not update admin.all_distinct_dbname_metrics listing for metric '%s': %s" , metricName , err )
539541 }
542+ if deletedRowsCnt > 0 {
543+ logger .Infof ("Removed %d stale entries from admin.all_distinct_dbname_metrics listing table for metric: %s" , deletedRowsCnt , metricName )
544+ }
545+ if insertedRowsCnt > 0 {
546+ logger .Infof ("Added %d entries to admin.all_distinct_dbname_metrics listing table for metric: %s" , insertedRowsCnt , metricName )
547+ }
540548 time .Sleep (time .Minute )
541549 }
542550
543551 // removes all entries for any non-existing table.
544552 sqlRemoveDroppedTables := "SELECT admin.remove_dropped_tables_listing(existing_metrics => $1)"
545- _ , err = pgw .sinkDb .Exec (pgw .ctx , sqlRemoveDroppedTables , allDistinctMetricTables )
553+ var deletedRowsCnt int ;
554+ err = pgw .sinkDb .QueryRow (pgw .ctx , sqlRemoveDroppedTables , allDistinctMetricTables ).Scan (& deletedRowsCnt )
546555 if err != nil {
547556 logger .Errorf ("Could not update admin.all_distinct_dbname_metrics listing table for dropped metric tables: %s" , err )
557+ } else if deletedRowsCnt > 0 {
558+ logger .Infof ("Removed %d stale entries for dropped metric tables from admin.all_distinct_dbname_metrics listing table" , deletedRowsCnt )
548559 }
549560}
550561
0 commit comments