diff --git a/src/libs/zbxdbhigh/proxy.c b/src/libs/zbxdbhigh/proxy.c
index e3724731fe..198f165e5c 100644
--- a/src/libs/zbxdbhigh/proxy.c
+++ b/src/libs/zbxdbhigh/proxy.c
@@ -2393,7 +2393,7 @@ static int	proxy_get_history_data(zbx_uint64_t lastid, zbx_history_data_t **data
 	char			*sql = NULL;
 	size_t			sql_alloc = 0, sql_offset = 0, data_num = 0;
 	size_t			string_buffer_offset = 0;
-	zbx_uint64_t		id;
+	zbx_uint64_t		id, last_id_first = lastid;
 	int			retries = 1, total_retries = 10;
 	struct timespec		t_sleep = { 0, 100000000L }, t_rem;
 	zbx_history_data_t	*hd;
@@ -2417,6 +2417,13 @@ try_again:
 	{
 		ZBX_STR2UINT64(id, row[0]);
 
+		if (id <= lastid)
+		{
+			zabbix_log(LOG_LEVEL_ERR, "id:" ZBX_FS_UI64 " is less than lastid:" ZBX_FS_UI64 " datanum:%d"
+					" first lastid:" ZBX_FS_UI64, id, lastid, (int)data_num, last_id_first);
+			continue;
+		}
+
 		if (1 < id - lastid)
 		{
 			/* At least one record is missing. It can happen if some DB syncer process has */
