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
- Confirm the data directory path is correct and readable.
- Run as the user owning the data directory.
- Check the pg_ctl version matches the cluster version.
- 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
- Confirm the data dir is a real cluster (has PG_VERSION) before status.
- Run as the directory owner to avoid permission-induced odd exit codes.
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
- Error initializing postgres database
- Could not start postgres server process
- Error shutting down postgres server process
- Error creating new user
- PKI authentication requested, but certificate authority file
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/7524d35ef5644d07.
Report an issue: GitHub.