{"record":{"id":"a6aac1f34793adf6","repo":"ruvnet/RuView","slug":"pg-dump-failed-error-msg","errorCode":null,"errorMessage":"pg_dump failed: {error_msg}","messagePattern":"pg_dump failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"archive/v1/src/tasks/backup.py","lineNumber":169,"sourceCode":"        \n        # Set environment variables\n        env = os.environ.copy()\n        if self.settings.db_password:\n            env[\"PGPASSWORD\"] = self.settings.db_password\n        \n        # Execute pg_dump\n        process = await asyncio.create_subprocess_exec(\n            *pg_dump_cmd,\n            env=env,\n            stdout=asyncio.subprocess.PIPE,\n            stderr=asyncio.subprocess.PIPE\n        )\n        \n        stdout, stderr = await process.communicate()\n        \n        if process.returncode != 0:\n            error_msg = stderr.decode() if stderr else \"Unknown pg_dump error\"\n            raise Exception(f\"pg_dump failed: {error_msg}\")\n        \n        backup_size_mb = self._get_file_size_mb(backup_path)\n        \n        # Clean up old backups\n        self._cleanup_old_backups(\"database_full_*.sql.gz\", self.retention_days)\n        \n        return {\n            \"backup_file\": backup_filename,\n            \"backup_path\": str(backup_path),\n            \"backup_size_mb\": backup_size_mb,\n            \"retention_days\": self.retention_days,\n        }\n\n\nclass ConfigurationBackup(BackupTask):\n    \"\"\"Backup configuration files and settings.\"\"\"\n    \n    def __init__(self, settings: Settings):","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/tasks/backup.py#L151-L187","documentation":"DatabaseBackup.execute_backup() shells out to pg_dump (custom format, compression 9, --no-password) and raises a generic Exception embedding pg_dump's stderr when the subprocess exits nonzero. The real cause is always in the appended stderr: common ones are authentication failure (no PGPASSWORD for the --no-password run), unreachable server, nonexistent database, or a pg_dump client version older than the PostgreSQL server (pg_dump refuses to dump newer server versions).","triggerScenarios":"Scheduled backup with wrong db_host/db_user/db_password in settings (PGPASSWORD set from settings.db_password); PostgreSQL server down or firewalled; pg_dump from OS packages older than the server major version; settings.database_url malformed; database name typo.","commonSituations":"Production Postgres upgraded (e.g. 14 -> 16) while the app container still has the old pg_dump client; rotated DB credentials not updated in .env; backups run from a host without network access to the DB; local dev without Postgres running.","solutions":["Read the embedded stderr in the raised message; it names the exact pg_dump failure.","Fix credentials/connectivity: verify with 'psql \"$DATABASE_URL\" -c \"select 1\"' using the same settings the task uses; ensure settings.db_password (PGPASSWORD) is present because --no-password forbids prompts.","Fix version mismatches: compare 'pg_dump --version' with the server ('SELECT version();') and install the matching or newer postgresql-client.","Confirm the backup directory exists and is writable, then re-run the backup task."],"exampleFix":"# before\nresult = await db_backup.execute_backup(session)  # Exception: pg_dump failed: ...\n\n# after\nimport subprocess\nsubprocess.run(['pg_dump', '--version'], check=True)  # confirm client present and version\nresult = await db_backup.execute_backup(session)","handlingStrategy":"retry","validationCode":"import shutil, subprocess\nif shutil.which('pg_dump') is None:\n    raise RuntimeError('pg_dump not installed on this host')\nclient = subprocess.run(['pg_dump', '--version'], capture_output=True, text=True).stdout","typeGuard":null,"tryCatchPattern":"last_exc = None\nfor attempt in range(3):\n    try:\n        result = await db_backup.execute_backup(session)\n        break\n    except Exception as exc:\n        last_exc = exc\n        if 'version' in str(exc) or 'authentication' in str(exc):\n            raise  # not transient: fix client version or credentials\n        await asyncio.sleep(2 ** attempt * 5)\nelse:\n    alert_ops(f'database backup failed after retries: {last_exc}')\n    raise last_exc","preventionTips":["Alert ops on every backup failure; a silently failing backup is data loss in waiting.","Pin the postgresql-client package to at least the server's major version in deployment images.","Smoke-test the backup after every DB or credentials change by running the task once and verifying backup_size_mb > 0."],"tags":["backup","postgres","pg-dump","database","ops"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}