Eliminar warning de code page no psql do Windows

<< Click to Display Table of Contents >>

Navigation:  PostgreSQL > Avançado >

Eliminar warning de code page no psql do Windows

Previous pageReturn to chapter overviewNext page

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.

 

Na prática

 

Se você abrir no Windows o psql ele dará um warning:

 

Microsoft Windows XP [versão 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

 

C:\>psql -h 192.168.60.155 -U postgres

Welcome to psql 8.3.3, the PostgreSQL interactive terminal.

 

Type:  \copyright for distribution terms

       \h for help with SQL commands

       \? for help with psql commands

       \g or terminate with semicolon to execute query

       \q to quit

 

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.

 

postgres=# \q

 

Para resolver isso, basta trocar o codepage do Windows:

 

C:\>cmd.exe /c chcp 1252

Página de códigos ativa: 1252

 

Agora ao conectar, não receberá o warning mais:

 

C:\>psql -h 192.168.60.155 -U postgres

Welcome to psql 8.3.3, the PostgreSQL interactive terminal.

 

Type:  \copyright for distribution terms

       \h for help with SQL commands

       \? for help with psql commands

       \g or terminate with semicolon to execute query

       \q to quit

 

postgres=#

 

Para ficar definitivo, adicione esta linha no c:\windows\system32\autoexec.nt

 

cmd.exe /c chcp 1252