{"record":{"id":"6cca615556325bd1","repo":"windmill-labs/windmill","slug":"could-not-connect-to-the-database","errorCode":null,"errorMessage":"Could not connect to the database","messagePattern":"Could not connect to the database","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/workspaceSettings/datatableProbe.ts","lineNumber":88,"sourceCode":"\t\ttimeoutCode: async () => {\n\t\t\tawait JobService.cancelQueuedJob({\n\t\t\t\tworkspace,\n\t\t\t\tid: job,\n\t\t\t\trequestBody: { reason: 'The connection check did not start' }\n\t\t\t}).catch(() => {})\n\t\t},\n\t\tinterval: 500,\n\t\ttimeout\n\t})\n\n\tif (!completed) {\n\t\tthrow new Error(\n\t\t\t'The connection check did not run. Is a worker listening to the postgresql tag available?'\n\t\t)\n\t}\n\tconst done = completed as { success: boolean; result?: any }\n\tif (!done.success) {\n\t\tthrow new Error(done.result?.error?.message ?? 'Could not connect to the database')\n\t}\n\n\tconst row: Row = (Array.isArray(done.result) ? done.result[0] : done.result) ?? {}\n\t// Suggested only where the privilege is actually missing; Postgres returns NULL for a\n\t// statement it could not name, which is the case where no grant would help anyway.\n\tconst suggested_grants = [\n\t\trow.can_create_table ? undefined : (row.grant_schema ?? undefined),\n\t\trow.can_create_schema ? undefined : (row.grant_database ?? undefined)\n\t].filter((s): s is string => !!s)\n\n\treturn {\n\t\tuser: row.usr ?? '',\n\t\tschema: row.sch ?? null,\n\t\tcan_create_table: !!row.can_create_table,\n\t\tcan_create_schema: !!row.can_create_schema,\n\t\tmigrations_table_exists: !!row.has_migrations_table,\n\t\tsuggested_grants,\n\t\tsuggested_search_path: row.sch ? undefined : (row.fix_search_path ?? undefined)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/workspaceSettings/datatableProbe.ts#L70-L106","documentation":"When the postgresql connection-check job does complete but reports success=false, the probe throws either the error message returned by the script (done.result?.error?.message) or the fallback 'Could not connect to the database'. It means a worker ran the check and Postgres actively refused/failed the connection.","triggerScenarios":"The connection-check script runs on a postgresql-tagged worker and its result has success=false with no parseable error.message — bad host/port, wrong credentials, TLS issues, unreachable database, or the script result shape differs from expected.","commonSituations":"Typo in database host/port or database name; wrong username/password; Postgres not accepting remote connections (pg_hba.conf/listen_addresses); firewall or VPC blocking the worker's egress; expired credentials.","solutions":["Read the underlying message when present (done.result.error.message) — it names the actual Postgres failure","Verify host, port, database, user and password in the resource; test with `psql` from a machine that shares the worker's network","Check Postgres server logs and pg_hba.conf / listen_addresses for rejected connections","Confirm network reachability from the worker (firewalls, security groups, VPC peering, TLS requirements)"],"exampleFix":"// before\n{ database: 'db', host: 'localhost', port: 5432 }  // worker cannot see 'localhost'\n// after\n{ database: 'db', host: 'postgres.internal', port: 5432 }  // reachable from the worker","handlingStrategy":"try-catch","validationCode":"// validate inputs before probing\nif (!host || !port || !db || !user || !password) throw new Error('Fill all connection fields before testing')","typeGuard":null,"tryCatchPattern":"try {\n  await probeDatatableConnection(...)\n} catch (e) {\n  const msg = e?.message ?? ''\n  if (/password authentication failed/i.test(msg)) { /* fix credentials */ }\n  else if (/connection refused|could not connect/i.test(msg)) { /* fix host/port/network */ }\n}","preventionTips":["Test credentials with psql from the same network as the worker before configuring","Double-check host/port/database and TLS settings; remember workers cannot reach your machine's 'localhost'","Review pg_hba.conf and firewall rules when moving between environments"],"tags":["postgresql","database","connection","network"],"backgroundTag":"database-connection-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}