
実行環境は次のとおりです。
• OS : Windows7 x64 SP1(英語版)
• Cygwin 2.5.1 x64 + PostgreSQL 9.5.2
• cygserverとPostgreSQLをアドホックに起動(サービスでない)
• クライアント : psql(Windowsネイティブ、Cygwin版ともに同じ現象)
Windows
> chcp 932 Active code page: 932 > psql -U postgres -p 5952 psql (9.5.3, サーバー 9.5.2) "help" でヘルプを表示します. postgres=# \t \\ \a \\ \set PROMPT1 '#' 「タプルのみ表示」は on です。 出力フォーマットは unaligned です。
↓ クライアントエンコーディングは
# \encoding SJIS # select version(); PostgreSQL 9.5.2 on x86_64-unknown-cygwin, compiled by gcc (GCC) 5.3.0, 64-bit # select current_setting('lc_messages'); C # select chr(12436); ERROR: character with byte sequence 0xe3 0x82 0x94 in encoding "UTF8" has no equivalent in encoding "SJIS"
次が問題。メッセージを日本語に設定して同じクエリを送ると ↓ サーバが強制終了しました。
# set lc_messages to 'ja_JP'; SET # select chr(12436); サーバとの接続が想定外にクローズされました おそらく要求の処理前または処理中にサーバが異常終了 したことを意味しています。 サーバーへの接続が切れました。リセットしています: 失敗。
日本語メッセージにすること自体は問題なく、他のエラーでは ↓ 普通です。やっぱり
# set lc_messages to 'ja_JP'; SET # select rand(); ERROR: 関数rand()は存在しません 行 1: select rand(); ^ HINT: 指定名称、指定引数型に合う関数がありません。明示的な型キャストが必要かもしれません

同じ現象が
# \encoding sjis # set lc_messages to 'C'; SET # select chr(12436); ERROR: character with byte sequence 0xe3 0x82 0x94 in encoding "UTF8" has no equivalent in encoding "SJIS" # set lc_messages to 'ja_JP'; SET # select chr(12436); server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed.

対策としては単純で、Windows
サーバが
R:\>d:\appsportable\postgresql\9.5.3\bin\psql -U postgres psql (9.5.3) "help" でヘルプを表示します. postgres=# \t \\ \a \set PROMPT1 '# ' 「タプルのみ表示」は on です。 出力フォーマットは unaligned です。 # \encoding SJIS # set lc_messages to 'ja_JP'; SET # select chr(12436); ERROR: 符号化方式"UTF8"における0xe3 0x82 0x94バイトシーケンスを持つ文字は"SJIS"符号化方式では等しくありません
