{"record":{"id":"365bf3153cce9957","repo":"NationalSecurityAgency/ghidra","slug":"trying-to-insert-on-read-only-database","errorCode":null,"errorMessage":"Trying to insert on read-only database","messagePattern":"Trying to insert on read-only database","errorType":"validation","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java","lineNumber":1937,"sourceCode":"\t\t\tresponse.result.add(simres);\n\n\t\t\tsimres.transfer(response.manage, true);\n\t\t}\n\n\t\treturn vecToResultMap.size();\n\t}\n\n\t/**\n\t * Entry point for the InsertRequest command\n\t * @param query the query to execute\n\t * @throws LSHException if trying to insert into a read-only database\n\t * @throws SQLException if there is an error issuing the query\n\t * @throws DatabaseNonFatalException if there are duplicate executables and/or functions\n\t */\n\tprivate void fdbDatabaseInsert(InsertRequest query)\n\t\t\tthrows LSHException, SQLException, DatabaseNonFatalException {\n\t\tif (info.readonly) {\n\t\t\tthrow new LSHException(\"Trying to insert on read-only database\");\n\t\t}\n\t\tif (FunctionDatabase.checkSettingsForInsert(query.manage, info)) { // Check if settings are valid and is this is first insert\n\t\t\tinfo.major = query.manage.getMajorVersion();\n\t\t\tinfo.minor = query.manage.getMinorVersion();\n\t\t\tinfo.settings = query.manage.getSettings();\n\t\t\tkeyValueTable.writeBasicInfo(info); // Save off the settings associated with this first insert\n\t\t}\n\t\tResponseInsert response = query.insertresponse;\n\t\tif ((query.repo_override != null) && (query.repo_override.length() != 0)) {\n\t\t\tquery.manage.overrideRepository(query.repo_override, query.path_override);\n\t\t}\n\t\tinsert(query.manage);\n\t\tresponse.numexe = query.manage.getExecutableRecordSet().size();\n\t\tresponse.numfunc = query.manage.numFunctions();\n\t}\n\n\t/**\n\t * Entry point for the QueryInfo command","sourceCodeStart":1919,"sourceCodeEnd":1955,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java#L1919-L1955","documentation":"`fdbDatabaseInsert` checks `info.readonly` at entry. If the connection was opened read-only, any insert is rejected with LSHException before any work begins. Read-only mode is intended for query-only clients; writes are refused outright.","triggerScenarios":"Opening a BSim DB connection in read-only mode (e.g. for similarity queries) and then dispatching an InsertRequest against it.","commonSituations":"Misconfigured connection URL/flags; reusing a query-only client for ingest; a DB role restricted to read; a deliberate read-only replica used accidentally for writes.","solutions":["Open the connection without the read-only flag.","Use a separate, read-write connection/client for insert operations.","Verify the connection's readonly setting before dispatching InsertRequest."],"exampleFix":"// before: readonly connection used for ingest\ninfo.readonly = true;  db.insert(query);   // throws\n// after: writable connection for writes\ninfo.readonly = false; db.insert(query);","handlingStrategy":"validation","validationCode":"// Guard inserts against a read-only connection.\nif (db.getInfo().readonly) {\n    throw new IllegalStateException(\n        \"Cannot insert on a read-only connection; open read-write\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    db.insert(query);\n} catch (LSHException e) {\n    if (e.getMessage().equals(\"Trying to insert on read-only database\")) {\n        // operator must use a read-write connection -- do not retry as-is\n        throw new ConnectionModeException(\"Reopen the DB read-write for inserts\", e);\n    }\n    throw e;\n}","preventionTips":["Use distinct read-only (query) and read-write (ingest) clients.","Verify info.readonly before dispatching InsertRequest.","Fail fast on mode mismatch rather than discovering it mid-ingest."],"tags":["config","database","insert","readonly","bsim"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}