{"record":{"id":"924c33caa690eba5","repo":"NationalSecurityAgency/ghidra","slug":"could-not-start-postgres-server-process","errorCode":null,"errorMessage":"Could not start postgres server process","messagePattern":"Could not start 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":1025,"sourceCode":"\t\tdiscoverPostgresInstall();\n\t\tinitializeDataDirectory();\n\n\t\tif (localAuthentication == AUTHENTICATION_PKI && certParameter == null) {\n\t\t\tthrow new GeneralSecurityException(\n\t\t\t\t\"Path to certificate necessary to start server (--cert /path/to/cert)\");\n\t\t}\n\t\tFile logFile = new File(dataDirectory, \"logfile\");\n\t\tList<String> command = new ArrayList<String>();\n\t\tcommand.add(postgresControl.getAbsolutePath());\n\t\tcommand.add(\"start\");\n\t\tcommand.add(\"-w\");\n\t\tcommand.add(\"-D\");\n\t\tcommand.add(dataDirectory.getAbsolutePath());\n\t\tcommand.add(\"-l\");\n\t\tcommand.add(logFile.getAbsolutePath());\n\t\tint res = runCommand(null, command, loadLibraryVar, loadLibraryValue);\n\t\tif (res != 0) {\n\t\t\tthrow new IOException(\"Could not start postgres server process\");\n\t\t}\n\n\t\tSystem.out.println(\"Server started\");\n\t\tboolean extensionEnabled = true;\n\t\ttry {\n\t\t\tenableLSHExtension();\n\t\t}\n\t\tcatch (SQLException e) {\n\t\t\tSystem.out.println(e.getMessage());\n\t\t\textensionEnabled = false;\n\t\t}\n\t\tif (extensionEnabled) {\n\t\t\tSystem.out.println(\"BSim extension enabled\");\n\t\t}\n\t\telse {\n\t\t\tforceShutdown = true;\t\t\t// Force a shutdown, because extension isn't enabled\n\t\t\tstopCommand();\n\t\t}","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L1007-L1043","documentation":"Thrown by startCommand() when `pg_ctl start -w` returns non-zero, meaning PostgreSQL failed to start within the wait window. BSim reports only the aggregate result, not the postgres log detail; the real cause is in the data directory's `logfile`.","triggerScenarios":"The constructed `pg_ctl start -w -D <dataDir> -l logfile` command exits non-zero because postgres could not bind the port, load config, or pass startup checks.","commonSituations":"Port already in use (--port collision); corrupt postgresql.conf/pg_hba.conf from a failed tuneConfig; missing or wrong ssl certs (server.crt/server.key); insufficient shared memory; wrong postgres version; leftover postmaster.pid from a crash; LD_LIBRARY_PATH not set so libs won't load.","solutions":["Read `<dataDir>/logfile` for the exact postgres error.","Free the configured port or change --port.","Remove a stale `postmaster.pid` only if no postgres is actually running.","Regenerate server.crt/server.key if SSL startup fails.","Verify loadLibraryVar/loadLibraryValue and the discovered postgres install.","Increase resources / check dmesg for shared-memory limits."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight common startup blockers before invoking start.\nFile pid = new File(dataDir, \"postmaster.pid\");\nif (pid.isFile()) {\n    throw new IllegalStateException(\"Stale postmaster.pid present; server may already run or crashed: \" + pid);\n}","typeGuard":"public boolean portFree(int port) {\n    try (ServerSocket s = new ServerSocket(port)) { return true; }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    bsimControl.start(args);\n} catch (IOException e) {\n    if (\"Could not start postgres server process\".equals(e.getMessage())) {\n        String log = Files.readString(Path.of(dataDir, \"logfile\"));\n        throw new UserFacingException(\"pg_ctl start failed; postgres log:\\n\" + log, e);\n    }\n    throw e;\n}","preventionTips":["Always read <dataDir>/logfile on start failure rather than retrying.","Clear stale postmaster.pid only after confirming no live postgres.","Reserve the --port to avoid collisions.","Verify SSL certs (server.crt/server.key) and the postgres shared-library path."],"tags":["postgresql","process","startup","network","bsim","cli","environment"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}