PostgreSQL: Warning: Console code page (437) differs from Windows code page (1252)

Viewed 48522

Using PostgreSQL when I connect to a db using \c testdb inside PostgreSQL Database SQL Prompt. I successfully connect to the db but getting the following warning:

postgres-# \c testdb
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
You are now connected to database "testdb" as user "postgres".
testdb-#

What does this warning mean? How to resolve it?

14 Answers

The default codepage for CMD.exe is different than the default for postgres... To change for CMD.exe using the REGISTRY try this:

  1. Start -> Run -> regedit
  2. Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
  3. Add new string value named "Autorun" with value "chcp 1252"

Then reopen CMD.exe

Please don't assume that Unix fixes work for Windows Users. For Windows 10, and PostgreSQL 12, combining the answers by "user3423801" and "numbers longer" worked for me. (The Windows Registry hack would not work. I did not try rebooting yet.) It is better to fix it in the PSQL startup script anyway.

The file location C:\Program Files\PostgreSQL\12\scripts contains the file runpsql.bat, into which you must insert the cmd.exe /c chcp 1252 command in the right location. So the top of your edited file should look like the 5 or 6 lines below.

@echo off

REM Copyright (c) 2012-2014, EnterpriseDB Corporation.  All rights reserved

REM PostgreSQL server psql runner script for Windows

cmd.exe /c chcp 1252

SET server=localhost
SET /P server="Server [%server%]: "

you just go to the power-shell or cmd.exe and type the command chcp 1252 or whatever the page number it wants "the one that is the windows code page". If the problem still persists, just open the console properties 'By clicking the power shell icon on the top left of the console window and choosing properties from the drop-down menu' and change the font to "Lucida Console". It worked for me, But you have to open power-shell as an Administrator.

For Postgres 11

"WARNING: Console code page (437) differs from Windows code page (1252) 8-bit characters might not work correctly. See psql reference page "Notes for Windows users" for details."

If you aren't an administrator on your machine Add a line "chcp 1252" to the pg_env.bat script found in the base directory of your postgres installation.' i.e. "C:\Program Files\PostgreSQL\11"

If you are and Administrator on your machine you can modify the registry to run the line everytime you run "cmd.exe" as mentioned above.

I couldn't figure out how to set it for Cygwin globally. This seemed to work though in my bash script

#!/bin/bash
cmd.exe /c chcp 1252 && psql -h myserver.postgres.database.azure.com -U myuser@prod-au -d mydatabase

The answers above are okay, but don't mention anywhere that Windows 1252 encoding is good for English language versions of Windows AND the other Western European Languages. This completes the answer for those people who may get confused about the aforementioned application to German language encoding. Yes it works for English without umlauts and other special characters needed for German, Spanish, French, Italian, Romanian, Hungarian, etc.

https://en.m.wikipedia.org/wiki/Windows-1252

What is Windows 1252 encoding?

Windows-1252 or CP-1252 (code page 1252) is a single-byte character encoding of the Latin alphabet, used by default in the legacy components of Microsoft Windows for English and some other Western languages (other languages use different default encodings).

Basically, set your console application encoding from 8-bit to utf-8 Windows 1252.

For git bash users run the command chcp.com 1252 before running postgres

chcp is a windows console command, so to execute it on git bash you might need to add .com

git bash can't extend chcp to a full executable on its own, so you need to type the full command.

here

  1. On the terminal screen go to the following directory;
    C:\Program Files\PostgreSQL\14\bin

note: whichever database version you are using, go to the bin folder of the db version file.

  1. Before creating a user or accessing the database user, you must write the following code;
    cmd.exe /c chcp 1252
Related