In my other article, we have seen steps to connect to Redshift cluster using PostgreSQL PSQL. When you connect to Amazon Redshift from Windows command prompt, you may experience the client encoding issue. In this article, we will check how to resolve “psql: FATAL: invalid value for parameter “client_encoding”: “WIN1252”” issue. This is issue is mostly seen when connecting using Windows command prompt.
Postgres PSQL Introduction
PSQL is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Since Redshift is based on PostgreSQL 8.x, you can use PSQL client to connect to Redshift cluster and type in queries interactively, issue them to Redshift cluster, and see the query results.
The Psql allows you to connect to Redshift and execute SQL queries or scripts containing SQL queries on Redshift cluster. You can also use PSQL to substitute the variables before issuing queries to the Redshift. The PSQL client also enables you to handle the errors within scripts using ON_ERROR-STOP option.
PSQL client also allows you to access Redshift cluster using system variables and without a password prompt for repetitive connections.
Psql Invalid Value for Parameter client_encoding Issue in Redshift
The “psql: FATAL: invalid value for parameter “client_encoding”: “WIN1252”” issue is common when you are connecting to AWS Redshift from Windows command (cmd) prompt. To resolve this issue, you will need to set the variable PGCLIENTENCODING
via the command line.
The following steps will help you to resolve encoding issue.
- Open the cmd
SET PGCLIENTENCODING=utf-8
chcp 65001
And now, you can connect to Amazon Redshift.
>psql -h test-redshift.djelrn1jk4jk.us-east-1.redshift.amazonaws.com -U awsuser -d dev -p 5439
Password for user awsuser:
psql (10.16, server 8.0.2)
WARNING: Console code page (65001) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
dev=#
You can use the following steps if your server encoding set to latin1 (a.k.a. iso8859-1).
- Open the cmd
SET PGCLIENTENCODING=iso8859-1
chcp 1252
Related Articles,
- Psql Windows Exit Status Codes – Explanation
- Best Amazon Redshift Query Tools – SQL Editors
- Redshift Connection Issues – Causes and Resolution
- Redshift RSQL Control Statements – IF-ELSE-GOTO-LABEL
Hope this helps 🙂