NationalSecurityAgency/ghidra · error · IOException

Error getting postgres server status

Error message

Error getting postgres server status

What it means

Thrown by statusCommand() when `pg_ctl status` returns an exit code other than 0 (running) or 3 (down). Exit 0 and 3 are the documented healthy outcomes; any other code indicates pg_ctl itself had a problem querying the server state.

Source

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

	 * @throws IOException if server status can not be retrieved
	 * @throws InterruptedException if the status command is interrupted
	 */
	private void statusCommand() throws IOException, InterruptedException {
		discoverPostgresInstall();
		List<String> command = new ArrayList<String>();
		command.add(postgresControl.getAbsolutePath());
		command.add("status");
		command.add("-D");
		command.add(dataDirectory.getAbsolutePath());
		int res = runCommand(null, command, loadLibraryVar, loadLibraryValue);
		if (res == 0) {
			System.out.println("Server running");
		}
		else if (res == 3) {
			System.out.println("Server down");
		}
		else {
			throw new IOException("Error getting postgres server status");
		}
	}

	/**
	 * Trigger a server running on the local host to rescan its identity file to pickup
	 * any changes to the user mapping
	 * @throws IOException if creating a new user fails
	 * @throws InterruptedException if the reload command is interrupted
	 */
	private void reloadIdent() throws IOException, InterruptedException {
		List<String> command = new ArrayList<String>();
		command.add(postgresControl.getAbsolutePath());
		command.add("reload");
		command.add("-D");
		command.add(dataDirectory.getAbsolutePath());
		command.add("-s");
		int res = runCommand(null, command, loadLibraryVar, loadLibraryValue);
		if (res != 0) {

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Confirm the data directory path is correct and readable.
  2. Run as the user owning the data directory.
  3. Check the pg_ctl version matches the cluster version.
  4. Run `pg_ctl status -D <dataDir>` directly to see the raw exit reason.
Defensive patterns

Strategy: try-catch

Validate before calling

File d = new File(dataDir);
if (!d.isDirectory() || !d.canRead() || !new File(d, "PG_VERSION").isFile()) {
    throw new IllegalStateException("Not a readable postgres data directory: " + d);
}

Type guard

public boolean isReadableClusterDir(File d) {
    return d != null && d.isDirectory() && d.canRead()
        && new File(d, "PG_VERSION").isFile();
}

Try / catch

try {
    bsimControl.status(args);
} catch (IOException e) {
    if ("Error getting postgres server status".equals(e.getMessage())) {
        // fall back to a direct pg_ctl status and report its raw output
        throw new UserFacingException("pg_ctl status returned unexpected code", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Running `bsim_ctl status <dataDir>` where pg_ctl returns an unexpected exit code (not 0/3).

Common situations: Permission denied reading the data directory or postmaster.pid; data directory missing/corrupt; pg_ctl version mismatch; the directory is not a valid postgres cluster.

Related errors


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