cat dumpall.sql | iconv -c -f EUC-JP -t UTF-8 -c | sed -E -f encoding_convert.sed | psql
encoding_convert.sed
s/SET client_encoding = 'EUC_JP';/SET client_encoding = 'UTF8';/ s/(CREATE DATABASE .* ENCODING = )'EUC_JP';/\1'UTF8';/
sedで
SET client_encoding = 'EUC_JP'; ↓ SET client_encoding = 'UTF8'; CREATE DATABASE example WITH TEMPLATE = template0 OWNER = postgres ENCODING = 'EUC_JP'; ↓ CREATE DATABASE example WITH TEMPLATE = template0 OWNER = postgres ENCODING = 'UTF8';
に置換
ERROR: invalid byte sequence for encoding
PostgreSQL の SQL_ASCII DB を UTF-8 で pg_restore する方法 | ミヤビッチの穴 2015