{"record":{"id":"841b4f8e42b03ddf","repo":"hyperledger/fabric","slug":"database-name-is-illegal-cannot-be-longer-than-d","errorCode":null,"errorMessage":"database name is illegal, cannot be longer than %d","messagePattern":"database name is illegal, cannot be longer than (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go","lineNumber":284,"sourceCode":"}\n\n// mapAndValidateDatabaseName checks to see if the database name contains illegal characters\n// CouchDB Rules: Only lowercase characters (a-z), digits (0-9), and any of the characters\n// _, $, (, ), +, -, and / are allowed. Must begin with a letter.\n//\n// Restrictions have already been applied to the database name from Orderer based on\n// restrictions required by Kafka and couchDB (except a '.' char). The databaseName\n// passed in here is expected to follow `[a-z][a-z0-9.$_()+-]*` pattern.\n//\n// This validation will simply check whether the database name matches the above pattern and will replace\n// all occurrence of '.' by '$'. This will not cause collisions in the transformed named\nfunc mapAndValidateDatabaseName(databaseName string) (string, error) {\n\t// test Length\n\tif len(databaseName) <= 0 {\n\t\treturn \"\", errors.Errorf(\"database name is illegal, cannot be empty\")\n\t}\n\tif len(databaseName) > maxLength {\n\t\treturn \"\", errors.Errorf(\"database name is illegal, cannot be longer than %d\", maxLength)\n\t}\n\tre, err := regexp.Compile(expectedDatabaseNamePattern)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"error compiling regexp: %s\", expectedDatabaseNamePattern)\n\t}\n\tmatched := re.FindString(databaseName)\n\tif len(matched) != len(databaseName) {\n\t\treturn \"\", errors.Errorf(\"databaseName '%s' does not match pattern '%s'\", databaseName, expectedDatabaseNamePattern)\n\t}\n\t// replace all '.' to '$'. The databaseName passed in will never contain an '$'.\n\t// So, this translation will not cause collisions\n\tdatabaseName = strings.Replace(databaseName, \".\", \"$\", -1)\n\treturn databaseName, nil\n}\n\n// escapeUpperCase replaces every upper case letter with a '$' and the respective\n// lower-case letter\nfunc escapeUpperCase(dbName string) string {","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go#L266-L302","documentation":"mapAndValidateDatabaseName enforces a maximum database name length (maxLength). CouchDB itself limits database names, so the library rejects names longer than this limit before mapping. This error fires when the provided name exceeds maxLength bytes.","triggerScenarios":"createCouchDatabase invoked with a databaseName whose length exceeds maxLength — typically a very long chaincode name or channel name producing an oversized namespace-derived database name.","commonSituations":"Chaincode instantiated with an extremely long name; channel IDs at/near the maximum combined with long chaincode names; earlier Fabric versions allowed longer names and data was migrated.","solutions":["Shorten the channel name or chaincode name so the derived database name fits within maxLength.","Check maxLength in couchdbutil.go and keep identifiers well under the limit when designing names.","If the name cannot change, use LevelDB as the state database, which has no such name restriction."],"exampleFix":"// before: name too long\nchannelName := \"averyveryverylongchannelnameexceedinglimits...\"\n// after: keep identifiers short\nchannelName := \"mychannel\"","handlingStrategy":"validation","validationCode":"const maxLength = 249 // as in couchdbutil.go\nif len(dbName) > maxLength { /* shorten channel/chaincode name before opening ledger */ }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"cannot be longer than\") {\n        // shorten identifiers or switch to goleveldb state database\n    }\n    return err\n}","preventionTips":["Keep channel and chaincode names short when designing the network.","Remember the derived db name adds prefixes; budget for maxLength.","Use LevelDB if long identifiers are unavoidable."],"tags":["couchdb","validation","database-name","length-limit"],"backgroundTag":"invalid-database-name","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}