DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Preset Options

server_encoding

Shows the server (database) character set encoding.

  • Default: SQL_ASCII
  • Type: string
  • Applies: Read-only

In plain words

The encoding in which text is stored in this database, almost always UTF8. It is chosen when the database is created and cannot be changed afterwards; clients may use a different encoding and PostgreSQL converts.

For DBAs and operators

Set per database by CREATE DATABASE … ENCODING (default from template1, which initdb sets from --encoding or the locale). Each database can differ; this shows the one you are connected to. Changing it means dump and restore into a new database.

  • SQL_ASCII (what the pg_settings boot default shows) means "no encoding checks": bytes are stored as-is. Migrating such databases to UTF8 often fails on invalid byte sequences.
  • Conversion errors: ERROR: character with byte sequence 0xe2 0x82 0xac in encoding "UTF8" has no equivalent in encoding "LATIN1".
SELECT datname, pg_encoding_to_char(encoding), datcollate, datctype FROM pg_database;

How to change it

Fixed when PostgreSQL was built or the cluster was initialised. You can only read it.

See it in context

Logical structure

Related parameters

client_encoding lc_messages

All Preset Options parameters