I just did my first install of PostgreSQL 9.1 on Ubuntu 10.04.
note: I have done it a few times on Windows with an installer without issues.
After a bit of effort, I got it set up to connect remotely via pgAdminIII. However, I was really surprised after connecting to the db, that I got a warning about the encoding. The "postgres" database itself was created with "SQL_ASCII" encoding. Every time that I've installed on windows, it created the postgres DB with "UTF8" - which seems like it would be a lot better and would stop the warning message when opening up the database via pgAdminIII.
Is there something I did wrong? Is there an installation option/param to use to set the default encoding to use?
And is there anyway to fix this? I've read some things on the web that says that you need to dumb and restore to change the encoding of a database, but I'm not sure this is even possible on the postgres db. Is it?
Thanks for your help!
The answer provided by Erwin Brandstetter, was helpful, but for whatever reason, it didn't work for me. The reason is that I couldn't initdb to ever run. I kept getting a "bash: command not found" error when trying to run it with the locale. What I ended up doing was:
changing the locale of the OS. For me, this was:
Note: then I had to reboot the server. To confirm that it worked, just run:
with that set, I stopped and dropped the cluster:
note: main is the default cluster that got created for me (your cluster name might be different)
Again, I just recreated the cluster with the same name (main).
Note: because I picked the same cluster name (main), I had to go back and update my .conf files. For me, this specifically was postgres.conf and pg_hba.conf to re-enable remote access to the box. I'm not going to include how to do that here as there is lots of documentation on the web for this. But, if someone wants to edit this answer later to include it, that would be fine! :)
The relevant option is
--locale=locale
to the initdb command which initializes your database cluster. If you don't supply it explicitly it defaults to the system locale. (You probably run your Ubuntu on locale 'C'.)Read more about it in the excellent manual here.
In PostgreSQL you can still sneak in a database with different locale by basing a new database off
template0
instead of the defaulttempleate1
. I quote the manual here:But I'd rather recreate the database cluster with the desired locale. Much cleaner.
Edit: info about available locales
You can only use locales that are provided by the operating system. I quote the manual here:
Look at
locale-gen
in a Unix-system, if you want to use a locale that has not yet been generated. The important thing to understand is that multiple locales can be installed in your OS, but only one of them can be picked for system parameters likeLC_CTYPE
,LC_COLLATE
, etc. Look at the output oflocale
versuslocale -a
in the shell. Usually it is the same for all, set viaLC_ALL
.@David: What you did may have solved your problem, but you could have had that easier. Also, be aware that the environment variable
LANG
only provides the default for all locale settings. If any of them is set to something different,LANG
will be overridden. SetLC_ALL
to override any existing setting. Here is one of many sites in the web telling you more about that.To check all current locale settings of your database (cluster), run in your database:
Or more specifically:
Creating the database via initdb with the encoding option (-E or --encoding=) did the trick for me on Mac Os X Snow Leopard:
If you init the database this way it will create the database templates with the correct encoding also.
Refer to the initdb documentation here and the encoding documentation here to choose the correct encoding.