How to Recover From a Malformed Database Image in wazuh-db

If you encounter the “database image malformed” error in wazuh-db, it usually means that one or more of Wazuh’s internal SQLite databases have become corrupted.

Because wazuh-db is responsible for storing and retrieving critical endpoint information, corruption can quickly affect multiple components across your Wazuh deployment.

Depending on which database is damaged, the symptoms can range from relatively minor inconsistencies to widespread monitoring failures.

Administrators may notice that agents stop updating their inventory, File Integrity Monitoring (FIM) results disappear, vulnerability detection stops producing findings, or the Wazuh manager fails to process certain events correctly.

In severe cases, agents remain connected but their metadata no longer updates, making it difficult to trust the information displayed in the Wazuh Dashboard.

The error itself originates from SQLite, the embedded database engine used by wazuh-db. SQLite reports “database disk image is malformed” whenever it detects structural corruption that prevents it from reading database pages safely.

Rather than continuing to operate on a damaged database and risking additional data loss, Wazuh surfaces the error so administrators can investigate and repair or rebuild the affected database.

Database corruption can occur for several reasons, including unexpected power failures, disk errors, abrupt system shutdowns, filesystem corruption, storage hardware failures, or processes being terminated while SQLite is writing changes to disk.

In this guide, you’ll learn how wazuh-db database image malformed errors occur, how to identify the affected database, how to verify whether corruption actually exists, and the safest recovery procedures.

We’ll also cover preventive best practices that reduce the likelihood of future database corruption and help keep your Wazuh deployment healthy.

Resource:

SQLite Database Corruption Documentation – https://www.sqlite.org/howtocorrupt.html


What Is wazuh-db?

The wazuh-db daemon is one of the core services within the Wazuh manager.

It acts as a high-performance database interface between other Wazuh components and the SQLite databases that store agent-related information.

Instead of every module interacting directly with SQLite files, modules communicate with wazuh-db, which manages database access, synchronization, and consistency.

This architecture improves performance while reducing contention between multiple Wazuh processes that need simultaneous access to agent data.

At its core, wazuh-db uses SQLite because it is lightweight, reliable, serverless, and well suited for local database operations.

Each agent maintains its own database containing operational information that various Wazuh modules continuously update.

How wazuh-db stores

These databases commonly store:

  • Agent metadata and registration information
  • File Integrity Monitoring (FIM) events and file state
  • Syscollector hardware and software inventory
  • Vulnerability Detection package information
  • Agent synchronization and state tracking data
  • Internal module metadata used by multiple Wazuh services

For example:

  • Syscollector continuously updates installed software, operating system information, running processes, network interfaces, and hardware inventory.
  • Vulnerability Detection compares collected package information against vulnerability feeds.
  • File Integrity Monitoring records monitored files and detects changes over time.
  • Other modules rely on the same databases to maintain agent state and synchronization.

Because so many Wazuh components depend on these SQLite databases, maintaining database integrity is essential.

Even a single corrupted database page can prevent modules from reading inventory data or writing new information, leading to cascading issues throughout the Wazuh platform.

Healthy databases allow:

  • Reliable event processing
  • Accurate asset inventories
  • Consistent vulnerability scanning
  • Stable File Integrity Monitoring
  • Proper synchronization between agents and the manager

Once corruption appears, administrators should treat it as a storage integrity issue rather than simply restarting services, since restarting alone rarely repairs damaged SQLite files.

Resources:

 Wazuh Architecture Documentation – https://documentation.wazuh.com/current/getting-started/architecture.html

Related Guides:


What Does “database image malformed” Mean?

The error “database image malformed” is generated directly by SQLite when it detects corruption within the physical structure of a database file.

Rather than indicating an application bug in Wazuh itself, the message tells you that SQLite can no longer safely interpret part of the database.

Unlike traditional database servers, SQLite stores the entire database in a single file.

Every table, index, page, and metadata structure must remain internally consistent.

If SQLite discovers invalid page headers, broken indexes, corrupted B-tree structures, missing pages, or inconsistent checksums, it reports the database as malformed.

When wazuh-db attempts to query or update a corrupted database, SQLite returns an error similar to:

database disk image is malformed

Wazuh then records the failure in its logs because the requested operation cannot be completed successfully.

