NationalSecurityAgency/ghidra · error · SQLException

attempted to drop non-BSim database

Error message

attempted to drop non-BSim database

What it means

Thrown by PostgresFunctionDatabase.dropDatabase() as a safety guard. Before issuing DROP DATABASE, the code queries the database schema and spot-checks for three core BSim tables that always exist in a valid BSim database: keyvaluetable, desctable, and weighttable. If any is missing, the drop is refused to prevent accidental destruction of a non-BSim database.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java:288

				}
			}

			// Connect to database and examine schema
			HashSet<String> tableNames = new HashSet<>();
			postgresDs.initializeFrom(defaultDs);
			try (Connection c = initConnection(); Statement st = c.createStatement()) {
				try (ResultSet rs = st.executeQuery(
					"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name")) {
					while (rs.next()) {
						tableNames.add(rs.getString(1));
					}
				}
			}

			// Spot check for a few BSim table names that always exist
			if (!tableNames.contains("keyvaluetable") || !tableNames.contains("desctable") ||
				!tableNames.contains("weighttable")) {
				throw new SQLException("attempted to drop non-BSim database");
			}

			postgresDs.dispose(); // disconnect before dropping database

			Msg.info(this, "Dropping BSim postgresql database: " + serverInfo);
			sb = new StringBuilder("DROP DATABASE ");
			Utils.escapeIdentifier(sb, serverInfo.getDBName());
			defaultSt.executeUpdate(sb.toString());
		}
		finally {
			// ensure 
			postgresDs.initializeFrom(defaultDs);
		}
	}

	/**
	 * 
	 * @throws SQLException if there is a problem creating or executing the query

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Verify the BSimServerInfo database name is correct and points to the intended BSim database.
  2. If the database is partially created from a failed createDatabase, manually drop it via psql before retrying.
  3. Confirm keyvaluetable, desctable, and weighttable all exist in the target database before attempting the programmatic drop.

Example fix

// before — wrong db name in config
BSimServerInfo info = new BSimServerInfo(DBType.postgres, ...
    "postgres"); // default db, not a BSim db
db.dropDatabase(); // throws "attempted to drop non-BSim database"

// after — correct BSim db name
BSimServerInfo info = new BSimServerInfo(DBType.postgres, ...
    "my_bsim_db"); // contains keyvaluetable etc.
db.dropDatabase();
Defensive patterns

Strategy: validation

Validate before calling

// Verify the target database is a valid BSim database before dropping
Set<String> required = Set.of("keyvaluetable", "desctable", "weighttable");
try (Connection c = dbConnection;
     Statement st = c.createStatement();
     ResultSet rs = st.executeQuery(
         "SELECT table_name FROM information_schema.tables WHERE table_schema='public'")) {
    Set<String> tables = new HashSet<>();
    while (rs.next()) tables.add(rs.getString(1));
    if (!tables.containsAll(required)) {
        throw new IllegalStateException("Not a BSim database; aborting drop");
    }
}

Try / catch

try {
    db.dropDatabase();
} catch (SQLException e) {
    if (e.getMessage().contains("non-BSim database")) {
        // wrong database; verify the BSimServerInfo db name and correct config
        throw e;
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling dropDatabase() on a PostgreSQL database that does not contain all three required BSim core tables. This happens when the target database was never properly initialized as a BSim database, was partially created, or is a completely unrelated database that happens to be targeted by misconfiguration.

Common situations: The server info / connection string points at the wrong database (e.g. a default 'postgres' database or a user's personal database). A previous createDatabase failed midway, leaving an incomplete schema. The database name was mistyped in configuration.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/0fe31501c72e4710. Report an issue: GitHub.