Evgenii Legotckoi
June 4, 2017, 2:52 p.m.

Correcting the client encoding of the PostgreSQL database from LATIN1 to UTF8

Content

On the site there was one bug that manifested itself when trying to attach to files messages whose names were in Cyrillic. In this case, the site issued error 503. This occurred despite the fact that the database was encoded in UTF8, after correcting the encoding of the database itself in the previous article . While Django issued the following message:

  1. 'latin-1' codec can't encode characters in position 55-64: ordinal not in range(256)

The problem was that the server's coding was initially set to LATIN1. That is, the following commands gave the following conclusion:

  1. postgres=# show server_encoding;
  2. server_encoding
  3. -----------------
  4. LATIN1
  5. (1 row)
  6.  
  7. postgres=# show client_encoding;
  8. client_encoding
  9. -----------------
  10. LATIN1
  11. (1 row)
  12.  
  13. postgres=# \encoding
  14. LATIN1

Executing the command SET CLIENT_ENCODING TO 'utf 8'; did not work, after exiting psql, the encoding was returned to LATIN1 .


Correction

Correction of this bug reduced to setting the encoding of the server itself. Since the server is primarily Russian-speaking, the installation of Russian-language packages of locales was made to correct it.

  1. sudo apt-get install language-pack-ru

Implementation of the Russification process

  1. sudo update-locale LANG=ru_RU.UTF-8

And reboot the server

  1. sudo reboot

After that, the server client encoding became UTF8

  1. postgres=# show server_encoding;
  2. server_encoding
  3. -----------------
  4. LATIN1
  5. (1 row)
  6.  
  7. postgres=# show client_encoding;
  8. client_encoding
  9. -----------------
  10. UTF8
  11. (1 row)
  12.  
  13. postgres=# \encoding
  14. UTF8

This was enough to fix the bug.

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html