Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql shell uses code page 850, windows uses 1252. How to solve change console code page?

I have installed PostgreSQL, wanting to set up a new database, everything is going fine, until I am trying to use the € sign. And then I knew, that warning I get in the beginning is for a reason.

The warning I am getting at starting up my psql shell is:

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

So I am going to do as I am told (from PostgreSQL Documentation 9.2 - psql):


Notes for Windows Users

psql is built as a "console application". Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8-bit characters within psql. If psql detects a problematic console code page, it will warn you at startup. To change the console code page, two things are necessary:

  • Set the code page by entering cmd.exe /c chcp 1252. (1252 is a code page that is appropriate for German; replace it with your value.) If you are using Cygwin, you can put this command in /etc/profile.
  • Set the console font to Lucida Console, because the raster font does not work with the ANSI code page.

When I type the cmd.exe /c chcp 1252 command I get a syntax error. So psql, doesn't recognize the command. Out of desperation, I was trying to do something in cmd.exe itself, does not work either.

I work in Windows 7 - 64Bit.

like image 612
mtjiran Avatar asked Oct 03 '13 14:10

mtjiran


2 Answers

I was able to fix this by running SET CLIENT_ENCODING TO 'UTF-8'; in the sql bash

like image 132
Marc Sloth Eastman Avatar answered Sep 24 '22 18:09

Marc Sloth Eastman


I had the same problem in Windows 10.

In psql type ! chcp

it revealed my setting as 850. This I changed to 1252 by doing the following.

! dir revealed a file runpsql.bat in C:\Program Files\PostgreSQL\9.6\scripts

From windows after exiting psql I ran Notebook in Administrator mode and added above the REM Run psql statement the command chcp 1252

Now runs without the warnings

like image 45
Jeff Simpson Avatar answered Sep 21 '22 18:09

Jeff Simpson