Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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:



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

Your Answer


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.