16

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.

matthias krull
  • 4,389
  • 3
  • 34
  • 54
mtjiran
  • 292
  • 1
  • 2
  • 12
  • 3
    Have you tried start the cmd.exe first then chcp 1252 (or chcp 850, which ever your psql shell asks)? It seems like you typed the command in psql shell. You should use windows run (Win+R) to type in the command and start psql shell in that console window. – Codism Oct 03 '13 at 14:45
  • strange, I made the suggested mistake, so I tried your suggestion. Error keeps popping up. To make no mistake I tried cmd.exe /c chcp 1252 and cmd.exe /c chcp 850. – mtjiran Oct 03 '13 at 17:43

7 Answers7

10

What is your database Character Set? If it is UTF-8, then before running, what ever you want in psql, just tell the console to use the UTF-8 encoding: cmd.exe /c chcp 65001

Nuno Lourenço
  • 136
  • 2
  • 5
5

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

Jeff Simpson
  • 51
  • 1
  • 1
  • This works when I double-click runpsql.bat from the file system, but the warning still shows up when running `psql` from the command line, do you know how to stop this? – user2361174 Mar 31 '17 at 04:10
3

As far as I know, in SQL shell you just need to type \! chcp <codepage_you_need>.

Still, after that, you might encounter another issue:

enter image description here

In order to solve this problem you need to go to properties (left upper corner) -> Fonts -> choose Lucida Console.

Then type \! chcp 1251

After that, everything must be alright.

IceTeaGreen
  • 133
  • 12
1

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

Marc Sloth Eastman
  • 693
  • 1
  • 10
  • 19
  • This didn't work for me. My password was broken after using this command and I had to reinstall postgres again. – aurumpurum Jun 06 '21 at 15:25
1

I had the same problem in Windows 8. You have to set the chcp to 1252. With the command cmd.exe /c chcp 1252, or, if you are using powershell: powershell /c chcp 1252.

0

You can also use powershell /c chcp 1252. But you have to type it before enter in the psql console.

mdmundo
  • 1,988
  • 2
  • 23
  • 37
0

Edit runpsql.bat (folder ...\PostgreSQL\XX\scripts)

On the next line after @echo off write: cmd /c chcp 1252 and save (you need admin permissions).

Screenshot runpsql

1

Results

2

vimuth
  • 5,064
  • 33
  • 79
  • 116