{"record":{"id":"b6ede7146ab96bf7","repo":"paperclipai/paperclip","slug":"embedded-postgresql-already-running-reusing-exist","errorCode":null,"errorMessage":"Embedded PostgreSQL already running; reusing existing process (pid=${runningPid}, port=${port})","messagePattern":"Embedded PostgreSQL already running; reusing existing process \\(pid=(.+?), port=(.+?)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/index.ts","lineNumber":504,"sourceCode":"    const clusterAlreadyInitialized = existsSync(clusterVersionFile);\n    const postmasterPidFile = resolve(dataDir, \"postmaster.pid\");\n    const isPidRunning = (pid: number): boolean => {\n      try {\n        process.kill(pid, 0);\n        return true;\n      } catch {\n        return false;\n      }\n    };\n  \n    const getRunningPid = (): number | null => {\n      if (!existsSync(postmasterPidFile)) return null;\n      try {\n        const pidLine = readFileSync(postmasterPidFile, \"utf8\").split(\"\\n\")[0]?.trim();\n        const pid = Number(pidLine);\n        if (!Number.isInteger(pid) || pid <= 0) return null;\n        if (!isPidRunning(pid)) return null;\n        return pid;\n      } catch {\n        return null;\n      }\n    };\n  \n    const runningPid = getRunningPid();\n    if (runningPid) {\n      logger.warn(`Embedded PostgreSQL already running; reusing existing process (pid=${runningPid}, port=${port})`);\n    } else {\n      const configuredAdminConnectionString = `postgres://paperclip:paperclip@127.0.0.1:${configuredPort}/postgres`;\n      try {\n        const actualDataDir = await getPostgresDataDirectory(configuredAdminConnectionString);\n        if (\n          typeof actualDataDir !== \"string\" ||\n          resolve(actualDataDir) !== resolve(dataDir)\n        ) {\n          throw new Error(\"reachable postgres does not use the expected embedded data directory\");\n        }","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/index.ts#L486-L522","documentation":"Startup embedded-Postgres bootstrap found a live postmaster pid in the data dir whose pid is still running; instead of starting a second instance it reuses the existing process (warn log with pid and port).","triggerScenarios":"Thrown at server/src/index.ts:431 when the library encounters an invalid state.","commonSituations":"Logged at startup when the embedded PostgreSQL pid file points to a live process, so the existing instance is reused instead of starting a new one.","solutions":["Informational only; no action needed. The server reused the already-running embedded PostgreSQL process.","If you expected a fresh database, stop the existing embedded PostgreSQL process (by pid) before restarting."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}