{"record":{"id":"d9c1e84733f1f407","repo":"juicedata/juicefs","slug":"create-table-setting-counter-s","errorCode":null,"errorMessage":"create table setting, counter: %s","messagePattern":"create table setting, counter: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":580,"sourceCode":"\t\t_, err := s.Delete(&sliceRef{Id: id})\n\t\tif err == nil {\n\t\t\tm.genLog(Background(), s, time.Now().UnixNano(), \"DELETESLICE(%d,%d)\", id, size)\n\t\t}\n\t\treturn err\n\t})\n}\n\nfunc (m *dbMeta) syncTable(beans ...interface{}) error {\n\terr := m.db.Sync2(beans...)\n\tif err != nil && strings.Contains(err.Error(), \"Duplicate key\") {\n\t\terr = nil\n\t}\n\treturn err\n}\n\nfunc (m *dbMeta) syncAllTables() error {\n\tif err := m.syncTable(new(setting), new(counter)); err != nil {\n\t\treturn fmt.Errorf(\"create table setting, counter: %s\", err)\n\t}\n\tif err := m.syncTable(new(edge)); err != nil {\n\t\treturn fmt.Errorf(\"create table edge: %s\", err)\n\t}\n\tif err := m.syncTable(new(node), new(symlink), new(xattr)); err != nil {\n\t\treturn fmt.Errorf(\"create table node, symlink, xattr: %s\", err)\n\t}\n\tif err := m.syncTable(new(chunk), new(sliceRef), new(delslices)); err != nil {\n\t\treturn fmt.Errorf(\"create table chunk, chunk_ref, delslices: %s\", err)\n\t}\n\tif err := m.syncTable(new(session2), new(sustained), new(delfile)); err != nil {\n\t\treturn fmt.Errorf(\"create table session2, sustaind, delfile: %s\", err)\n\t}\n\tif err := m.syncTable(new(flock), new(plock), new(dirQuota), new(userGroupQuota)); err != nil {\n\t\treturn fmt.Errorf(\"create table flock, plock, dirQuota, userGroupQuota: %s\", err)\n\t}\n\tif err := m.syncTable(new(dirStats)); err != nil {\n\t\treturn fmt.Errorf(\"create table dirStats: %s\", err)","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L562-L598","documentation":"In syncAllTables (pkg/meta/sql.go), JuiceFS uses xorm Sync2 to create/auto-migrate the `setting` and `counter` tables. If that DDL fails, the error is wrapped as \"create table setting, counter: %s\". This is the first schema step of `doInit`, so it typically indicates the database user cannot create tables or the underlying DDL hit a driver/compatibility problem.","triggerScenarios":"Any command that initializes the SQL metadata engine (`juicefs format`, `juicefs mount`, `juicefs status`) when Sync2 on (setting, counter) fails: insufficient CREATE privileges, read-only database, disk-full on the DB host, or incompatible SQL dialect.","commonSituations":"DB user granted only SELECT/INSERT but not CREATE/ALTER; connecting to a managed DB where DDL is restricted; table prefix collides with an existing incompatible table of the same name; server out of disk space.","solutions":["Grant the database user CREATE and ALTER privileges on the target schema/database.","Check the wrapped inner error: read-only filesystem or 'access denied' indicates privilege/storage issues to fix on the DB side.","Verify no pre-existing table with the same (prefixed) name has an incompatible schema that Sync2 cannot migrate; drop or rename it after backing up.","Confirm the database server has free disk space and is writable.","Test manually with the same credentials: run a `CREATE TABLE` in a SQL client to confirm DDL is permitted."],"exampleFix":"// before: user lacks DDL rights\nCREATE USER 'jfs'@'%' IDENTIFIED BY '...';\nGRANT SELECT, INSERT ON juicefs.* TO 'jfs'@'%';\n\n// after: grant full DDL rights\nGRANT ALL PRIVILEGES ON juicefs.* TO 'jfs'@'%';","handlingStrategy":"validation","validationCode":"// Before initializing, verify the DB user can perform DDL\n// run with the same credentials as the meta URL:\n// MySQL:\n//   CREATE TABLE jfs__ddl_probe (id BIGINT PRIMARY KEY); DROP TABLE jfs__ddl_probe;\n// PostgreSQL:\n//   CREATE TABLE __ddl_probe (id BIGINT PRIMARY KEY); DROP TABLE __ddl_probe;\n// If either statement fails with 'access denied', fix grants before running juicefs format/mount.","typeGuard":null,"tryCatchPattern":"// Catch the wrapped schema error and fail fast with an actionable hint\nif err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"create table setting, counter\") {\n        return fmt.Errorf(\"metadata init failed: ensure DB user has CREATE/ALTER privileges: %w\", err)\n    }\n    return err\n}","preventionTips":["Grant ALL (or at least CREATE + ALTER + INDEX) on the metadata schema to the JuiceFS DB role at provisioning time.","Keep the DB user dedicated to JuiceFS so rights are not accidentally revoked.","Test DDL capability after any DB permission or managed-policy change.","Use a consistent tablePrefix and avoid reusing schemas that contain foreign tables."],"tags":["database","schema-migration","ddl","permissions"],"backgroundTag":"database-write-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}