Windows, Linux, psql…

As for me I’m pretty sure that it’s not cool to use non-Latin letters for database objects names. In other words this is true Mauvais Ton.

However the reality dictates its own rules. I saw a lot of databases with names in Hebrew, Russian etc. What is the disadvantage of such names using?

Linux console

If we’re talking about Linux console then the answer most likely will be: “There is no disadvantage at all”, though I haven’t every existing distributive tested, but only a few. In this article we will use pg_live – a Xubuntu-based live CD designed and optimized expressly for the PostgreSQL Database administrator and enthusiast.

Let’s create database with Cyrillic letters under gorgeous name of “Колбаса”. First of all start psql. You may use such command:

$psql -h /tmp -U ubuntu ubuntu

After psql started we’ll create and connect to “Колбаса” database:

Creating database with Cyrillic letters in Ubuntu

Creating database with Cyrillic letters in Ubuntu

As you can see no magic is needed. In Windows it’s quite the contrary.

Windows console

Just for information: I’m using WinXP with SP3 installed.

Let’s the wizardry begin.  First of all we must set code page used in the Windows console :

C:\Program Files\PostgreSQL\8.3\bin\>chcp 1251
Active code page: 1251

Could not find this for three days, was cursing up hill and down dale. But it turnes out the only thing needed is the Notes for Windows users chapter in the psql manual.

Do not forget to set Lucida Console font either:

Setting Lucida Console font

Setting Lucida Console font

Starting psql:

C:\Program Files\PostgreSQL\8.3\bin\>psql -U pasha "Test"
Welcome to psql 8.3.5, the PostgreSQL interactive terminal.
Type:  copyright for distribution terms
       h for help with SQL commands
       ? for help with psql commands
       g or terminate with semicolon to execute query
       q to quit


Creating database:

Test=# CREATE DATABASE "Колбаса";
Test=# l
          List of databases
       Name       | Owner | Encoding
 Comments         | pasha | UTF8
 DBDEMOS          | pasha | UTF8
 Test             | pasha | UTF8
 UTF8             | pasha | UTF8
 huy              | pasha | UTF8
 postgres         | pasha | UTF8
 template0        | pasha | UTF8
 template1        | pasha | UTF8
 template_postgis | pasha | UTF8
 Колбаса          | pasha | UTF8
(10 rows)

Connecting to just created database:

Test=# c "Колбаса"
FATAL:  database "Колбаса" does not exist
Previous connection kept

Oops! Houston, we have a problem.

Checking encoding parameters:

Test=# SHOW client_encoding;
(1 row)

Test=# SHOW server_encoding;
(1 row)

Can we at least drop it?

Test=# DROP DATABASE "Колбаса";

May be I’m stupid, however I didn’t find a way to connect to “Колбаса” database using psql.

One thought on “Windows, Linux, psql…

  1. Pingback: Meet the PaGoDump « Pasha Golub’s Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s