Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Methods of installing PostgreSQL

Installation of PostgreSQL:
The first thing to work on when installing PostgreSQL is to decide on the version number. In general, a PostgreSQL version number consists of three digits.

EX: - 9.4.0, 9.4.1, or 9.4.2,10,11

The last digit is the so-called minor release. When a new minor release is issued, it generally means that some bugs have been fixed (for example, some time zone changes, crashes, and so on). There will never be new features, missing functions, or changes of that sort in a minor release. The same applies to something truly important—the storage format. It won't change with a new minor release.

These little facts have a wide range of consequences. As the binary format and the functionality are unchanged, you can simply upgrade your binaries, restart PostgreSQL, and enjoy your improved minor release.

Methods of installing PostgreSQL:

·         Install using source code
o   Source code means the “code of postgresql which is written in C language”. We compile and execute the source code to do the installation.
o   Source code installation provide more flexibility in selecting the locations where we want to perform the installation.
·         Install using RPM package
o   rpm means Red Hat Package Manager. For redhat and centos the complete postgresql(including libraries etc) is provided as rpm packages where by installing them we can complete the installation of postgres.
o   This will do the installation into default location.(/var/lib/pgsql)
·         Install using .run file provided by third party(like edb)
o   This is third party tools where we can perform the installation easily, we need to execute the installation using the root user.
o   This installable file includes all the required packages and libraries for postgresql.
o   By using this we can select the locations where you want to install the postgresql and store the data (data directory).
o   The problem with this installation is the libraries are conflicted with the libraries in OS level.

Install using source code:

Prerequisite for postgres installation:

gcc compiler
zlib package
readline package


·         Create a dedicated PostgreSQL user under whom we install the postgres software

useradd postgres
passwd postgres

NOTE: passwd command is used to set the password

·      Create the required directories to install postgres (This is according to my configuration)
Here we create two directories one for software and another for cluster data.

mkdir /home/postgres/software
mkdir /home/postgres/DATA

·         Download the postgresql source code from http://www.postgresql.org/ftp/source/v9.5.2/.

·         untar the source code

tar xvf <filename>


Installation steps
1.Go to the build directory, execute the below command to configure the server with required options.

cd <directory name which you untarrted in step 4>

./configure --prefix=/home/postgres/software

--prefix: option is used to mention the location where to install the software
--exec-prefix: option to install the architecture (OS) dependent software location
--with-pgport: option specify the port number
--with-segsize: option specify the size of the segment. PostgreSQL store the data in terms of segments (os level files) each segment is a file. This is in terms of GB.
--with-wal-segsize: option specify the size of the wal segment in MB.
--with-wal-blocksize: option specify the size of the block size in KB
 
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... yes
checking whether NLS is wanted... no
checking for default port number... 1818
checking for block size... 8kB
checking for segment size... 4GB
checking for WAL block size... 4kB
checking for WAL segment size... 8MB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
.........................................
.........................................
.........................................
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

2)  Execute the command "make" to build.
make
 At the end we can see the message
All of PostgreSQL successfully made. Ready to install.

3) Execute the command "make install" to complete installation of software.

At the end you will get a message "PostgreSQL installation complete." This will use the directories mentioned in the first step.


Post-installation steps:-

set the variables(PATH,LD_LIBRARY_PATH) in bash profile file.
[postgres@localhost Desktop]$ cat ~/.bash_profile
export PATH=$PATH:/home/postgres/software/bin
export LD_LIBRARY_PATH=/home/postgres/software/include/server/lib
Initialize the database cluster:-

After completing the installation and changing the bash variables. Use the below command “initdb” to initialise the cluster.

NOTE : Make sure you have privileges on the directory.
initdb –D <location of your data directory>
After completion of initialisation start the postgres cluster
pg_ctl –D <directory which gave in above command> -l logfile start
To check the status of postgresql cluster.
pg_ctl –D <directory which gave in above command> status
Install using RPM package


2) Copy it to server

3) Install the rpm to create the repository
[root@localhost Desktop]#
[root@localhost Desktop]# rpm -ivh pgdg-redhat96-9.6-3.noarch.rpm
warning: pgdg-redhat96-9.6-3.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:pgdg-redhat96          ########################################### [100%]
 4) Install all the postgresql9.6 packages.
yum -y install postgresql96*

NOTE:Default location of installation of software /usr/pgsql-9.6

5) After installing the packages, a database needs to be initialized and configured.

The default data directory is:

/var/lib/pgsql/<name>/data

EX:

/var/lib/pgsql/9.6/data

6) Initialize the database cluster.
[root@localhost data]# service postgresql-9.6 initdb

Initializing database:                                     [  OK  ]
7) Start-up the database service.
chkconfig postgresql-9.6 on
service postgresql-9.6 start

NOTE: chkconfig is used to make the database service start automatically.

8) set the environment variables in .bash_profile file present in user home directory.
export PATH=/usr/pgsql-9.6/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-9.6/lib:$LD_LIBRARY_PATH
Removing:-
Use below command to remove the PostgreSQL software
yum erase postgresql96*

Install using third party run file:


2) Copy the file to server

3) Give execution privileges to the file using the “chmod” command.

NOTE: Login as root user and execute the command.

chmod +x postgresql-9.6.0-1-linux-x64.run

4) Run the file and follow the steps of installation
[root@localhost Desktop]# ./postgresql-9.6.0-1-linux-x64.run
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.
----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.

Installation Directory [/opt/PostgreSQL/9.6]:
----------------------------------------------------------------------------
Please select a directory under which to store your data.
Data Directory [/opt/PostgreSQL/9.6/data]:

----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.
Password :
Retype password :

----------------------------------------------------------------------------
Please select the port number the server should listen on.
Port [5433]:

----------------------------------------------------------------------------
Advanced Options
Select the locale to be used by the new database cluster.
Locale
[1] [Default locale]
............
............
............
[718] zu_ZA.utf8

Please choose an option [1] :
----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.
Do you want to continue? [Y/n]: Y

----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer. 
Installing
 0% ______________ 50% ______________ 100%
  #########################################

----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.

NOTE: This automatically complete installation and configuration of PostgreSQL.

 Written BY :- Raghavan Rao

Comments

Popular posts from this blog

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

7 Steps to configure BDR replication in postgresql

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

Ora2PG - Oracle/MySQL to Postgres DB migration Version 20.0

PostgreSQL Introduction