Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When you create a new postgresql cluster you can specify an encoding for the cluster, but I'm not sure to know how to retrieve it once the cluster has been created.

I have seen that with \encoding you can see an encoding, but I don't know it this is the encoding of the cluster or the encoding of the client.

I have also seen that with \l I can see the encoding used by each database.

And SHOW server_encoding shows another encoding.

What is the correct way to query for the value using during initialization?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Each database in a cluster can have its own encoding, although this probably isn't useful for most people.

When you create the cluster, the encoding you specify is used for the template1 and postgres databases, so it is the default for all new ones. You can create a new database from template0 in a different encoding, though.

\encoding shows the encoding used for the client<->server communication protocol, and is equivalent to show client_encoding. server_encoding shows the encoding used for the database you are currently connected to. It should show the encoding used to create the cluster if you are connected to template1. The encoding for each database is listed in pg_database, e.g.: should

select datname, pg_encoding_to_char(encoding) from pg_database
share|improve this answer

You could use pg_controldata: pg_controldata <path/to/cluster> |grep LC_ where the path is where your cluster is located.

This will output something similar like this:

LC_COLLATE: en_US.UTF-8

LC_CTYPE: en_US.UTF-8

share|improve this answer
    
Anyone have an explanation for the down vote? –  Levi Jan 6 '12 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.