I'm trying to optimize my PostgreSQL 8.3 DB tables to the best of my ability, and I'm unsure if I need to use varchar_pattern_ops
for certain columns where I'm performing a LIKE
against the first N characters of a string. According to this documentation, the use of xxx_pattern_ops
is only necessary "...when the server does not use the standard 'C' locale".
Can someone explain what this means? How do I check what locale my database is using?
Locale support refers to an application respecting cultural preferences regarding alphabets, sorting, number formatting, etc. PostgreSQL uses the standard ISO C and POSIX locale facilities provided by the server operating system.
Connecting to Your Database The PostgreSQL database service is available on localhost and the default PostgreSQL port is 5432 . A default user ( hosting-db ) and database ( postgres ) exist so you can quickly test your connection and perform management tasks.
Now that Postgres is running locally, we can connect to it via a “client” – a graphical or command-line interface that enables us to connect to the Postgres server, write and execute SQL commands as input, and see the resulting output.
Currently some locale [docs] support can only be set at initdb time, but I think the one relevant to _pattern_ops
can be modified via SET at runtime, LC_COLLATE. To see the set values you can use the SHOW command.
For example:
SHOW LC_COLLATE
_pattern_ops
indexes are useful in columns that use pattern matching constructs, like LIKE
or regexps. You still have to make a regular index (without _pattern_ops
) to do equality search on an index. So you have to take all this into consideration to see if you need such indexes on your tables.
About what locale is, it's a set of rules about character ordering, formatting and similar things that vary from language/country to another language/country. For instance, the locale fr_CA (French in Canada) might have some different sorting rules (or way of displaying numbers and so on) than en_CA (English in Canada.). The standard "C" locale is the POSIX standards-compliant default locale. Only strict ASCII characters are valid, and the rules of ordering and formatting are mostly those of en_US (US English)
In computing, locale is a set of parameters that defines the user's language, country and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language identifier and a region identifier.
psql -l
according to handbook
example output:
List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -------------+--------+----------+-------------+-------------+------------------- packrd | packrd | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | packrd | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | packrd | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/packrd + | | | | | packrd=CTc/packrd template1 | packrd | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/packrd + | | | | | packrd=CTc/packrd (5 rows)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With