As you know, at the end of September 2016, PostgreSQL version 9.6 was released.
In this article you will find the installation steps of PostgreSQL 9.6 on a minimal Debian 8.x (Jessie).
In addition, we will create a database with Turkish support. You can configure it to support your own language.
Since PostgreSQL supports UTF-8, you can store characters in any language in the database.
However, some special situations may occur according to languages.
For example, The upper case of the ”i“ in Turkish is ”İ” and the upper case of the “i” in English is “I”.
This means that the output of the various functions will be different according to the language. In PostgreSQL, these settings are made when creating a database. (different language support can be used in the same database, but I won’t go into this detail)
Precondition
This article begins by assuming that a minimal Jessie installation with ssh support is performed and you have root privileges.
In addition, a shell editor such as vim / nano should be available. I’ll use vim in the article.
Installation
Debian Language settings
First, let’s check whether the default locale of our operating system and Turkish locale are installed or not.
If you do not have Turkish locale, let’s install it. To check the default locale;
1 2 |
root@JESSIE:/home/sahap# echo $LANG en_US.UTF-8 |
Our default language is en_US.UTF-8 We note this and continue with the following command.
1 |
dpkg-reconfigure locales |
Let’s make sure that “[*] tr_TR.UTF-8 UTF-8” is selected (you can select it with space) and press <OK> (you can switch to Tab).
We’ve already looked at what was the default locale. We continue our way of choosing it. The purpose of this is to keep the language settings of the services that are already running. In our case this was en_US.UTF-8
When you press <OK>, the result should be as follows. Thus, we are sure that there is Turkish language support in our operating system.
1 2 3 4 5 |
root@JESSIE:/home/sahap# dpkg-reconfigure locales Generating locales (this might take a while)... en_US.UTF-8... done tr_TR.UTF-8... done Generation complete. |
PostgreSQL Installion:
We already have PostgreSQL packages in Debian, but because we want to install a higher version of PostgreSQL, we use PostgreSQL’s own repository.
In our case, Jessie comes with version 9.4 of PostgreSQL but we want to install version 9.6.
Let’s add our repository;
1 |
vim /etc/apt/sources.list.d/pgdg.list |
Then we write the following line into the document. This way, Jessie also checks the URL we provide when searching for available packages.
1 |
deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main |
Save and exit;
We add the key of Repository to reliable keys.
1 |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - |
We are updating the package list;
1 |
apt-get update |
Let’s install PostgreSQL; Let’s continue by saying ‘Y’ to the question;
1 |
apt-get install postgresql-9.6 |
The following information gives us information about where our data files are located.
1 2 3 4 5 6 |
Creating new cluster 9.6/main ... config /etc/postgresql/9.6/main data /var/lib/postgresql/9.6/main locale en_US.UTF-8 socket /var/run/postgresql port 5432 |
Our configuration files are in “/etc/postgresql/9.6/main” and our data files are in “/var/lib/postgresql/9.6/main”.
These are the default settings and can be changed as desired. We’re not going into that detail for now.
Let’s check that our PostgreSQL service is running;
1 |
systemctl status postgresql |
How To Create a Database With Turkish Language?(or your own language)
We have installed PostgreSQL. Now we can create the database into it.
Because our operating system’s default locale is en_US.UTF-8, PostgreSQL has created a cluster in the default language.
If we create a new database without providing a parameter, the database will be created according to the default locale (en_US.UTF-8 locale).
If our default language in our operating system was tr_TR.UTF-8, then it wasn’t necessary.
Because most operating systems are in English, we need to check them.
Let’s log into PostgreSQL;
There are several ways. One of them is to log in with the postgres user created during the installation. First we switch to the postgres user. then connect to the database using psql.
1 2 |
su postgres psql |
Lets create the database;
1 2 3 4 5 |
CREATE DATABASE testdb WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'tr_TR.UTF-8' LC_CTYPE = 'tr_TR.UTF-8'; |
You can connect to the newly created database by using the command “\ c testdb”.
1 2 3 |
postgres=# \c testdb You are now connected to database "testdb" as user "postgres". testdb=# |
Let’s test the Turkish characters and their order;
1 2 3 4 5 6 7 |
SELECT harf, upper(harf) FROM ( VALUES ('ş'), ('t'), ('u'), ('a'), ('n'), ('o'), ('ö'), ('p'), ('f'), ('g'), ('ğ'), ('h'), ('ı'), ('i'), ('j' ), ('k'), ('l'), ('m'), ('ü'), ('v'), ('r'), ('s'), ('b'), ('c'), ('ç'), ('d'), ('e'), ('y'), ('z')) AS alfabe(harf) ORDER BY 1; |
Our Turkish database is ready. You can create a database that supports your own language by making minor changes.
We have not yet made the necessary settings to access the postgreSQL server from another computer. We only access it from the computer where it is installed. In another article, we will go into details about access.