Difference between logical corruption and filesystem corruption

It is important to distinguish between logical database corruption and filesystem corruption.

Logical database corruption occurs when the SQLite file itself contains damaged structures.

This may result from interrupted writes, hardware failures, memory corruption, or software crashes during database updates.

Filesystem corruption, on the other hand, affects the storage layer beneath SQLite.

Problems such as bad sectors, damaged filesystems, failing SSDs, RAID issues, or kernel storage errors may corrupt multiple files, not just the SQLite database.

In these situations, simply rebuilding the database without addressing the underlying storage issue often results in recurring corruption.

Administrators frequently discover the problem while reviewing Wazuh manager logs.

Common log messages include:

wazuh-db: ERROR: database disk image is malformed

wazuh-db: ERROR: SQLite database query failed.

wazuh-db: ERROR: Cannot execute statement because the database is corrupted.

ossec-analysisd: WARNING: Failed to retrieve agent database information.

wazuh-modulesd: ERROR: Unable to update Syscollector inventory.

The exact messages vary depending on which Wazuh module is accessing the damaged database, but they generally point back to SQLite reporting corruption.

Whenever you see this error, avoid immediately deleting the database.

First determine whether the corruption is isolated to a single agent database or indicative of broader storage problems.

Checking filesystem health, disk SMART data, and system logs before rebuilding the database can prevent repeated failures caused by an underlying hardware issue.

Feature insight: The SQLite developers emphasize that SQLite database corruption is uncommon under normal operation and is most often associated with external factors such as faulty storage hardware, filesystem issues, incomplete writes caused by power loss, or application-level misuse.

Their guidance recommends identifying and eliminating the root cause before restoring or recreating the database to avoid repeated corruption.

Example log snippet

2026/07/09 11:14:08 wazuh-db: ERROR: database disk image is malformed
2026/07/09 11:14:08 wazuh-db: ERROR: Cannot execute SQL statement.
2026/07/09 11:14:08 wazuh-modulesd:syscollector: ERROR: Failed to update agent inventory.
2026/07/09 11:14:09 wazuh-db: INFO: Retrying database operation.
2026/07/09 11:14:09 wazuh-db: ERROR: database disk image is malformed
Resources:

SQLite “How To Corrupt Your Database Files” – https://www.sqlite.org/howtocorrupt.html


Common Symptoms

A malformed SQLite database can affect far more than a single Wazuh module.

Since wazuh-db serves as the storage layer for multiple services, corruption often causes seemingly unrelated issues throughout the deployment.

The exact symptoms depend on which database is damaged, but administrators typically observe one or more of the following.

Repeated “database image malformed” Errors in Logs

The most obvious symptom is the continuous appearance of SQLite corruption errors in the Wazuh manager logs.

Because various modules repeatedly attempt to read or write to the damaged database, the same error may be logged every few seconds or minutes.

Typical messages include:

  • database disk image is malformed
  • SQLite query failed
  • Cannot execute SQL statement
  • Database read error

If left unresolved, log files can grow rapidly due to repeated retries.

Failed Agent Synchronization

When agent databases become corrupted, synchronization between the agent and manager may no longer function correctly.

Symptoms include:

  • Agent information stops updating.
  • Configuration changes are not reflected.
  • Inventory synchronization stalls.
  • Agent status becomes inconsistent.

The agent may still appear connected while silently failing to synchronize important metadata.

Missing Inventory Data

Syscollector relies heavily on wazuh-db to store endpoint inventory.

A corrupted database can cause missing or incomplete:

  • Installed software
  • Operating system information
  • Running processes
  • Network interfaces
  • Hardware inventory
  • Installed packages

As a result, administrators may notice devices appearing only partially populated within the dashboard.

Related Guide: How to Monitor Linux Event Logs Using Wazuh

Vulnerability Detection Stops Updating

Vulnerability Detection depends on accurate Syscollector inventory.

If package information cannot be stored or retrieved, vulnerability scans may stop producing new findings.

Common symptoms include:

  • Old vulnerabilities remain indefinitely.
  • Newly installed software is never scanned.
  • No recent vulnerability data appears.
  • Scan timestamps stop updating.

This often leads administrators to believe the Vulnerability Detection module has failed, when the underlying issue is actually SQLite corruption.

