{"record":{"id":"c8c78614b5f869a2","repo":"NationalSecurityAgency/ghidra","slug":"error-shutting-down-postgres-server-process","errorCode":null,"errorMessage":"Error shutting down postgres server process","messagePattern":"Error shutting down postgres server process","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":1065,"sourceCode":"\t * Stop the running PostgreSQL processes on the local host. No authentication is required to shutdown\n\t * the server.  User must be the process owner.\n\t * @throws IOException if postgres cannot be discovered or stopped\n\t * @throws InterruptedException if the stop command is interrupted\n\t */\n\tprivate void stopCommand() throws IOException, InterruptedException {\n\t\tdiscoverPostgresInstall();\n\t\tList<String> command = new ArrayList<String>();\n\t\tcommand.add(postgresControl.getAbsolutePath());\n\t\tcommand.add(\"stop\");\n\t\tcommand.add(\"-D\");\n\t\tcommand.add(dataDirectory.getAbsolutePath());\n\t\tif (forceShutdown) {\n\t\t\tcommand.add(\"-m\");\n\t\t\tcommand.add(\"fast\");\t\t// Does not wait for clients to disconnect, all active transactions rolled back\n\t\t}\n\t\tint res = runCommand(null, command, loadLibraryVar, loadLibraryValue);\n\t\tif (res != 0) {\n\t\t\tthrow new IOException(\"Error shutting down postgres server process\");\n\t\t}\n\t\tSystem.out.println(\"Server shutdown complete\");\n\t}\n\n\t/**\n\t * Retrieve the status of a PostgreSQL server.\n\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) {","sourceCodeStart":1047,"sourceCodeEnd":1083,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L1047-L1083","documentation":"Thrown by stopCommand() when `pg_ctl stop [-m fast]` returns non-zero. BSim treats a non-zero exit as a failure to shut the server down; the postgres error detail is not surfaced.","triggerScenarios":"Running `bsim_ctl stop <dataDir>` (optionally `--force`) and the postgres stop command fails.","commonSituations":"Server already stopped or not running; stale postmaster.pid; insufficient privileges to signal the postmaster; data directory path mismatch; shutdown blocked and -m fast still timed out.","solutions":["Check whether postgres is actually running: `bsim_ctl status <dataDir>` or `pg_ctl status`.","Remove a stale postmaster.pid if no process holds the port.","Run bsim_ctl as the same OS user that owns the data directory.","Retry with `--force` (maps to `pg_ctl stop -m fast`).","Inspect postgres logs if the process exists but won't stop."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only attempt stop if status indicates running.\nint rc = runPgCtl(\"status\", dataDir);\nif (rc == 3) {\n    return; // already down; skip stop to avoid the error\n}","typeGuard":"public boolean serverLikelyRunning(File dataDir) {\n    return new File(dataDir, \"postmaster.pid\").isFile();\n}","tryCatchPattern":"try {\n    bsimControl.stop(args);\n} catch (IOException e) {\n    if (\"Error shutting down postgres server process\".equals(e.getMessage())) {\n        // check status; if already down, treat as success; else escalate.\n        int rc = runPgCtl(\"status\", dataDir);\n        if (rc == 3) return;\n        throw new UserFacingException(\"pg_ctl stop failed; server still up\", e);\n    }\n    throw e;\n}","preventionTips":["Check status before stop to avoid failing on an already-stopped server.","Run bsim_ctl as the data-directory owner.","Use --force (-m fast) when a graceful stop hangs."],"tags":["postgresql","process","shutdown","bsim","cli"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}