{"record":{"id":"ad83f77415e9fece","repo":"NationalSecurityAgency/ghidra","slug":"could-not-create-database-ad83f7","errorCode":null,"errorMessage":"Could not create database: ","messagePattern":"Could not create database: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java","lineNumber":239,"sourceCode":"\t\t\t\tst.executeUpdate(\"GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO PUBLIC\");\n\t\t\t\tst.executeUpdate(\"GRANT USAGE ON ALL SEQUENCES IN SCHEMA PUBLIC TO PUBLIC\");\n\n\t\t\t\tserverLoadWeights(db);\n\n\t\t\t\t// Tell server to do asynchronous commits. This speeds up large\n\t\t\t\t// ingests with a (slight) danger of\n\t\t\t\t// losing the most recent commits if the server crashes (NOTE:\n\t\t\t\t// database integrity should still be recoverable)\n\t\t\t\tif (asynchronous) {\n\t\t\t\t\tst.executeUpdate(\"SET SESSION synchronous_commit TO OFF\");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tst.executeUpdate(\"SET SESSION synchronous_commit to ON\");\n\t\t\t\t}\n\t\t\t}\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@Override\n\tprotected void dropDatabase() throws SQLException {\n\n\t\tif (getStatus() == Status.Busy || postgresDs.getActiveConnections() != 0) {\n\t\t\tthrow new SQLException(\"database in use\");\n\t\t}\n\n\t\tBSimServerInfo serverInfo = postgresDs.getServerInfo();\n\t\tBSimServerInfo defaultServerInfo =\n\t\t\tnew BSimServerInfo(DBType.postgres, serverInfo.getUserInfo(),\n\t\t\t\tserverInfo.getServerName(), serverInfo.getPort(), DEFAULT_DATABASE_NAME);\n\n\t\tBSimPostgresDataSource defaultDs =\n\t\t\tBSimPostgresDBConnectionManager.getDataSource(defaultServerInfo);\n\t\tif (getStatus() == Status.Ready) {","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java#L221-L257","documentation":"Thrown by PostgresFunctionDatabase.createDatabase() wrapping any SQLException during the multi-step database creation: creating the lshvector extension, the vectable and its GIN index, the vector stored functions, GRANT statements, weight loading, or setting synchronous_commit. The original SQLException message is appended for diagnostics.","triggerScenarios":"Calling createDatabase(config) on a PostgresFunctionDatabase when any SQL step fails — most commonly the CREATE EXTENSION lshvector fails because the extension is not installed on the PostgreSQL server, or table/index creation fails due to insufficient privileges.","commonSituations":"The PostgreSQL server does not have the BSim lshvector extension installed. The connecting user lacks CREATEDB or CREATE EXTENSION privileges. A table or index name already exists from a prior partial create. PostgreSQL version incompatibility with the extension.","solutions":["Install the BSim PostgreSQL extension (lshvector) on the target server before calling createDatabase.","Ensure the connecting user has CREATEDB and CREATE EXTENSION privileges.","Inspect the wrapped SQLException message to identify the exact failing SQL statement.","If a partial create left orphaned tables, manually drop them or the database before retrying."],"exampleFix":"// before\ndb.createDatabase(config); // throws \"Could not create database: extension \\\"lshvector\\\" does not exist\"\n\n// after — install extension on the server first\n// (run on the PostgreSQL host, once)\n//   CREATE EXTENSION lshvector;\n// then retry\ndb.createDatabase(config);","handlingStrategy":"validation","validationCode":"// Verify the lshvector extension is installed before createDatabase\ntry (Connection c = dataSource.getConnection();\n     Statement st = c.createStatement();\n     ResultSet rs = st.executeQuery(\n         \"SELECT 1 FROM pg_extension WHERE extname = 'lshvector'\")) {\n    if (!rs.next()) {\n        throw new IllegalStateException(\"lshvector extension not installed on server\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    db.createDatabase(config);\n} catch (SQLException e) {\n    if (e.getMessage().startsWith(\"Could not create database\")) {\n        // inspect root cause; install extension, fix privileges, clean partial tables\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Install the lshvector extension on the PostgreSQL server before createDatabase.","Ensure the connecting user has CREATEDB and CREATE EXTENSION privileges.","Clean up partially-created tables before retrying a failed create."],"tags":["bsim","ghidra","postgresql","database","setup","permissions"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}