{"record":{"id":"9c92d5e99c8c0e9f","repo":"NationalSecurityAgency/ghidra","slug":"could-not-create-database","errorCode":null,"errorMessage":"Could not create database: ","messagePattern":"Could not create database: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"critical","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java","lineNumber":434,"sourceCode":"\t\t\t\tcommit = true;\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tendTransaction(commit);\n\t\t\t}\n\n\t\t\texeCategoryTable.create(st);\n\t\t\texeTable.create(st);\n\t\t\tdescTable.create(st);\n\n\t\t\tif (trackcallgraph) {\n\t\t\t\tcallgraphTable.create(st);\n\t\t\t}\n\n\t\t\tinstallWeights(db, config.weightfactory);\n\t\t\tinstallIDFLookup(db, config.idflookup);\n\t\t}\n\t\tcatch (final SQLException err) {\n\t\t\tthrow new SQLException(\"Could not create database: \" + err.getMessage());\n\t\t}\n\t}\n\n\t/**\n\t * Drop this database\n\t * @throws SQLException if a database error occured\n\t */\n\tabstract protected void dropDatabase() throws SQLException;\n\n\tprotected void setConnectionOnTables(Connection db) {\n\n\t\tweightTable.setConnection(db);\n\t\tidfLookupTable.setConnection(db);\n\n\t\tarchtable.setConnection(db);\n\t\tcompilertable.setConnection(db);\n\t\trepositorytable.setConnection(db);\n\t\tpathtable.setConnection(db);","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java#L416-L452","documentation":"During BSim database creation, several DDL statements build the core tables (exeCategory, exe, desc, callgraph when tracked) plus install weights and IDF lookups. Any SQLException from these steps is caught and re-wrapped into a single `new SQLException(\"Could not create database: \" + err.getMessage())`. The original message text is preserved, but the SQL state and cause chain are flattened into the string, which can hamper root-cause analysis.","triggerScenarios":"Calling the database-create path when the DB role lacks CREATE TABLE privileges, target tables already exist with an incompatible shape, the connection drops mid-DDL, or disk/quota is exhausted. Any of these surfaces as the wrapped message.","commonSituations":"First-time setup with an under-privileged role; pointing BSim at a database name that already holds unrelated or older-schema tables; H2-vs-PostgreSQL driver mismatch; wrong JDBC URL; restoring onto a DB with leftover objects.","solutions":["Read the appended original message after 'Could not create database:' for the true SQL error (privilege, duplicate object, etc.).","Verify the DB user has CREATE on the target database and that the schema is empty or pre-seeded correctly.","Drop conflicting tables or point at a fresh, dedicated database.","Confirm the JDBC URL and driver match the configured BSim flavor."],"exampleFix":"# before: targeting a populated / under-privileged db\njdbc:postgresql://host/already_used_db\n# after: fresh dedicated db with granted privileges\njdbc:postgresql://host/fresh_bsim_db   # role has CREATE","handlingStrategy":"try-catch","validationCode":"// Before createDatabase: verify role can create tables and schema is clean.\ntry (Connection c = ds.getConnection(); Statement s = c.createStatement()) {\n    ResultSet rs = s.executeQuery(\n        \"SELECT has_database_privilege(current_database(),'CREATE')\");\n    rs.next();\n    if (!rs.getBoolean(1)) throw new IllegalStateException(\"role lacks CREATE privilege\");\n    // ensure no conflicting tables already exist\n    rs = s.executeQuery(\"SELECT count(*) FROM information_schema.tables \" +\n        \"WHERE table_schema='public'\");\n    rs.next();\n    if (rs.getInt(1) > 0) throw new IllegalStateException(\"schema not empty\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    db.createDatabase();\n} catch (SQLException e) {\n    // the wrapped message carries the root SQL error text\n    String root = e.getMessage().substring(\"Could not create database: \".length());\n    log.error(\"DB creation failed, root cause: {}\", root);\n    throw e; // abort setup; do not retry unchanged\n}","preventionTips":["Provision a dedicated, empty database for each BSim instance.","Grant the connecting role CREATE (and CONNECT) privileges before setup.","Never point setup at a database that already holds unrelated tables.","Confirm the JDBC URL/driver match the configured BSim flavor."],"tags":["database","setup","ddl","postgres","bsim","initialization"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}