1

Whenever I access psql, I get the following message:

psql (9.6.2)
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.

postgres=#

I tried command

cmd.exe /c chcp 1252

before running runpsql.bat file in command line. And there, it runs fine without the error. But accessing psql again after closing command prompt, throws the same warning. How do I solve this warning within SQL Shell?

I am using windows 10 OS.

Edit:

This is what I did:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Sarthak Joshi>E:

E:\>cd PostgreSQL

E:\PostgreSQL>cd scripts

E:\PostgreSQL\scripts>chcp 1252
Active code page: 1252

E:\PostgreSQL\scripts>runpsql.bat
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (9.6.2)
Type "help" for help.

postgres=#

But after exiting from cmd, and firing up shell like this:

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (9.6.2)
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.

postgres=#

It still throws the same warning...

6

When you use cmd.exe /c chcp 1252 in the batch file, you start a new command line, change the codepage for that and then that command line is immediately terminated, but the one that runs psql has not bee changed.

Just put:

chcp 1252

(without calling cmd.exe) into the batch file.

0
0

This works in Powershell as well.

chcp 1252

$connstr = -join ("postgresql://", $dbUser, ":", $dbPW, "@", $connStringEndPoint, ":5432/db")

.\psql $connstr --filename="TestConn.sql"
0

As mentioned in the accepted answer, running chcp in a new command line interpreter context does not work. Here's how I wrapped my Windows PostgreSQL client start in a batch file.

@echo off
setlocal
chcp 1252
if [%1]==[] (set psqlhost=localhost) else (set psqlhost=%1)
if [%2]==[] (set psqluser=postgres) else (set psqluser=%2)
if [%3]==[] (set psqldbase=postgres) else (set psqldbase=%3)
if [%4]==[] (set psqlport=5432) else (set psqlport=%4)

"C:\Program Files\PostgreSQL\11\bin\psql.exe" -h %psqlhost% -U %psqluser% -d %psqldbase% -p %psqlport%
endlocal

Create this batch script as e.g. %APPDATA%\psql.bat. Make sure you have the correct path to psql.exe, I'm using version 11 in Windows 10 (x64).

Passwords can be stored in %APPDATA%\postgresql\pgpass.conf as described in PostgreSQL documentation.

Script can be executed by issuing %appdata%\psql on the command line or as I like to use it, in Windows Terminal profile:

PostgreSQL command line client running in Windows Terminal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.