pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
6+ messages / 4 participants
[nested] [flat]

* BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
@ 2012-07-18 07:17 exclusion@gmail.com
  2012-07-18 07:21 ` Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 6+ messages in thread

From: exclusion@gmail.com @ 2012-07-18 07:17 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      6742
Logged by:          Alexander LAW
Email address:      exclusion@gmail.com
PostgreSQL version: 9.1.4
Operating system:   Windows
Description:        

When I try to dump database with UTF-8 encoding in Windows, I get unreadable
object names.
Please look at the screenshot (http://oi50.tinypic.com/2lw6ipf.jpg). On the
left window all the pg_dump messages displayed correctly (except for the
prompt password (bug #6510)), but the non-ASCII object name is gibberish. On
the right window (where dump is done with the Windows 1251 encoding (OS
Encoding for Russian locale)) everything is right.

It seems that pg_dump doesn't do necessary encoding conversion for the
object names.
For example, there is a code in pg_dump.c:
    write_msg(NULL, "finding the columns and types of table \"%s\"\n",
        tbinfo->dobj.name);
or in backup_archiver.c
    ahlog(AH, 1, "setting owner and privileges for %s %s\n",
        te->desc, te->tag);

And then it comes to the following function in dumputils.c:
void
vwrite_msg(const char *modulename, const char *fmt, va_list ap)
{
...
        vfprintf(stderr, _(fmt), ap);
}

So the format string goes through the translation and encoding conversion
(for the current OS locale), but tbinfo->dobj.name (or te->tag) does not.
I think it would be appropriate to convert all the obect names with some
function like dump_output_encoding_to_OS_encoding.

Best regards,
Alexander




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
  2012-07-18 07:17 BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding exclusion@gmail.com
@ 2012-07-18 07:21 ` Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 0 replies; 6+ messages in thread

From: Thomas Kellerer @ 2012-07-18 07:21 UTC (permalink / raw)
  To: pgsql-bugs

