6

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?

8

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
-1

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

1
  • Anyone have an explanation for the down vote?
    – Levi
    Jan 6 '12 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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