Notes for windows users psql
C:\Program Files\PostgreSQL\9.0\bin>psql -U postgres
psql (9.0.3)
WARNING: Console code page (866) differs from Windows code page (1251)
8-bit characters might not work correctly. See psql reference
page «Notes for Windows users» for details.
Type «help» for help.
C:\Program Files\PostgreSQL\9.0\bin>chcp 1251
������� ������� ��������: 1251
C:\Program Files\PostgreSQL\9.0\bin>psql -U postgres
psql (9.0.3)
Type «help» for help.
postgres=# select * from «Test»;
name
———-
РямчикЦЙ
John
(2 rows)
��� ������?
| |
eye-cutter Member \encoding win-1251 | |
27 ��� 11, 18:26����[10576522] �������� | ���������� �������� ���������� |
| |
������� Member SET client_encoding=win866; | |
28 ��� 11, 00:19����[10577825] �������� | ���������� �������� ���������� |
| |
Judo Member ������: | C:\Program Files\PostgreSQL\9.0\bin>psql -U postgres psql (9.0.3) WARNING: Console code page (866) differs from Windows code page (1251) 8-bit characters might not work correctly. See psql reference page «Notes for Windows users» for details. Type «help» for help. postgres=# \encoding win-1251 postgres=# SET client_encoding=win866; PostgreSQL — Кириллица в psql под WindowsВ статье пойдёт речь о том, как добиться корректного вывода кириллицы в «консоли» Windows ( cmd.exe ). СодержаниеОписание проблемыВ дистрибутив PostgreSQL, помимо всего прочего, для работы с СУБД входит:
При работе с psql в среде Windows пользователи Ну и зачем тогда работать с psql , кому нужно долбить клавиатурой в консольке, когда можно всё сделать красиво и быстро в pgAdmin ? Ну, не всегда pgAdmin доступен, особенно если речь идёт об удалённой машине. Кроме того, выполнение SQL-запросов в текстовом режиме консоли — это +10 к хакирству. Решение проблемы
На сервере имеется БД, созданная в кодировке UTF8. Суть проблемы в том, что cmd.exe работает (и так будет до скончания времён) в кодировке CP866 , а сама Windows — в WIN1251 , о чём psql предупреждает при начале работы: Значит, надо как-то добиться, чтобы кодировка была одна. В разных источниках встречаются разные рецепты, включая правку реестра и подмену файлов в системных папках Windows. Ничего этого делать не нужно, достаточно всего трёх шагов:
Конкретные действияСупер быстро и простоЗапускаете cmd.exe , оттуда psql :
Быстро и простоЗапускаете cmd.exe , оттуда psql : Вводите пароль (если установлен) и выполняете команду: И всё. Теперь результаты запроса, содержащие кириллицу, будут отображаться нормально. Но есть небольшой косяк: Потому предлагаем ещё способ, который этого недостатка лишён. Посложнее и подольшеЗапустить cmd.exe , нажать мышью в Кстати, обратите внимание — теперь предупреждения о несовпадении кодировок нет. Всё, теперь кириллица будет нормально отображаться. warning about console code page on starting psqlwarning about console code page on starting psqlSUMMARY OF PROBLEM: Postgres notes no errors upon installation, but upon startup of psql there’s a warning; documentation fix doesn’t eliminate the warning message. 1. psql says this when I log in: Password for user postgres: 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. Type «help» for help. 2. psql ref. pg. says this: 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 console font to Lucida Console , because the raster font does not work with the ANSI code page. 3. When I enter «cmd.exe /c chcp 1252» into the command prompt, it says this: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\zzzzzz>cmd.exe /c chcp 1252 Active code page: 1252 4. Am I supposed to type this at the command prompt: «cmd.exe /c chcp 437»? Because that’s what I did, and now the command prompt says this. C:\Users\zzzzzz>cmd.exe /c chcp 437 Active code page: 437 . but I quit and reopened psql, the error message isn’t gone or changed. 5. The instructions to set console font mean nothing to me: «Set the console font to Lucida Console , because the raster font does not work with the ANSI code page». Googled it and found nothing that made sense to me. Set whose console font? PG or Windows? Where and how to set it? What is a console, anyway? Googled again and again, finally discovered that the console being referred to is apparently psql itself. By clicking on the little rectangular icon at the top left of the title bar of the command prompt (psql), Properties, Font. there it is. «Raster Fonts» had been selected. I changed this to Lucida Console. Quit psql and restarted it. 6. psql startup warning has now changed to a different font, no other change. 7. I changed the console page back to 1252 in the command prompt: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\>cmd.exe /c chcp 1252 Active code page: 1252 8. Quit and restarted psql (twice). The warning message has not changed. Is it possible that pg is wrongly detecting code page 437, and does it matter? I have a lot of work to do and want a sparkling clean foundation to start from so I don’t have problems later. This email has been checked for viruses by Avast antivirus software. Re: warning about console code page on starting psql
Do not type the «cmd.exe /c» part. This will run a new instance of «cmd» (the Windows command-line console); «\c» means «run the following command». So you are basically starting a new console, changing the code page within that new console, and exiting back to your original console. Instead, once you have a command prompt, use «chcp 1252» to change the code page of the Windows console to match the code page «psql» expects from Windows. Then you can run «psql» without the warning. You will have to do this each time you open a new command line console, before running «psql», as far as I can tell. Re: warning about console code page on starting psqlGoing from memory here but. The window is which the command prompt appears is called the console. When you type psql at the command prompt you are now running a console application in that same console. You can have more than one running console and each one is independent. Any changes to the console, e.g. via the «cmd.exe /c chcp 1252» command, only persist as long as that console window remains open. Going into and out of a console application should not make a difference, only closing the actual window. Same goes for the font — it is a property of the console and not psql directly. Since the database server uses the Windows code page you want your console to match. So given said warning you want to supply the current Windows value to the chcp command. The message and documentation could probably be improved though I’m not positive what I am saying is 100% correct as I have never encountered this problem — because I’ve never used psql on Windows. Re: warning about console code page on starting psqlOn 12/16/2014 11:10 PM, Scott Robertson wrote: Do not type the «cmd.exe /c» part. This will run a new instance of «cmd» Instead, once you have a command prompt, use «chcp 1252» to change the So basically the documented fix is useless. At least a «/k» would keep the new console with altered code page around for interactive use but the /c switch simply kills the console after running a single command whose sole purpose is to change the to-be-killed console’s codepage. It is implied that since you are chasing the console codepage that the target value would be whatever Window’s is using. but that could be made more clear as well. Encodings are confusing and this doesn’t even mention using windows psql against Linux or how Unicode would fit in — though external notes indicate that the font change suggestion also solves Unicode characters as well as dealing with ANSI. Fwd: warning about console code page on starting psql———- Forwarded message ———- On 12/16/2014 11:10 PM, Scott Robertson wrote: Do not type the «cmd.exe /c» part. This will run a new instance of «cmd» Instead, once you have a command prompt, use «chcp 1252» to change the So basically the documented fix is useless. At least a «/k» would keep the new console with altered code page around for interactive use but the /c switch simply kills the console after running a single command whose sole purpose is to change the to-be-killed console’s codepage. It is implied that since you are chasing the console codepage that the target value would be whatever Window’s is using. but that could be made more clear as well. Encodings are confusing and this doesn’t even mention using windows psql against Linux or how Unicode would fit in — though external notes indicate that the font change suggestion also solves Unicode characters as well as dealing with ANSI. Re: warning about console code page on starting psql———- Forwarded message ———- On 12/16/2014 11:10 PM, Scott Robertson wrote: Do not type the «cmd.exe /c» part. This will run a new instance of «cmd» Instead, once you have a command prompt, use «chcp 1252» to change the So basically the documented fix is useless. At least a «/k» would keep the new console with altered code page around for interactive use but the /c switch simply kills the console after running a single command whose sole purpose is to change the to-be-killed console’s codepage. It is implied that since you are chasing the console codepage that the target value would be whatever Window’s is using. but that could be made more clear as well. Encodings are confusing and this doesn’t even mention using windows psql against Linux or how Unicode would fit in — though external notes indicate that the font change suggestion also solves Unicode characters as well as dealing with ANSI. Re: warning about console code page on starting psql
It sounds like you’re saying that I should type this command in the psql
Re: warning about console code page on starting psql
It sounds like you’re saying that I should type this command in the psql Yes, I had a shortcut for psql in the program files start menu of Windows, which I moved to the desktop. I don’t know another way to open it. Shortcut target is «C:\Program Files\PostgreSQL\9.4\scripts\runpsql.bat»
This email has been checked for viruses by Avast antivirus software. Re: warning about console code page on starting psqlSorry, I forgot to Cc the list earlier when I was replying from my phone. On 18 December 2014 at 07:38, Scott Robertson wrote: I assume you also changed the font. Since I don’t currently use > C:\>cd \program files\postgresql\9.4\bin\ The way you were running psql before seems to be via a .bat or .cmd If you decide to edit the .bat (or .cmd) file, make a backup of it first Re: warning about console code page on starting psql
———- Forwarded message ———- On 12/16/2014 11:10 PM, Scott Robertson wrote: Do not type the «cmd.exe /c» part. This will run a new instance of «cmd» Instead, once you have a command prompt, use «chcp 1252» to change the So basically the documented fix is useless. At least a «/k» would keep the new console with altered code page around for interactive use but the /c switch simply kills the console after running a single command whose sole purpose is to change the to-be-killed console’s codepage. It is implied that since you are chasing the console codepage that the target value would be whatever Window’s is using. but that could be made more clear as well. Encodings are confusing and this doesn’t even mention using windows psql against Linux or how Unicode would fit in — though external notes indicate that the font change suggestion also solves Unicode characters as well as dealing with ANSI. Case closed and much learned. The documentation was depending on me remembering some things learned from a dos class almost 20 years ago, haven’t used the command line console since. SUMMARY OF SOLUTION RESULTS: C:\>chcp C:\>chcp 1252 C:\>cd program files\postgresql\9.4\bin\ C:\Program Files\PostgreSQL\9.4\bin> postgres=# \c testdb2 |