{"record":{"id":"25667aa794862d28","repo":"neondatabase/neon","slug":"createdb-failed-with-status-stderr","errorCode":null,"errorMessage":"createdb failed with status {}: {stderr}","messagePattern":"createdb failed with status (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"control_plane/src/storage_controller.rs","lineNumber":291,"sourceCode":"                \"-p\",\n                &format!(\"{postgres_port}\"),\n                \"-U\",\n                &username(),\n                \"-O\",\n                &username(),\n                DB_NAME,\n            ])\n            .envs(envs)\n            .output()\n            .await\n            .expect(\"Failed to spawn createdb\");\n\n        if !output.status.success() {\n            let stderr = String::from_utf8(output.stderr).expect(\"Non-UTF8 output from createdb\");\n            if stderr.contains(\"already exists\") {\n                tracing::info!(\"Database {DB_NAME} already exists\");\n            } else {\n                anyhow::bail!(\"createdb failed with status {}: {stderr}\", output.status);\n            }\n        }\n\n        Ok(database_url)\n    }\n\n    pub async fn connect_to_database(\n        &self,\n        postgres_port: u16,\n    ) -> anyhow::Result<(\n        tokio_postgres::Client,\n        tokio_postgres::Connection<tokio_postgres::Socket, tokio_postgres::tls::NoTlsStream>,\n    )> {\n        tokio_postgres::Config::new()\n            .host(\"localhost\")\n            .port(postgres_port)\n            // The user is the ambient operating system user name.\n            // That is an impurity which we want to fix in => TODO https://github.com/neondatabase/neon/issues/8400","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/control_plane/src/storage_controller.rs#L273-L309","documentation":"The storage controller's control database is created by spawning the postgres createdb binary against the locally started postgres instance. If createdb exits non-zero and its stderr does not contain 'already exists', the raw exit status and stderr are surfaced with this error.","triggerScenarios":"createdb cannot reach the server (postgres not accepting connections on postgres_port), authentication fails (pg_hba/missing password), the database name is invalid, or a locale/encoding option is unsupported.","commonSituations":"postgres exiting between pg_isready succeeding and createdb running, auth configuration drift between storcon and its local postgres, or half-created database state not covered by the 'already exists' string match.","solutions":["Read the embedded stderr — createdb states the exact reason (connection refused, auth failed, invalid name)","Confirm postgres is still up on the expected port (pg_isready) right before createdb runs","Fix credentials/pg_hba so createdb can authenticate as the configured user","Drop the inconsistent database and retry start"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check the database is absent before running createdb\nlet exists: bool = client\n    .query_opt(\"SELECT 1 FROM pg_database WHERE datname = $1\", &[&DB_NAME])\n    .await?\n    .is_some();\nif exists { /* skip createdb entirely */ }","typeGuard":null,"tryCatchPattern":"if !output.status.success() {\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    if stderr.contains(\"already exists\") { /* fine */ }\n    else if stderr.contains(\"connection refused\") || stderr.contains(\"does not exist\") { /* postgres gone: restart and retry */ }\n    else { anyhow::bail!(\"createdb failed: {stderr}\"); }\n}","preventionTips":["Verify pg_isready immediately before createdb","Keep storcon's postgres auth in sync with the env config","Skip creation idempotently when the database already exists"],"tags":["rust","storage-controller","postgres","createdb","subprocess"],"backgroundTag":"database-creation-failed","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}