{"record":{"id":"7524d35ef5644d07","repo":"NationalSecurityAgency/ghidra","slug":"error-getting-postgres-server-status","errorCode":null,"errorMessage":"Error getting postgres server status","messagePattern":"Error getting postgres server status","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":1090,"sourceCode":"\t * @throws IOException if server status can not be retrieved\n\t * @throws InterruptedException if the status command is interrupted\n\t */\n\tprivate void statusCommand() throws IOException, InterruptedException {\n\t\tdiscoverPostgresInstall();\n\t\tList<String> command = new ArrayList<String>();\n\t\tcommand.add(postgresControl.getAbsolutePath());\n\t\tcommand.add(\"status\");\n\t\tcommand.add(\"-D\");\n\t\tcommand.add(dataDirectory.getAbsolutePath());\n\t\tint res = runCommand(null, command, loadLibraryVar, loadLibraryValue);\n\t\tif (res == 0) {\n\t\t\tSystem.out.println(\"Server running\");\n\t\t}\n\t\telse if (res == 3) {\n\t\t\tSystem.out.println(\"Server down\");\n\t\t}\n\t\telse {\n\t\t\tthrow new IOException(\"Error getting postgres server status\");\n\t\t}\n\t}\n\n\t/**\n\t * Trigger a server running on the local host to rescan its identity file to pickup\n\t * any changes to the user mapping\n\t * @throws IOException if creating a new user fails\n\t * @throws InterruptedException if the reload command is interrupted\n\t */\n\tprivate void reloadIdent() throws IOException, InterruptedException {\n\t\tList<String> command = new ArrayList<String>();\n\t\tcommand.add(postgresControl.getAbsolutePath());\n\t\tcommand.add(\"reload\");\n\t\tcommand.add(\"-D\");\n\t\tcommand.add(dataDirectory.getAbsolutePath());\n\t\tcommand.add(\"-s\");\n\t\tint res = runCommand(null, command, loadLibraryVar, loadLibraryValue);\n\t\tif (res != 0) {","sourceCodeStart":1072,"sourceCodeEnd":1108,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L1072-L1108","documentation":"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.","triggerScenarios":"Running `bsim_ctl status <dataDir>` where pg_ctl returns an unexpected exit code (not 0/3).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File d = new File(dataDir);\nif (!d.isDirectory() || !d.canRead() || !new File(d, \"PG_VERSION\").isFile()) {\n    throw new IllegalStateException(\"Not a readable postgres data directory: \" + d);\n}","typeGuard":"public boolean isReadableClusterDir(File d) {\n    return d != null && d.isDirectory() && d.canRead()\n        && new File(d, \"PG_VERSION\").isFile();\n}","tryCatchPattern":"try {\n    bsimControl.status(args);\n} catch (IOException e) {\n    if (\"Error getting postgres server status\".equals(e.getMessage())) {\n        // fall back to a direct pg_ctl status and report its raw output\n        throw new UserFacingException(\"pg_ctl status returned unexpected code\", e);\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["postgresql","status","process","bsim","cli"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}