{"record":{"id":"d069290f77488f5e","repo":"jdx/mise","slug":"postgres-initialization-failed-existing-data-was-preserved","errorCode":null,"errorMessage":"Postgres initialization failed; existing data was preserved","messagePattern":"Postgres initialization failed; existing data was preserved","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/daemons/presets.rs","lineNumber":226,"sourceCode":"                .trim()\n                != major\n        {\n            bail!(\"Postgres data version does not match its initialization marker\");\n        }\n        return Ok(());\n    }\n    let staging = tempfile::Builder::new()\n        .prefix(\".mise-init-\")\n        .tempdir_in(parent)?;\n    let staged_data: PathBuf = staging.path().join(\"data\");\n    if preset_name == \"postgres\" {\n        let status = Command::new(\"initdb\")\n            .args([\"-D\"])\n            .arg(&staged_data)\n            .args([\"-U\", \"postgres\", \"--auth=trust\"])\n            .status()?;\n        if !status.success() {\n            bail!(\"Postgres initialization failed; existing data was preserved\");\n        }\n        if database != \"postgres\" {\n            if database.is_empty()\n                || !database\n                    .chars()\n                    .all(|c| c.is_ascii_alphanumeric() || c == '_')\n            {\n                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(),","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/daemons/presets.rs#L208-L244","documentation":"initialize stages a fresh data directory and runs `initdb -D <staged> -U postgres --auth=trust`; if initdb exits non-zero, the staged initialization failed. Because staging happens in a temp dir, the existing (old) data directory is untouched and preserved.","triggerScenarios":"initdb fails during initialization of a new postgres data dir — e.g. initdb not on PATH (command spawn) or exits non-zero due to bad locale/permissions/existing files.","commonSituations":"initdb binary missing or not executable; insufficient permissions on the staging parent; locale/encoding problems in the environment; disk full.","solutions":["Ensure initdb (from the postgres tool install) is on PATH and executable","Check initdb's stderr by running it manually on the same parent directory","Free disk space / fix permissions on the state directory","Check locale environment variables (LC_ALL/LANG) that initdb may reject"],"exampleFix":"// shell before: initdb not on PATH\nPATH=\"$HOME/.local/share/mise/installs/postgres/16/bin:$PATH\" mise daemon start","handlingStrategy":"retry","validationCode":"command -v initdb && initdb --version || echo 'initdb missing or broken'","typeGuard":null,"tryCatchPattern":"catch (e) { if (/Postgres initialization failed/.test(e.message)) { checkInitdbPathAndLocale(); /* existing data is preserved, safe to retry */ } }","preventionTips":["Keep the postgres bin dir on PATH before starting daemons","Watch disk space on the state partition","Fix locale env vars (LC_ALL/LANG) for initdb"],"tags":["daemon","postgres","initdb","initialization"],"backgroundTag":"database-initialization-failed","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"}