Related Guide: Wazuh Vulnerability Detection Not Working? Here’s How to Fix It

File Integrity Monitoring (FIM) Inconsistencies

Because File Integrity Monitoring also stores metadata within agent databases, corruption may lead to:

  • Missing monitored files
  • Files disappearing from reports
  • Duplicate entries
  • Inconsistent change detection
  • Missing FIM alerts

In severe cases, FIM scans complete successfully but produce incomplete results.

Related Guide: How to Configure File Integrity Monitoring (FIM) in Wazuh

High CPU Usage Caused by Repeated Retries

Many Wazuh modules continuously retry failed database operations.

Instead of failing once, they repeatedly:

  • Open the database
  • Execute SQL queries
  • Receive corruption errors
  • Retry again

This retry loop can cause wazuh-db to consume noticeably more CPU than normal.

If the corruption affects multiple databases simultaneously, CPU utilization may increase significantly.

Related Guide: Why Is Wazuh Using High CPU? Troubleshooting Guide

Missing Data in the Wazuh Dashboard

Database corruption frequently appears as missing information rather than obvious error messages.

Administrators may observe:

  • Empty inventory pages
  • Missing vulnerability reports
  • Blank widgets
  • Incomplete agent details
  • Missing FIM history
  • Outdated statistics

Since the dashboard simply displays information stored by wazuh-db, corrupted databases often result in incomplete visualizations.

Unexpected Agent Behavior

Some agents continue sending events while others appear partially functional.

Examples include:

  • Agent remains connected but never updates inventory.
  • Configuration changes are ignored.
  • Event counts stop increasing.
  • Modules fail intermittently.
  • Agent information becomes stale.

Because corruption usually affects only specific SQLite databases, the resulting behavior can appear inconsistent and difficult to diagnose.


Common Causes

SQLite databases are designed to be extremely reliable, and corruption is relatively rare under normal operating conditions.

According to the SQLite development team, database corruption is almost always caused by external factors such as hardware failures, storage problems, interrupted writes, or improper handling of database files rather than defects in SQLite itself.

Understanding these root causes helps prevent future occurrences after the database has been repaired or rebuilt.

Unexpected Server Shutdowns

One of the most common causes is an unexpected interruption while SQLite is writing data.

Examples include:

  • Sudden power outages
  • Kernel panics
  • Forced system resets
  • Virtual machine crashes
  • Hypervisor failures
  • Accidental power cycling

Although SQLite uses journaling mechanisms to minimize corruption, no database engine can completely protect against storage failures occurring during critical write operations.

Disk Corruption

Underlying storage hardware problems frequently lead to malformed databases.

Examples include:

  • Bad sectors
  • SSD wear-out
  • HDD mechanical failures
  • RAID degradation
  • Controller failures
  • Unrecoverable read/write errors

If storage hardware begins returning corrupted data, SQLite eventually detects inconsistencies within the database pages.

Filesystem Problems

Filesystem corruption may damage SQLite databases even when the storage hardware itself is healthy.

Examples include:

  • Unclean filesystem shutdowns
  • Corrupted filesystem metadata
  • Mount failures
  • Journal replay errors
  • Filesystem inconsistencies after crashes

Before rebuilding databases, administrators should verify filesystem health to avoid recurring corruption.

Running Out of Disk Space

SQLite requires sufficient free space to complete transactions safely.

When disks become completely full, writes may terminate unexpectedly, resulting in:

  • Partial transactions
  • Incomplete journal files
  • Interrupted checkpoints
  • Damaged database pages

Monitoring disk utilization helps prevent this avoidable cause of corruption.

Memory or Hardware Errors

Faulty hardware can silently corrupt data before it reaches disk.

Potential causes include:

  • Defective RAM
  • Storage controller failures
  • Motherboard issues
  • CPU cache errors
  • DMA transfer problems

Enterprise deployments often use ECC memory to reduce the likelihood of silent memory corruption affecting databases.

Manual Modification of Database Files

SQLite databases should never be modified while wazuh-db is actively using them.

Risky actions include:

  • Editing databases directly with SQLite tools
  • Copying active database files without stopping Wazuh
  • Restoring incomplete backups
  • Replacing individual SQLite files
  • Manually deleting internal database objects

