In this post, we will see how to Install and Run PostgreSQL on Linux machines.
There are three ways to installation procedures to download the software.
1. Binary Installation
2. Yum Installation
3. RPM Installation
In this post, will see how to install PostgreSQL using Binary installation.
1. Download the binaries from the official website.
pg_ctl - pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server
6. After successfully initializing the data directory, we need to start the server using the below command.
Note: When logging to the server for the first time you won't have any access enabled. To enable the access do below steps:
9. And, finally to shutdown database use below commands.
There are three ways to installation procedures to download the software.
1. Binary Installation
2. Yum Installation
3. RPM Installation
In this post, will see how to install PostgreSQL using Binary installation.
1. Download the binaries from the official website.
$ wget https://get.enterprisedb.com/postgresql/postgresql-9.6.2-4-linux-x64-binaries.tar.gz
2. Untar the downloaded binaries.$ tar -xvzf postgresql-9.6.2-4-linux-x64-binaries.tar.gz
3. Create appropriate data directories and permissions with root user to run PostgreSQL Server.# mkdir -p /var/lib/pgsql/data
# chown -R psql /var/lib/pgsql/data
# su psql
4. Now change the directory path to the downloaded software path$ cd /home/psql/softwares/pgsql
5. Initialize the data directories required for PostgreSQL to run, there are two ways to initialize the directories.$ initdb -D /usr/local/pgsql/data
Alternatively, we can also initialize using pg_ctlpg_ctl - pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server
$ pg_ctl -D /usr/local/pgsql/data initdb
$ /home/psql/softwares/pgsql/bin/pg_ctl -D /var/lib/pgsql/data -l logfile start
7. Before login into the shell, create a test database to loginNote: When logging to the server for the first time you won't have any access enabled. To enable the access do below steps:
$ cd /home/psql/softwares/pgsql/bin/ $ ./psql template1 psql.bin (9.6.2) Type "help" for help. template1=# CREATE DATABASE mydb; CREATE DATABASE
8. Once the database is created you can login using the database which you have created like below.
$psql mydb
psql.bin (9.6.2)
Type "help" for help.
mydb=#
mydb=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit
(1 row)
mydb=# select current_date;
date
------------
2017-05-04
(1 row)
mydb=# select 5 + 5;
?column?
----------
10
(1 row)
mydb=# \q
$ /home/psql/softwares/pgsql/bin/pg_ctl -D /var/lib/pgsql/data -l logfile stop
waiting for server to shut down.... done
server stopped
So, that's it for this post, will have a look at other two installations in the coming posts.
How do you make it to auto start on os boot
ReplyDeleteAnd thank you for the good article
ReplyDeleteThanks for the comment.
ReplyDeleteSEGA TINOHORE SEGA TINOHORE SEGA TINOHORE
ReplyDeleteSEGA TINOHORE SEGA 2019 ford ecosport titanium TINOHORE how much is titanium worth TINOHORE. Designed for the SEGA fans of Genesis, the titanium money clip new iron titanium SEGA T-Mobile app titanium nitride gun coating has you covered!