PostgreSQL is a free and open source Object-Relational Database Management System (ORDBMS). This post demonstrate how to install and configure PostgreSQL 12.02 Latest version on Debian Linux 10 (Buster) using Source Code.
Prerequisites:
2. Sudo or superuser access
3. Internet to download package
4. GNU Readline library
5. GCC
Follow below steps to install GCC
$ sudo apt update
$ sudo apt install build-essential
$ sudo apt-get install manpages-dev
How to check GCC version.
$ gcc –version
6. zlib compression library
Note: You may ask for Debian 10 Buster DVD or ISO file.
Mount ISO file with below command if required.
$ sudo mount -o loop /tmp/debian-10.2.0-amd64-DVD-1.iso /media/cdrom
Mount ISO file with below command if required.
$ sudo mount -o loop /tmp/debian-10.2.0-amd64-DVD-1.iso /media/cdrom
Let’s start Installation of PostgreSQL on Debian Linux 10 (Buster).
$ sudo wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.gz
Step 2 – Extract the downloaded package
Go to the directory and untar the downloaded file and postgresql-12.2 (Future release versions might differ) directory will be created.
$ sudo tar -zxvf postgresql-12.2.tar.gz
Step 3 – Go to the new created postgresql-12.2 directory where you have extracted the PostgreSQL package and configure the source with below command.
$ ./configure
Step 4 – Build the process by executing the command below. (After executing “sudo make install” at the end you will see message “PostgreSQL Installation complete” as shown below screenshot).
$ sudo make
$ sudo make install
Step 5 – Create Super-user account.
Create a super-user account for PostgreSQL by executing the following command.
Step 6 – Create a directory to hold PostgreSQL data tree.
In the following, “data” directory will be created and ownership will be changed to “postgres”. Login with “postgres” user created previous step.
$ mkdir /usr/local/pgsql/data
$ chown postgres /usr/local/pgsql/data
$ su – postgres
Step 7 – Create PostgreSQL cluster by executing below command.
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
Step 8 – Start the PostgreSQL server executing command below:
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Step 9 – PostgreSQL listen on port 5432. Verify listening port with below command.
Allow port 5432 if UFW firewall is active.
$ sudo ufw allow 5432/tcp
Step 10 – Create a PostgreSQL database called “teclues” and login with following command.
$ /usr/local/pgsql/bin/createdb teclues
$ /usr/local/pgsql/bin/psql teclues
Step 11 – List databases from PostgreSQL console.
teclues=# l
Step 12 – Login and check the version of PostgreSQL.
$ /usr/local/pgsql/bin/psql
Step 13 – You can get help on the syntax of various PostgreSQL SQL commands by typing “h” from PostgreSQL prompt. To quit from psql, type “q” from PostgreSQL prompt.
Conclusion:
In this post, we have learned how to install PostgreSQL using source code on Debian Linux 10 (Buster). Please share it with others and Like Our Facebook Page.