These operations can easily leave databases in an inconsistent state.

Interrupted Wazuh Upgrades

Database corruption occasionally appears after interrupted upgrades.

Possible causes include:

  • Upgrade failures
  • Unexpected reboot during migration
  • Package installation interruption
  • Service termination before migration completed

Whenever an upgrade fails unexpectedly, administrators should verify database integrity before restarting production workloads.

Related Guide: How to Upgrade a Wazuh Agent

Third-Party Backup or Antivirus Interference

Some backup products and antivirus software interact poorly with active SQLite databases.

Potential issues include:

  • File locking
  • Snapshot inconsistencies
  • Partial file copies
  • Real-time scanning interruptions
  • Aggressive file monitoring

Modern backup solutions that support application-consistent snapshots are generally safer than copying active database files directly.


How to Diagnose the Problem

Proper diagnosis should always precede recovery.

Although the error message clearly indicates SQLite corruption, administrators should determine which database is affected and whether the underlying cause is storage-related before attempting repairs.

Check wazuh-db Logs

Begin by reviewing the Wazuh manager logs.

On most Linux installations:

sudo grep -i "malformed" /var/ossec/logs/ossec.log

Or search for SQLite-related errors:

sudo grep -Ei "sqlite|database|wazuh-db" /var/ossec/logs/ossec.log

You can also monitor new messages in real time:

sudo tail -f /var/ossec/logs/ossec.log

Look for:

  • database image malformed
  • SQLite errors
  • SQL query failures
  • Agent database names
  • Module names reporting failures

These messages often identify the affected agent or database.

Identify the Corrupted SQLite Database

Once you’ve confirmed corruption, determine which database is failing.

Most Wazuh agent databases reside beneath:

/var/ossec/queue/db/

List the available databases:

sudo ls -lh /var/ossec/queue/db/

Depending on your deployment, you’ll typically find one SQLite database per registered agent.

Knowing which database corresponds to which endpoint allows you to determine whether the corruption affects:

  • A single agent
  • Multiple agents
  • Shared Wazuh data
  • System-wide inventory

If only one database is damaged, recovery is generally much simpler than if multiple databases are corrupted simultaneously.

Verify Database Integrity Using SQLite

SQLite includes a built-in integrity checker.

Run:

sqlite3 /path/to/database.db "PRAGMA integrity_check;"

A healthy database returns:

ok

A corrupted database may return messages such as:

*** in database main ***
Page 421 is never used
Malformed B-Tree
Row missing from index
Database disk image is malformed

Minor index corruption may sometimes be repairable, whereas extensive page corruption often requires rebuilding the database from backups or allowing Wazuh to recreate it after the affected data has been removed.

Check System Logs for Storage Errors

If SQLite reports corruption, verify that the operating system is not reporting storage problems.

Useful commands include:

dmesg | grep -Ei "error|I/O|ext4|xfs|nvme|disk"
journalctl -k
journalctl -p err

Look for:

  • I/O errors
  • Read failures
  • Write failures
  • Filesystem corruption
  • Device resets
  • Storage controller errors

Storage-related kernel messages often explain why the SQLite database became corrupted in the first place.

Verify Available Disk Space

Ensure the server has adequate free space.

Check filesystem utilization:

df -h

Also verify inode usage:

df -i

Pay particular attention to:

  • Nearly full partitions
  • 100% disk usage
  • Exhausted inode counts
  • Rapid filesystem growth

Running out of either storage space or inodes can interrupt SQLite writes and contribute to database corruption.

Determine Whether Multiple Databases Are Affected

Finally, determine whether the problem is isolated or widespread.

For example, you can run integrity checks against multiple agent databases:

find /var/ossec/queue/db -name "*.db" -exec sqlite3 {} "PRAGMA integrity_check;" \;

If only one database reports corruption, recovery can usually focus on a single affected agent.

However, if many databases fail the integrity check, the root cause is more likely to be:

  • Filesystem corruption
  • Storage hardware failure
  • Faulty memory
  • An interrupted system-wide event
  • Backup or virtualization issues

Widespread corruption should always prompt a thorough investigation of the underlying infrastructure before rebuilding databases, otherwise newly created databases may become corrupted again shortly afterward.


How to Recover From a Malformed Database Image

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *