The default clean installation of Snow Leopard uses the en_US.us-ascii locale. Unfortunately, when installing postgresql 8.3 using macports, the installer will complain when initializing the database, for example:

sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb 
-D /opt/local/var/db/postgresql83/defaultdb'

You will get the following error

The database cluster will be initialized with locale en_US.us-ascii.
could not determine encoding for locale "en_US.us-ascii": codeset is "us-ascii" 
initdb: could not find suitable encoding for locale en_US.us-ascii
Rerun initdb with the -E option.
Try "initdb --help" for more information.

The solution is to change the locale. First we list the locales available:

Outrun:db rdegraci$ locale -a | grep en_US
en_US
en_US.ISO8859-1
en_US.ISO8859-15
en_US.US-ASCII
en_US.UTF-8

Now we set the locale to en_US.UTF-8

Outrun:~ rdegraci$ export LC_ALL=en_US.UTF-8
Now start the server
Outrun:~ rdegraci$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb 
-D /opt/local/var/db/postgresql83/defaultdb'
You should get the following output
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

fixing permissions on existing directory /opt/local/var/db/postgresql83/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 1600kB/20000
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql83/defaultdb/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

Leave a Reply