How can I query the encoding of a postgresql cluster?
Solution 1:
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