{"record":{"id":"14b3cb7b40982d0d","repo":"jdx/mise","slug":"initdb-and-postgres-have-incompatible-versions","errorCode":null,"errorMessage":"initdb and postgres have incompatible versions","messagePattern":"initdb and postgres have incompatible versions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/daemons/presets.rs","lineNumber":252,"sourceCode":"                bail!(\"invalid database name\");\n            }\n            let mut child = Command::new(\"postgres\")\n                .arg(\"--single\")\n                .arg(\"-D\")\n                .arg(&staged_data)\n                .arg(\"postgres\")\n                .stdin(Stdio::piped())\n                .spawn()?;\n            writeln!(\n                child.stdin.take().unwrap(),\n                \"CREATE DATABASE \\\"{database}\\\";\"\n            )?;\n            if !child.wait()?.success() {\n                bail!(\"failed to create database {database}\");\n            }\n        }\n        if std::fs::read_to_string(staged_data.join(\"PG_VERSION\"))?.trim() != major {\n            bail!(\"initdb and postgres have incompatible versions\");\n        }\n    } else {\n        std::fs::create_dir(&staged_data)?;\n    }\n    std::fs::write(staged_data.join(\".mise-daemon-version\"), marker)?;\n    std::fs::rename(staged_data, data)?;\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    #[test]\n    fn presets_render_local_persistent_daemons() {\n        for (name, _) in PRESETS {\n            let daemon = expand(\n                name,\n                name,","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/daemons/presets.rs#L234-L270","documentation":"After creating a postgres data directory with initdb, mise reads the staged PG_VERSION file and compares it to the major version it parsed from `postgres --version`. If they differ, the initdb binary on PATH came from a different PostgreSQL major release than the postgres server binary, and mise refuses to commit the data directory because PG data is major-version specific. This guards against producing a data directory the server cannot open.","triggerScenarios":"Daemon preset initialization for postgres where `read_to_string(staged_data/PG_VERSION).trim()` does not equal the major version parsed from `postgres --version` — e.g. initdb 15 is on PATH while postgres resolves to 16, or a mise-installed postgres version differs from a system initdb.","commonSituations":"A system PostgreSQL (e.g. from Homebrew or apt) puts initdb on PATH while mise's [tools] postgres is used for the server, or the user recently upgraded postgres and PATH/shims still point at the old initdb.","solutions":["Ensure initdb and postgres come from the same installation: fix PATH so the same postgres prefix wins, or use mise's postgres shims for both.","Run `which initdb` and `which postgres` (or `mise which postgres`) and compare their paths and major versions.","If versions were recently changed, run `mise install`/`mise use` for the intended postgres version and reopen the shell so PATH refreshes.","Delete any leftover staged data directory and retry initialization after aligning versions."],"exampleFix":"// before (mismatched tools on PATH)\n[tools]\npostgres = \"16\"\n# system initdb 15 still first on PATH\n\n// after\n[tools]\npostgres = \"16\"\n# ensure mise shims precede system postgres in PATH (mise activate)","handlingStrategy":"validation","validationCode":"# Confirm initdb and postgres come from the same install before initializing\nwhich initdb postgres\ninitdb --version\npostgres --version  # major numbers must match","typeGuard":null,"tryCatchPattern":"try {\n  mise daemons start\n} catch (e) {\n  if (String(e).includes(\"incompatible versions\")) {\n    console.error(\"initdb/postgres major mismatch — fix PATH or mise postgres version, then retry.\");\n  }\n}","preventionTips":["Keep initdb and postgres from the same installation first on PATH (mise activate/shims)","After upgrading postgres, open a fresh shell so PATH refreshes","Check `mise which postgres` matches your expected install"],"tags":["postgres","version-mismatch","daemon"],"backgroundTag":"version-mismatch","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}