1Panel-dev/1Panel · error

init db dir failed, err: %v

Error message

init db dir failed, err: %v

What it means

Error "init db dir failed, err: %v" thrown in 1Panel-dev/1Panel.

Source

Thrown at core/utils/common/sqlite.go:17

package common

import (
	"fmt"
	"log"
	"os"
	"path"
	"time"

	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func LoadDBConnByPath(fullPath, dbName string) *gorm.DB {
	if _, err := CreateDirWhenNotExist(true, path.Dir(fullPath)); err != nil {
		panic(fmt.Errorf("init db dir failed, err: %v", err))
	}
	if _, err := os.Stat(fullPath); err != nil {
		f, err := os.Create(fullPath)
		if err != nil {
			panic(fmt.Errorf("init %s db file failed, err: %v", dbName, err))
		}
		_ = f.Close()
	}

	db, err := GetDBWithPath(fullPath)
	if err != nil {
		panic(err)
	}
	return db
}

func CloseDB(db *gorm.DB) {
	sqlDB, err := db.DB()

View on GitHub (pinned to 5ac7c80881)

Solutions

  1. Check that the parent directory of the database path exists and that the 1Panel core process has write permission to create it.
  2. Verify the filesystem is not full (`df -h`) and not mounted read-only (`mount | grep <dir>`).
  3. Ensure the configured install/base directory is valid and on a local filesystem that supports directory creation.
  4. Create the directory manually with correct ownership (e.g. `mkdir -p <dir> && chown <user>:<group> <dir>`) and restart the service.

Example fix

mkdir -p /opt/1panel/db && chown -R root:root /opt/1panel/db && systemctl restart 1panel

When it happens

Trigger: Thrown at core/utils/common/sqlite.go:17 when the library encounters an invalid state.

Common situations: Occurs when LoadDBConnByPath cannot create the parent directory for the sqlite database file (missing permissions, read-only filesystem, or invalid path). The process panics immediately. Defense: ensure the data directory exists and is writable by the service account before startup; check disk space and mount status; do not retry in a loop because the panic indicates a persistent environment problem.


AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15). Data as JSON: /api/errors/0ba79d2151892150. Report an issue: GitHub.