Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PgAdmin III, opening server status gives "invalid byte sequence for encoding UTF8"

I have two Postgres 9.3 servers in synchronous replication.

I had needed to restart the slave in order to load a new archive_cleanup_command in the recovery.conf.

The server restarted correctly and it's now perfectly in sync with the master server.

But when I open "Server status" panel for the slave server in PgAdmin III (which executable is located on the master server), I get some errors like this:

invalid byte sequence for encoding “UTF8” plus some hex codes

enter image description here

It might be because I put a tilde ~ in the archive_cleanup_command, but it didn't worked, then I removed it and the command worked correctly.

Maybe that ~ has been written somewhere and it's not a valid char... but I also deleted logs...

Log of the slave server has a lot of lines like the followings:

2015-02-13 11:11:32 CET ERROR:  invalid byte sequence for encoding “UTF8”: 0xe8 0x20 0x73
2015-02-13 11:11:32 CET STATEMENT:  SELECT pg_file_read('pg_log/postgresql-2015-02-13_111038.log', 0, 50000)

Note that postgresql-2015-02-13_111038.log is the last log, the one from which I got these lines.

like image 634
Teejay Avatar asked Feb 13 '15 10:02

Teejay


1 Answers

The problem you have is that the locale setting lc_messages is set to an encoding that is different to the encoding of the database(s). As a result, some messages are being written into the log using Windows-1252 encoding, while when you try to use PgAdmin to view the log, it tries to interpret the file using UTF-8. Some of the byte sequences written in the log are not valid UTF-8, leading to the error.

In fact, the way in which different locales interact in postgresql can result in mixed encodings in the log file. There is a Bug Report on this, but it does not look like it has been resolved.

Probably the easiest way to resolve this is to set lc_messages to English_United States.UTF-8.

It would also be preferable to have lc_messages aligned across all of the databases on the server (or at least all using the same encoding).

Be sure to remove any existing log files as they will already contain the incorrect encoding.

like image 140
harmic Avatar answered Sep 29 '22 21:09

harmic