PostgreSQL ERROR 22021: invalid byte sequence for encoding "UTF8": 0x00
Null byte (`\x00`) or Latin-1 bytes were sent to a UTF-8 PostgreSQL database.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: PostgreSQL ERROR 22021
Platform: PostgreSQL
Common Root Causes:
- Null byte (`\x00`) or Latin-1 bytes were sent to a UTF-8 PostgreSQL database.
Interactive Diagnostic Checklist
Verified Solutions:
- Strip `\0` bytes from text inputs and convert source CSVs to UTF-8 via `iconv`.
Safe Diagnostic Command:
file -i <input-file>
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Null byte (`\x00`) or Latin-1 bytes were sent to a UTF-8 PostgreSQL database. Recommended diagnostic: `file -i <input-file>`. Remediation: Strip `\0` bytes from text inputs and convert source CSVs to UTF-8 via `iconv`.
Worked Examples
- Run `file -i <input-file>` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-pg-invalid-byte-sequence-utf8 · Independently verified: 2026-11-25