exclusion@gmail.com, 18.07.2012 09:17:
> The following bug has been logged on the website:
>
> Bug reference:      6742
> Logged by:          Alexander LAW
> Email address:      exclusion@gmail.com
> PostgreSQL version: 9.1.4
> Operating system:   Windows
> Description:
>
> When I try to dump database with UTF-8 encoding in Windows, I get unreadable
> object names.
> Please look at the screenshot (http://oi50.tinypic.com/2lw6ipf.jpg). On the
> left window all the pg_dump messages displayed correctly (except for the
> prompt password (bug #6510)), but the non-ASCII object name is gibberish. On
> the right window (where dump is done with the Windows 1251 encoding (OS
> Encoding for Russian locale)) everything is right.
>
Did you check the dump file using an editor that can handle UTF-8?
The Windows console is not known for properly handling that encoding.

Thomas






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
@ 2012-07-18 08:51 Alexander Law <exclusion@gmail.com>
  2012-07-18 15:05 ` Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
  2012-07-25 11:54 ` Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Alexander Law @ 2012-07-18 08:51 UTC (permalink / raw)
  To: pgsql-bugs

Hello,

The dump file itself is correct. The issue is only with the non-ASCII 
object names in pg_dump messages.
The messages text (which is non-ASCII too) displayed consistently with 
right encoding (i.e. with OS encoding thanks to libintl/gettext), but 
encoding of db object names depends on the dump encoding and thus 
they're getting unreadable when different encoding is used.
The same can be reproduced in Linux (where console encoding is UTF-8) 
when doing dump with Windows-1251 or Latin1 (for western european 
languages).

Thanks,
Alexander


    The following bug has been logged on the website:

    Bug reference:      6742
    Logged by:          Alexander LAW
    Email address:      exclusion(at)gmail(dot)com
    PostgreSQL version: 9.1.4
    Operating system:   Windows
    Description:

    When I try to dump database with UTF-8 encoding in Windows, I get unreadable
    object names.
    Please look at the screenshot (http://oi50.tinypic.com/2lw6ipf.jpg). On the
    left window all the pg_dump messages displayed correctly (except for the
    prompt password (bug #6510)), but the non-ASCII object name is gibberish. On
    the right window (where dump is done with the Windows 1251 encoding (OS
    Encoding for Russian locale)) everything is right.

Did you check the dump file using an editor that can handle UTF-8?
The Windows console is not known for properly handling that encoding.

Thomas

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
  2012-07-18 08:51 Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
@ 2012-07-18 15:05 ` Alexander Law <exclusion@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Alexander Law @ 2012-07-18 15:05 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; ringerc@ringerc.id.au; +Cc: yi.codeplayer@gmail.com

Hello!

May I to propose a solution and to step up?

I've read a discussion of the bug #5800 and here is my 2 cents.
To make things clear let me give an example.
I am a PostgreSQL hosting provider and I let my customers to create any databases they wish.
I have clients all over the world (so they can create databases with different encoding).

The question is - what I (as admin) want to see in my postgresql log, containing errors from all the databases?
IMHO we should consider two requirements for the log.
First, The file should be readable with a generic text viewer. Second, It should be useful and complete as possible.

Now I see following solutions.
A. We have different logfiles for each database with different encodings.
Then all our logs will be readable, but we have to look at them one by onе and it's inconvenient at least.
Moreover, our log reader should understand what encoding to use for each file.

B. We have one logfile with the operating system encoding.
First downside is that the logs can be different for different OSes.
The second is that Windows has non-Unicode system encoding.
And such an encoding can't represent all the national characters. So at best I will get ??? in the log.

C. We have one logfile with UTF-8.
Pros: Log messages of all our clients can fit in it. We can use any generic editor/viewer to open it.
Nothing changes for Linux (and other OSes with UTF-8 encoding).
Cons: All the strings written to log file should go through some conversation function.

I think that the last solution is the solution. What is your opinion?

In fact the problem exists even with a simple installation on Windows when you use non-English locale.
So the solution would be useful for many of us.

Best regards,
Alexander


On 05/23/2012 09:15 AM, yi huang wrote:
> I'm using postgresql 9.1.3 from debian squeeze-backports with
> zh_CN.UTF-8 locale, i find my main log (which is
> "/var/log/postgresql/postgresql-9.1-main.log") contains "???" which
> indicate some sort of charset encoding problem.

It's a known issue, I'm afraid. The PostgreSQL postmaster logs in the
system locale, and the PostgreSQL backends log in whatever encoding
their database is in. They all write to the same log file, producing a
log file full of mixed encoding data that'll choke many text editors.

If you force your editor to re-interpret the file according to the
encoding your database(s) are in, this may help.

In the future it's possible that this may be fixed by logging output to
different files on a per-database basis or by converting the text
encoding of log messages, but no agreement has been reached on the
correct approach and nobody has stepped up to implement it.

--
Craig Ringer




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
  2012-07-18 08:51 Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
@ 2012-07-25 11:54 ` Alexander Law <exclusion@gmail.com>
  2012-08-07 17:24   ` Re: Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Alexander Law @ 2012-07-25 11:54 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org

Hello,
I would like to fix this bug, but it looks like it would be not one-line 
patch.
Looking at the pg_dump code I see that the object names come through the 
following chain:
1. pg_dump executes 'SELECT c.tableoid, c.oid, c.relname, ... ' and gets 
the object_name with the encoding chosen for db connection/dump.
2. it invokes write_msg function or alike:
     write_msg(NULL, "finding the columns and types of table \"%s\"\n", 
tbinfo->dobj.name);
3. vwrite_msg localizes text message, but not the argument(s):
     vfprintf(stderr, _(fmt), ap);
Here gettext (_) internally translates fmt to OS encoding (if it's 
different from UTF-8 - encoding of a localized strings).

And I can see only a few solutions of the problem:
1. To convert the object name at the back-end, i.e. to modify all the 
similar SELECT's as:
'SELECT c.tableoid, c.oid, c.relname, convert_to(c.relname, 
'OS_ENCODING') AS locrelname, ...'
and then do     write_msg(NULL, "finding the columns and types of table 
\"%s\"\n", tbinfo->dobj.local_name);
The downside of this approach is that it requires rewriting all the 
SELECT's for all the object. And it doesn't help us to write out any 
other text from backend, such as localized backend error.

2. To setup another connection to backend with the OS encoding, and to 
get all the object names through it. It looks insane too. And we have 
the same problem with the localized backend errors coming on "main" 
connection.

3. To make convert_to_os_encoding(text, encoding) function for a 
frontend utilities. Unfortunately frontend can't use internal PostgreSQL 
conversion functions, and modifying them to use through libpq looks 
unfeasible.
So the only way to implement such function is to use another encoding 
conversion framework (library).
And my question is - is it possible to include libiconv (add this 
dependency) to the frontend utilities code?

4. To force users to use OS encoding as the Database encoding. Or to not 
use non-ASCII characters in an db object names and to disable nls on 
Windows completely. It doesn't look like a solution at all.

BTW, it's not the only one instance of the issue. For example, when I 
try to use vacuumdb, I get completely unreadable messages:
http://oi48.tinypic.com/1c8j9.jpg
(blue marks what is in Russian or English, all the other text is gibberish).

Best regards,
Alexander


18.07.2012 12:51, Alexander Law wrote:
> Hello,
>
> The dump file itself is correct. The issue is only with the non-ASCII 
> object names in pg_dump messages.
> The messages text (which is non-ASCII too) displayed consistently with 
> right encoding (i.e. with OS encoding thanks to libintl/gettext), but 
> encoding of db object names depends on the dump encoding and thus 
> they're getting unreadable when different encoding is used.
> The same can be reproduced in Linux (where console encoding is UTF-8) 
> when doing dump with Windows-1251 or Latin1 (for western european 
> languages).
>
> Thanks,
> Alexander
>
>
>     The following bug has been logged on the website:
>
>     Bug reference:      6742
>     Logged by:          Alexander LAW
>     Email address:      exclusion(at)gmail(dot)com
>     PostgreSQL version: 9.1.4
>     Operating system:   Windows
>     Description:
>
>     When I try to dump database with UTF-8 encoding in Windows, I get unreadable
>     object names.
>     Please look at the screenshot (http://oi50.tinypic.com/2lw6ipf.jpg). On the
>     left window all the pg_dump messages displayed correctly (except for the
>     prompt password (bug #6510)), but the non-ASCII object name is gibberish. On
>     the right window (where dump is done with the Windows 1251 encoding (OS
>     Encoding for Russian locale)) everything is right.
>
> Did you check the dump file using an editor that can handle UTF-8?
> The Windows console is not known for properly handling that encoding.
>
> Thomas
>
>
>
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding
  2012-07-18 08:51 Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
  2012-07-25 11:54 ` Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
@ 2012-08-07 17:24   ` Robert Haas <robertmhaas@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Robert Haas @ 2012-08-07 17:24 UTC (permalink / raw)
  To: Alexander Law <exclusion@gmail.com>; +Cc: pgsql-hackers@postgresql.org

On Wed, Jul 25, 2012 at 7:54 AM, Alexander Law <exclusion@gmail.com> wrote:
> Hello,
> I would like to fix this bug, but it looks like it would be not one-line
> patch.
> Looking at the pg_dump code I see that the object names come through the
> following chain:
> 1. pg_dump executes 'SELECT c.tableoid, c.oid, c.relname, ... ' and gets the
> object_name with the encoding chosen for db connection/dump.
> 2. it invokes write_msg function or alike:
>
>     write_msg(NULL, "finding the columns and types of table \"%s\"\n",
> tbinfo->dobj.name);
> 3. vwrite_msg localizes text message, but not the argument(s):
>     vfprintf(stderr, _(fmt), ap);
> Here gettext (_) internally translates fmt to OS encoding (if it's different
> from UTF-8 - encoding of a localized strings).
>
> And I can see only a few solutions of the problem:
> 1. To convert the object name at the back-end, i.e. to modify all the
> similar SELECT's as:
> 'SELECT c.tableoid, c.oid, c.relname, convert_to(c.relname, 'OS_ENCODING')
> AS locrelname, ...'
> and then do     write_msg(NULL, "finding the columns and types of table
> \"%s\"\n", tbinfo->dobj.local_name);
> The downside of this approach is that it requires rewriting all the SELECT's
> for all the object. And it doesn't help us to write out any other text from
> backend, such as localized backend error.
>
> 2. To setup another connection to backend with the OS encoding, and to get
> all the object names through it. It looks insane too. And we have the same
> problem with the localized backend errors coming on "main" connection.
>
> 3. To make convert_to_os_encoding(text, encoding) function for a frontend
> utilities. Unfortunately frontend can't use internal PostgreSQL conversion
> functions, and modifying them to use through libpq looks unfeasible.
> So the only way to implement such function is to use another encoding
> conversion framework (library).
> And my question is - is it possible to include libiconv (add this
> dependency) to the frontend utilities code?
>
> 4. To force users to use OS encoding as the Database encoding. Or to not use
> non-ASCII characters in an db object names and to disable nls on Windows
> completely. It doesn't look like a solution at all.

I think if you're going to try to do something about this, #1 is
probably the best option.

It does sound like a lot of work, though.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2012-08-07 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 07:17 BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding exclusion@gmail.com
2012-07-18 07:21 ` Thomas Kellerer <spam_eater@gmx.net>
2012-07-18 08:51 Re: BUG #6742: pg_dump doesn't convert encoding of DB object names to OS encoding Alexander Law <exclusion@gmail.com>
2012-07-18 15:05 ` Alexander Law <exclusion@gmail.com>
2012-07-25 11:54 ` Alexander Law <exclusion@gmail.com>
2012-08-07 17:24   ` Robert Haas <robertmhaas@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox