Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a database that I need to know what's the default encoding for the database

share|improve this question

4 Answers 4

up vote 36 down vote accepted

psql my_database -c 'SHOW SERVER_ENCODING'

share|improve this answer
3  
If you're already logged in and viewing a database after a psql ... show server_encoding; works fine as well. –  Meredith Jul 11 '13 at 18:00

If you want to get database encodings:

psql  -U postgres -h somehost --list

You'll see something like:

List of databases
           Name         |  Owner   | Encoding
------------------------+----------+----------
db1                     | postgres | UTF8
share|improve this answer

A programmatic solution:

SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'yourdb';
share|improve this answer

If you're already logged in, this will also work

SHOW SERVER_ENCODING;

Result:

server_encoding

UTF8

For Client encoding :

SHOW CLIENT_ENCODING;

share|improve this answer

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.