diff --git a/app/vmagent/influx/request_handler.go b/app/vmagent/influx/request_handler.go
index 489e0874ea..4ac39982e5 100644
--- a/app/vmagent/influx/request_handler.go
+++ b/app/vmagent/influx/request_handler.go
@@ -63,17 +63,18 @@ func insertRows(db string, rows []parser.Row) error {
 	for i := range rows {
 		r := &rows[i]
 		commonLabels = commonLabels[:0]
+		hasDBKey := false
 		for j := range r.Tags {
 			tag := &r.Tags[j]
 			if tag.Key == "db" {
-				db = ""
+				hasDBKey = true
 			}
 			commonLabels = append(commonLabels, prompbmarshal.Label{
 				Name:  tag.Key,
 				Value: tag.Value,
 			})
 		}
-		if len(db) > 0 {
+		if len(db) > 0 && !hasDBKey {
 			commonLabels = append(commonLabels, prompbmarshal.Label{
 				Name:  "db",
 				Value: db,
diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go
index bddb677a55..dc5c037225 100644
--- a/app/vminsert/influx/request_handler.go
+++ b/app/vminsert/influx/request_handler.go
@@ -70,6 +70,7 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount
 	for i := range rows {
 		r := &rows[i]
 		ic.Labels = ic.Labels[:0]
+		hasDBKey := false
 		for j := range r.Tags {
 			tag := &r.Tags[j]
 			if mayOverrideAccountProjectID {
@@ -82,11 +83,13 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount
 				}
 			}
 			if tag.Key == "db" {
-				db = ""
+				hasDBKey = true
 			}
 			ic.AddLabel(tag.Key, tag.Value)
 		}
-		ic.AddLabel("db", db)
+		if !hasDBKey {
+			ic.AddLabel("db", db)
+		}
 		ctx.metricGroupBuf = ctx.metricGroupBuf[:0]
 		if !*skipMeasurement {
 			ctx.metricGroupBuf = append(ctx.metricGroupBuf, r.Measurement...)