Saturday, May 27, 2017

Linux: How to Install PostgreSQL on Debian 8 Jessie




PostgreSQL is one of the leading object-relational DBMS in the market of database. One of the most interesting about PostgreSQL over MySQL is because of many supported data types. Some of these data types are network addresses, mapping coordinates, shapes etc. In this tutorial we are going to install PostgreSQL on Debian 8 Jessie. 

1. Update your system. Before we install PostgreSQL, we need to update our system. 

sudo apt-get update


2. Add this line deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main  to the bottom of  /etc/apt/sources.list . After adding the codes bellow, save it to commit changes on our repository. Take note that I'm using vi for editing files. But you can also use other editing tools such as nano and pico. Either of them will mostly work.

 deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main



3. Download and Import the repository signing key. In this step, we are going to import our key on the system so that you can validate you have got the right package from the postgresql repository. By using wget, we are downloading the key to our server and the apt-key command add the key to our system. 

wget https://www.postgresql.org/media/keys/ACCC4CF8.asc
apt-key add ACCC4CF8.asc

Download the key
Add the key


4. Update the System. We need to update again to know that we want to install postgresql and want to add it in repository so that if we use the command apt-get update, the postgresql repository will also update its version if updates are available.

apt-get update




5. Install PostgreSQL. But it will get an error. to fix this, we will add some lines of code in our repository list. If there is no error in your terminal, you can skip step 6 and proceed to step 8 and continue. 

Installing posgresql - Error

6. Add this below to your repository in  /etc/apt/sources.list. Most of the packages that we need are in the repository ftp of debian. Deb indicates the binary packages, and deb-src indicates source packages, debian control files and changes to the files on the packages. 

deb http://ftp.de.debian.org/debian/ jessie main non-free contrib
deb-src http://ftp.de.debian.org/debian/ jessie main non-free contrib



7. Update the system. Again we need to update the system to take effect the changes the we save earlier. 

apt-get update




8. You can now install postgresql without any error. After installing the postgresl, we can now test the postgresql if we installed it properly. We use su -postgres to change our user from root to postgres because postgres user only has the access to postgresql. After that we can now use the command psql. We can type help if we need help in some syntax and commands. 

apt-get install postgresql-9.6
su - postgres
psql

Start of Installation
Installation Complete
Some postgres command

No comments:

Post a Comment