NationalSecurityAgency/ghidra · error · IOException

Data directory not initialized: run "bsim_ctl start" first

Error message

Data directory not initialized: run "bsim_ctl start" first

What it means

Thrown by BSimControlLaunchable.changeAuthCommand() when the BSim PostgreSQL data directory has not been initialized. The method expects a 'postgresql.conf' file inside the data directory, which is only created when 'bsim_ctl start' runs 'initdb' against that directory. The IOException signals that the configuration files needed to change authentication settings do not exist yet.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java:1273

	/**
	 * The data directory for a server (which must not be running) is reconfigured
	 * with new local and remote authentication options, and the port may be reconfigured as well.
	 * Database records are unaltered.
	 * The user submits "auth=..", "localAuth=..", and "port=.." options on the command line:
	 * among those submitted, any option that doesn't match the current configuration is changed.
	 * @throws IOException if the postgres installation cannot be found
	 * @throws InterruptedException if the postgres installation cannot be found
	 * @throws SAXException if the {@link #tuneConfig(File, File, File, File, File)} call fails
	 * @throws GeneralSecurityException if there is no Distinguished Name supplied
	 */
	private void changeAuthCommand()
			throws IOException, InterruptedException, SAXException, GeneralSecurityException {
		discoverPostgresInstall();
		File configFile = new File(dataDirectory, POSTGRES_CONFIGFILE);
		File hbaFile = new File(dataDirectory, POSTGRES_CONNECTFILE);
		if (!configFile.exists()) {
			throw new IOException("Data directory not initialized: run \"bsim_ctl start\" first");
		}
		int requestedLocalAuth = localAuthentication;
		int requestedHostAuth = hostAuthentication;
		int requestedPort = port;
		port = -1;
		recoverConfigurationParameters(configFile, hbaFile);
		if (isServerRunning()) {
			throw new IOException("Cannot modify settings on running server");
		}
		if ((!authConfigPresent || (requestedHostAuth == hostAuthentication &&
			requestedLocalAuth == localAuthentication)) &&
			(requestedPort == -1 || requestedPort == port)) {
			System.out.println("No changes to make");
			return;
		}

		File serverConfigFile = Application.getModuleDataFile("serverconfig.xml").getFile(false);
		File configCopy = new File(dataDirectory, POSTGRES_CONFIGFILE + ".orig");

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Run 'bsim_ctl start <datadir-path>' first to initialize the PostgreSQL data directory.
  2. Verify the datadir path is correct and that <datadir>/postgresql.conf exists.
  3. If the directory was never initialized, start fresh with 'bsim_ctl start' to generate it.

Example fix

# before (fails: datadir never initialized)
bsim_ctl changeauth /opt/bsim/newdir --auth password
# after (initialize first)
bsim_ctl start /opt/bsim/newdir --auth password
bsim_ctl changeauth /opt/bsim/newdir --auth password
Defensive patterns

Strategy: try-catch

Validate before calling

// Before invoking changeauth, confirm the data directory is initialized:
File conf = new File(dataDirectory, "postgresql.conf");
if (!conf.exists()) {
    throw new IllegalStateException("Run 'bsim_ctl start " + dataDirectory + "' first");
}

Try / catch

try {
    bsimControl.run(new String[]{"changeauth", dataDir, "--auth", "password"});
} catch (IOException e) {
    if (e.getMessage().contains("not initialized")) {
        // prompt operator to run 'bsim_ctl start' first
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Running 'bsim_ctl changeauth <datadir-path>' against a data directory that was never initialized (no postgresql.conf present), or pointing changeauth at a wrong/non-existent directory path.

Common situations: Operator runs changeauth before ever starting the server; pointing at a stale or accidentally-deleted data directory; copy-pasting the wrong datadir argument.

Related errors


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