dgraph-io/badger · critical

error opening table %s: %v %s

Error message

error opening table %s: %v
%s

What it means

When opening a DB, badger opens all manifest-listed tables concurrently in goroutines; any panic or error while opening a table is captured and returned as this wrapped error including the file name, panic value, and a stack trace. It indicates a corrupt or unreadable SSTable.

Source

Thrown at levels.go:124

		fname := table.NewFilename(fileID, db.opt.Dir)
		select {
		case <-tick.C:
			db.opt.Infof("%d tables out of %d opened in %s\n", numOpened.Load(),
				len(mf.Tables), time.Since(start).Round(time.Millisecond))
		default:
		}
		if err := throttle.Do(); err != nil {
			closeAllTables(tables)
			return nil, err
		}
		if fileID > maxFileID {
			maxFileID = fileID
		}
		go func(fname string, tf TableManifest) {
			var rerr error
			defer func() {
				if r := recover(); r != nil {
					rerr = fmt.Errorf("error opening table %s: %v\n%s", fname, r, debug.Stack())
				}
				throttle.Done(rerr)
				numOpened.Add(1)
			}()
			// tables is sized by opt.MaxLevels, and nothing upstream constrains
			// the level recorded in the manifest, so reject an out-of-range level
			// here rather than letting the append below panic.
			if int(tf.Level) >= len(tables) {
				rerr = fmt.Errorf(
					"manifest records table %s at level %d, but MaxLevels is %d",
					fname, tf.Level, len(tables))
				return
			}
			dk, err := db.registry.DataKey(tf.KeyID)
			if err != nil {
				rerr = y.Wrapf(err, "Error while reading datakey")
				return
			}

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Inspect and drop/repair the specific corrupt table reported in the error (badger's DropAll/repair tooling or badger info)
  2. Restore the table file from backup
  3. Verify encryption/DataKey registry matches the one used when the tables were written
  4. Ensure the DB directory is copied while the DB is closed

Example fix

// before
badger.Open(opts) // fails: error opening table 005.sst: checksum mismatch
// after
defOpts := badger.DefaultOptions("./data/badger")
defOpts.ReadOnly = true // open read-only to inspect/repair
// then remove or replace the corrupt table file listed in the error before normal open
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: pre-check files exist and are non-zero before open
for _, f := range manifestTables {
    fi, err := os.Stat(filepath.Join(dir, keyIDToFile(f)))
    if err != nil || fi.Size() == 0 { return fmt.Errorf("table missing/empty: %v", err) }
}

Try / catch

// Go
db, err := badger.Open(opts)
if err != nil {
    var stackHint = "error opening table"
    if strings.Contains(err.Error(), stackHint) {
        // parse fname from error, quarantine/restore that file, then retry
        return quarantineAndRetry(err)
    }
    return err
}

Prevention

When it happens

Trigger: A panic occurs while loading a table file (corrupt SSTable, truncated file, checksum failure, incompatible encryption/registry key, or out-of-range level in a patched build).

Common situations: Corrupted table files after a machine crash or power loss; copying the DB directory while badger was running; restoring files encrypted with a different key; mixing table files across badger versions.

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/7c7875eca29a434c. Report an issue: GitHub.