• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

How to fix PostgreSQL Error Code: 22021 – character_not_in_repertoire

January 2, 2024

How to Fix PostgreSQL Error Code: 22021 – character_not_in_repertoire

PostgreSQL is a powerful open-source relational database management system that is widely used by developers and organizations around the world. However, like any software, it can encounter errors that can hinder its functionality. One such error is the PostgreSQL Error Code: 22021 – character_not_in_repertoire. In this article, we will explore what this error means and how to fix it.

The PostgreSQL Error Code: 22021 – character_not_in_repertoire occurs when a character that is not supported by the current encoding is encountered. This error typically arises when trying to insert or update data that contains characters outside the supported character set. It can be frustrating, but fortunately, there are several steps you can take to resolve this issue.

1. Check the Encoding: The first step is to verify the encoding settings of your PostgreSQL database. You can do this by running the following SQL query:

SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = ‘your_database_name’;

Replace ‘your_database_name’ with the name of your database. This query will return the current encoding used by your database.

2. Change the Encoding: If the encoding is not set correctly, you will need to change it. To do this, you will need to dump the database, create a new one with the correct encoding, and then restore the data. Here are the steps:

a. Dump the database using the pg_dump command:

pg_dump -Fc -f backup_file.dump your_database_name

This command will create a backup file of your database.

b. Drop the existing database:

DROP DATABASE your_database_name;

c. Create a new database with the correct encoding:

CREATE DATABASE your_database_name WITH ENCODING ‘UTF8’;

d. Restore the data from the backup file:

pg_restore -C -d your_database_name backup_file.dump

3. Update the Data: If changing the encoding is not an option, you can try updating the data to remove or replace the unsupported characters. You can use the REPLACE function in PostgreSQL to replace specific characters or use regular expressions to remove them.

For example, to replace all occurrences of a specific character, you can use the following query:

UPDATE your_table SET your_column = REPLACE(your_column, ‘character_to_replace’, ‘replacement_character’);

Replace ‘your_table’ with the name of your table, ‘your_column’ with the name of the column containing the data, ‘character_to_replace’ with the unsupported character, and ‘replacement_character’ with the desired replacement.

4. Use a Different Encoding: If none of the above solutions work, you may need to consider using a different encoding that supports the characters you need. However, changing the encoding can have implications on the existing data, so it is essential to thoroughly test and backup your database before making any changes.

In conclusion, the PostgreSQL Error Code: 22021 – character_not_in_repertoire can be resolved by checking and changing the encoding settings, updating the data, or using a different encoding. It is crucial to understand the cause of the error and choose the appropriate solution based on your specific requirements.

For reliable and high-performance VPS hosting solutions, consider Server.HK. Our Hong Kong VPS hosting services offer top-notch performance and support for PostgreSQL and other popular databases. Visit our website to learn more about our hosting plans and how we can help you optimize your PostgreSQL database.

Recent Posts

  • How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  • How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  • CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  • Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  • Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot