|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /proc/self/root/usr/share/doc/postgresql-8.1.9/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Localization</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.1.9 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Server Administration"
HREF="admin.html"><LINK
REL="PREVIOUS"
TITLE="Authentication problems"
HREF="client-authentication-problems.html"><LINK
REL="NEXT"
TITLE="Character Set Support"
HREF="multibyte.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2007-04-20T04:40:08"></HEAD
><BODY
CLASS="CHAPTER"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.1.9 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="client-authentication-problems.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="client-authentication.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="maintenance.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="multibyte.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="CHARSET"
></A
>Chapter 21. Localization</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>21.1. <A
HREF="charset.html#LOCALE"
>Locale Support</A
></DT
><DD
><DL
><DT
>21.1.1. <A
HREF="charset.html#AEN22060"
>Overview</A
></DT
><DT
>21.1.2. <A
HREF="charset.html#AEN22133"
>Behavior</A
></DT
><DT
>21.1.3. <A
HREF="charset.html#AEN22175"
>Problems</A
></DT
></DL
></DD
><DT
>21.2. <A
HREF="multibyte.html"
>Character Set Support</A
></DT
><DD
><DL
><DT
>21.2.1. <A
HREF="multibyte.html#MULTIBYTE-CHARSET-SUPPORTED"
>Supported Character Sets</A
></DT
><DT
>21.2.2. <A
HREF="multibyte.html#AEN22557"
>Setting the Character Set</A
></DT
><DT
>21.2.3. <A
HREF="multibyte.html#AEN22591"
>Automatic Character Set Conversion Between Server and Client</A
></DT
><DT
>21.2.4. <A
HREF="multibyte.html#AEN22901"
>Further Reading</A
></DT
></DL
></DD
></DL
></DIV
><P
> This chapter describes the available localization features from the
point of view of the administrator.
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> supports localization with
two approaches:
<P
></P
></P><UL
><LI
><P
> Using the locale features of the operating system to provide
locale-specific collation order, number formatting, translated
messages, and other aspects.
</P
></LI
><LI
><P
> Providing a number of different character sets defined in the
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> server, including
multiple-byte character sets, to support storing text in all
kinds of languages, and providing character set translation between
client and server.
</P
></LI
></UL
><P>
</P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LOCALE"
>21.1. Locale Support</A
></H1
><A
NAME="AEN22054"
></A
><P
> <I
CLASS="FIRSTTERM"
>Locale</I
> support refers to an application respecting
cultural preferences regarding alphabets, sorting, number
formatting, etc. <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> uses the standard ISO
C and <ACRONYM
CLASS="ACRONYM"
>POSIX</ACRONYM
> locale facilities provided by the server operating
system. For additional information refer to the documentation of your
system.
</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN22060"
>21.1.1. Overview</A
></H2
><P
> Locale support is automatically initialized when a database
cluster is created using <TT
CLASS="COMMAND"
>initdb</TT
>.
<TT
CLASS="COMMAND"
>initdb</TT
> will initialize the database cluster
with the locale setting of its execution environment by default,
so if your system is already set to use the locale that you want
in your database cluster then there is nothing else you need to
do. If you want to use a different locale (or you are not sure
which locale your system is set to), you can instruct
<TT
CLASS="COMMAND"
>initdb</TT
> exactly which locale to use by
specifying the <TT
CLASS="OPTION"
>--locale</TT
> option. For example:
</P><PRE
CLASS="SCREEN"
>initdb --locale=sv_SE</PRE
><P>
</P
><P
> This example sets the locale to Swedish (<TT
CLASS="LITERAL"
>sv</TT
>) as spoken
in Sweden (<TT
CLASS="LITERAL"
>SE</TT
>). Other possibilities might be
<TT
CLASS="LITERAL"
>en_US</TT
> (U.S. English) and <TT
CLASS="LITERAL"
>fr_CA</TT
> (French
Canadian). If more than one character set can be useful for a
locale then the specifications look like this:
<TT
CLASS="LITERAL"
>cs_CZ.ISO8859-2</TT
>. What locales are available under what
names on your system depends on what was provided by the operating
system vendor and what was installed. (On most systems, the command
<TT
CLASS="LITERAL"
>locale -a</TT
> will provide a list of available locales.)
</P
><P
> Occasionally it is useful to mix rules from several locales, e.g.,
use English collation rules but Spanish messages. To support that, a
set of locale subcategories exist that control only a certain
aspect of the localization rules:
<DIV
CLASS="INFORMALTABLE"
><P
></P
><A
NAME="AEN22076"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><TBODY
><TR
><TD
><TT
CLASS="ENVAR"
>LC_COLLATE</TT
></TD
><TD
>String sort order</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_CTYPE</TT
></TD
><TD
>Character classification (What is a letter? Its upper-case equivalent?)</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_MESSAGES</TT
></TD
><TD
>Language of messages</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_MONETARY</TT
></TD
><TD
>Formatting of currency amounts</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_NUMERIC</TT
></TD
><TD
>Formatting of numbers</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_TIME</TT
></TD
><TD
>Formatting of dates and times</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
The category names translate into names of
<TT
CLASS="COMMAND"
>initdb</TT
> options to override the locale choice
for a specific category. For instance, to set the locale to
French Canadian, but use U.S. rules for formatting currency, use
<TT
CLASS="LITERAL"
>initdb --locale=fr_CA --lc-monetary=en_US</TT
>.
</P
><P
> If you want the system to behave as if it had no locale support,
use the special locale <TT
CLASS="LITERAL"
>C</TT
> or <TT
CLASS="LITERAL"
>POSIX</TT
>.
</P
><P
> The nature of some locale categories is that their value has to be
fixed for the lifetime of a database cluster. That is, once
<TT
CLASS="COMMAND"
>initdb</TT
> has run, you cannot change them anymore.
<TT
CLASS="LITERAL"
>LC_COLLATE</TT
> and <TT
CLASS="LITERAL"
>LC_CTYPE</TT
> are
those categories. They affect the sort order of indexes, so they
must be kept fixed, or indexes on text columns will become corrupt.
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> enforces this by recording
the values of <TT
CLASS="ENVAR"
>LC_COLLATE</TT
> and <TT
CLASS="ENVAR"
>LC_CTYPE</TT
> that are
seen by <TT
CLASS="COMMAND"
>initdb</TT
>. The server automatically adopts
those two values when it is started.
</P
><P
> The other locale categories can be changed as desired whenever the
server is running by setting the run-time configuration variables
that have the same name as the locale categories (see <A
HREF="runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT"
>Section 17.10.2</A
> for details). The defaults that are
chosen by <TT
CLASS="COMMAND"
>initdb</TT
> are actually only written into
the configuration file <TT
CLASS="FILENAME"
>postgresql.conf</TT
> to
serve as defaults when the server is started. If you delete these
assignments from <TT
CLASS="FILENAME"
>postgresql.conf</TT
> then the
server will inherit the settings from its execution environment.
</P
><P
> Note that the locale behavior of the server is determined by the
environment variables seen by the server, not by the environment
of any client. Therefore, be careful to configure the correct locale settings
before starting the server. A consequence of this is that if
client and server are set up in different locales, messages may
appear in different languages depending on where they originated.
</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
> When we speak of inheriting the locale from the execution
environment, this means the following on most operating systems:
For a given locale category, say the collation, the following
environment variables are consulted in this order until one is
found to be set: <TT
CLASS="ENVAR"
>LC_ALL</TT
>, <TT
CLASS="ENVAR"
>LC_COLLATE</TT
>
(the variable corresponding to the respective category),
<TT
CLASS="ENVAR"
>LANG</TT
>. If none of these environment variables are
set then the locale defaults to <TT
CLASS="LITERAL"
>C</TT
>.
</P
><P
> Some message localization libraries also look at the environment
variable <TT
CLASS="ENVAR"
>LANGUAGE</TT
> which overrides all other locale
settings for the purpose of setting the language of messages. If
in doubt, please refer to the documentation of your operating
system, in particular the documentation about
<SPAN
CLASS="APPLICATION"
>gettext</SPAN
>, for more information.
</P
></BLOCKQUOTE
></DIV
><P
> To enable messages to be translated to the user's preferred language,
<ACRONYM
CLASS="ACRONYM"
>NLS</ACRONYM
> must have been enabled at build time. This
choice is independent of the other locale support.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN22133"
>21.1.2. Behavior</A
></H2
><P
> The locale settings influence the following SQL features:
<P
></P
></P><UL
><LI
><P
> Sort order in queries using <TT
CLASS="LITERAL"
>ORDER BY</TT
> on textual data
<A
NAME="AEN22140"
></A
>
</P
></LI
><LI
><P
> The ability to use indexes with <TT
CLASS="LITERAL"
>LIKE</TT
> clauses
<A
NAME="AEN22146"
></A
>
</P
></LI
><LI
><P
> The <CODE
CLASS="FUNCTION"
>upper</CODE
>, <CODE
CLASS="FUNCTION"
>lower</CODE
>, and <CODE
CLASS="FUNCTION"
>initcap</CODE
>
functions
<A
NAME="AEN22154"
></A
>
<A
NAME="AEN22157"
></A
>
</P
></LI
><LI
><P
> The <CODE
CLASS="FUNCTION"
>to_char</CODE
> family of functions
<A
NAME="AEN22163"
></A
>
</P
></LI
></UL
><P>
</P
><P
> The drawback of using locales other than <TT
CLASS="LITERAL"
>C</TT
> or
<TT
CLASS="LITERAL"
>POSIX</TT
> in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is its performance
impact. It slows character handling and prevents ordinary indexes
from being used by <TT
CLASS="LITERAL"
>LIKE</TT
>. For this reason use locales
only if you actually need them.
</P
><P
> As a workaround to allow <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> to use indexes
with <TT
CLASS="LITERAL"
>LIKE</TT
> clauses under a non-C locale, several custom
operator classes exist. These allow the creation of an index that
performs a strict character-by-character comparison, ignoring
locale comparison rules. Refer to <A
HREF="indexes-opclass.html"
>Section 11.8</A
>
for more information.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN22175"
>21.1.3. Problems</A
></H2
><P
> If locale support doesn't work in spite of the explanation above,
check that the locale support in your operating system is
correctly configured. To check what locales are installed on your
system, you may use the command <TT
CLASS="LITERAL"
>locale -a</TT
> if
your operating system provides it.
</P
><P
> Check that <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is actually using the locale
that you think it is. <TT
CLASS="ENVAR"
>LC_COLLATE</TT
> and <TT
CLASS="ENVAR"
>LC_CTYPE</TT
>
settings are determined at <TT
CLASS="COMMAND"
>initdb</TT
> time and cannot be
changed without repeating <TT
CLASS="COMMAND"
>initdb</TT
>. Other locale
settings including <TT
CLASS="ENVAR"
>LC_MESSAGES</TT
> and <TT
CLASS="ENVAR"
>LC_MONETARY</TT
>
are initially determined by the environment the server is started
in, but can be changed on-the-fly. You can check the active locale
settings using the <TT
CLASS="COMMAND"
>SHOW</TT
> command.
</P
><P
> The directory <TT
CLASS="FILENAME"
>src/test/locale</TT
> in the source
distribution contains a test suite for
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s locale support.
</P
><P
> Client applications that handle server-side errors by parsing the
text of the error message will obviously have problems when the
server's messages are in a different language. Authors of such
applications are advised to make use of the error code scheme
instead.
</P
><P
> Maintaining catalogs of message translations requires the on-going
efforts of many volunteers that want to see
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> speak their preferred language well.
If messages in your language are currently not available or not fully
translated, your assistance would be appreciated. If you want to
help, refer to <A
HREF="nls.html"
>Chapter 45</A
> or write to the developers'
mailing list.
</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="client-authentication-problems.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="multibyte.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Authentication problems</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="admin.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Character Set Support</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>