Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id EC9C96502FB for ; Fri, 29 Aug 2008 16:45:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56753-05 for ; Fri, 29 Aug 2008 16:44:53 -0300 (ADT) X-Greylist: delayed 00:38:10.240583 by SQLgrey-1.7.6 Received: from nazgul.esiway.net (Nazgul.esiway.net [193.194.16.154]) by postgresql.org (Postfix) with ESMTP id 0DD846502EC for ; Fri, 29 Aug 2008 16:44:54 -0300 (ADT) Received: from Megathlon.ESI (Ghost.esi.it [193.194.16.225]) by nazgul.esiway.net (8.13.8/8.13.8) with ESMTP id m7TJ6aPM016289 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Aug 2008 21:06:36 +0200 Received: from themule.home.lan (themule.ESI [10.10.10.42]) by Megathlon.ESI (8.14.1/8.14.1) with ESMTP id m7TJ6XD1014628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 29 Aug 2008 21:06:34 +0200 Message-ID: <48B848B9.4040805@esiway.net> Date: Fri, 29 Aug 2008 21:06:33 +0200 From: Marco Colombo User-Agent: Thunderbird 2.0.0.14 (X11/20080501) MIME-Version: 1.0 To: Phoenix Kiula CC: Andrew Sullivan , pgsql-general@postgresql.org Subject: Re: Dumping/Restoring with constraints? References: <48B5BC2A.5070104@wildenhain.de> <20080828174712.GB27283@commandprompt.com> <20080829133436.GG29463@commandprompt.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded STARTTLS authentication, not delayed by milter-greylist-3.0 (nazgul.esiway.net [193.194.16.131]); Fri, 29 Aug 2008 21:06:37 +0200 (CEST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/1126 X-Sequence-Number: 136956 Phoenix Kiula wrote: > Thanks Andrew. > > On the server (the DB to be dumped) everything is "UTF8". > > On my home server (where I would like to mirror the DB), this is the output: > > > =# \l > List of databases > Name | Owner | Encoding > -----------+-----------------+----------- > postgres | postgres | SQL_ASCII > pkiula | pkiula_pkiula | UTF8 > template0 | postgres | SQL_ASCII > template1 | postgres | SQL_ASCII > (4 rows) > > > > This is a fresh install as you can see. The database into which I am > importing ("pkiula") is in fact listed as UTF8! Is this not enough? > You said you're getting these errors: ERROR: invalid byte sequence for encoding "UTF8": 0x80 those 0x80 bytes are inside the mydb.sql file, you may find it easier to look for them there and identify the offending string(s). Try (on the linux machine): zcat mydb.sql.gz | iconv -f utf8 > /dev/null should tell you something like: illegal input sequence at position xxx BTW, 0x80 is usually found in windows encoding, such as windows-1250, where it stands for the EURO symbol: echo -n "€" | iconv -t windows-1250 | hexdump -C 00000000 80 |.| 00000001 FYI, you *can* get non UTF-8 data from an UTF-8 database, if (and only if) your client encoding is something different (either because you explicitly set it so, or because of your client defaults). Likewise, you can insert non UTF-8 data (such as your mydb.sql) into an UTF-8 database, provided you set your client encoding accordingly. PostgreSQL clients handle encoding conversions, but there's no way to guess (reliabily) the encoding of a text file. OTOH, from a SQL_ASCII database you can get all sort of data, even mixed encoding text (which you need to fix somehow). If your mydb.sql contains data from a SQL_ASCII database, you simply know nothing about the encoding. I have seen SQL_ASCII databases containg data inserted from HTTP forms, both in UTF-8 and windows-1250 encoding. Displaying, dumping, restoring that correctly is impossible, you need to fix it somehow before processing it as text. .TM.