paperclipai/paperclip · error

Embedded PostgreSQL already running; reusing existing proces

Error message

Embedded PostgreSQL already running; reusing existing process (pid=${runningPid}, port=${port})

What it means

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).

Source

Thrown at server/src/index.ts:504

    const clusterAlreadyInitialized = existsSync(clusterVersionFile);
    const postmasterPidFile = resolve(dataDir, "postmaster.pid");
    const isPidRunning = (pid: number): boolean => {
      try {
        process.kill(pid, 0);
        return true;
      } catch {
        return false;
      }
    };
  
    const getRunningPid = (): number | null => {
      if (!existsSync(postmasterPidFile)) return null;
      try {
        const pidLine = readFileSync(postmasterPidFile, "utf8").split("\n")[0]?.trim();
        const pid = Number(pidLine);
        if (!Number.isInteger(pid) || pid <= 0) return null;
        if (!isPidRunning(pid)) return null;
        return pid;
      } catch {
        return null;
      }
    };
  
    const runningPid = getRunningPid();
    if (runningPid) {
      logger.warn(`Embedded PostgreSQL already running; reusing existing process (pid=${runningPid}, port=${port})`);
    } else {
      const configuredAdminConnectionString = `postgres://paperclip:paperclip@127.0.0.1:${configuredPort}/postgres`;
      try {
        const actualDataDir = await getPostgresDataDirectory(configuredAdminConnectionString);
        if (
          typeof actualDataDir !== "string" ||
          resolve(actualDataDir) !== resolve(dataDir)
        ) {
          throw new Error("reachable postgres does not use the expected embedded data directory");
        }

View on GitHub (pinned to 01ad858492)

Solutions

  1. Informational only; no action needed. The server reused the already-running embedded PostgreSQL process.
  2. If you expected a fresh database, stop the existing embedded PostgreSQL process (by pid) before restarting.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at server/src/index.ts:431 when the library encounters an invalid state.

Common situations: 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.


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-08-18). Data as JSON: /api/errors/b6ede7146ab96bf7. Report an issue: GitHub.