Let’s Get Started
PostgreSQL often knows as “Postgres”, is world most advance Object-relational database management system. PostgreSQL is developed by the PostgreSQL Global Development Group, a diverse group of many companies and individual contributors. It is free and Open source software, released under the terms of the PostgreSQL License,
This is the quick guide for installation of PostgreSQL v9.3.5 on RHEL 6.3 from the source
PostgreSQL can be installed in RHEL by using any of these two methods:
1) Using the source code distribution.
2) Pre-Packaged distribution, such as RPM or debian Package.
RHEL provides pre-packaged RPM for the installation of PostgreSQL. RHEL 6.3 media contains stable version of PostgreSQL v8.4.11.
For installation from the source code, certain prerequisites has to be completed to build and install PostgreSQL database.
- GNU make version 3.80 or newer is required. To test the GNU make enter the following command in the terminal
[student@ap2v ~]$ gmake --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for x86_64-redhat-linux-gnu
- Recent version of GCC are recommended.
- tar is required to unpack the source distribution, in addition with gzip or bzip2.
- The GNU Readline library.
- The Zlib compression library.
Step 1: After completing the pre-requisites, you can download the source code from here.
[student@ap2v ~]$ wget -c https://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.bz2 --2014-12-20 22:49:14-- https://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.bz2 Resolving ftp.postgresql.org... 126.96.36.199, 188.8.131.52, 184.108.40.206, ... Connecting to ftp.postgresql.org|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 16727725 (16M) [application/x-bzip] Saving to: postgresql-9.3.5.tar.bz2 100%[======================================>] 16,727,725 162K/s in 1m 55s 2014-12-20 22:51:10 (143 KB/s) - postgresql-9.3.5.tar.bz2 [student@ap2v ~]$
Step 2: The downloaded package will be available in compressed format. Use tar utility to uncompress and extract the contents.
[student@ap2v ~]$ tar -jxvf postgresql-9.3.5.tar.bz2
Step 3: Switch to the extracted directory of PostgreSQL and excute the “configure” script to configure the source tree for your system. The script will run a number of test to determine the status of system dependent settings & variables. You can also customize the build and installation process by supplying parameters while executing configure scripts.
[student@ap2v ~]$ cd postgresql-9.3.5 [student@ap2v postgresql-9.3.5]$ ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-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... 5432 checking for block size... 8kB checking for segment size... 1GB checking for WAL block size... 8kB checking for WAL segment size... 16MB checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc supports -Wdeclaration-after-statement... yes
There are various options available with configure script, some of them are described below
- –prefix=PREFIX will install architecture-independent files in PREFIX. Default installation location is /usr/local/pgsql.
- –bindir=DIRECTORY specifies the directory for executable programs. Default location is /usr/local/pgsql/bin.
- –with-pgport=NUMBER set default port number for server and clients. Default is 5432.
You can refer to INSTALL file in your source directory for detailed explanations of all options.
Step 4: Next step is to build the code.
[student@ap2v postgresql-9.3.5]$ make . . gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags -shared -o worker_spi.so worker_spi.o make: Leaving directory `/home/student/postgresql-9.3.5/contrib/worker_spi' make: Leaving directory `/home/student/postgresql-9.3.5/contrib' PostgreSQL, contrib, and documentation successfully made. Ready to install.
If you want to build everything including documentation and additional modules run this make command with world argument as
[student@ap2v postgresql-9.3.5]$ make world
Step 5: Now it’s time to install the PostgreSQL, login through the superuser ( i.e. root) and execute the following command
[root@ap2v postgresql-9.3.5]# make install . . /usr/bin/install -c -m 644 ./Makefile.shlib '/usr/local/pgsql/lib/pgxs/src/Makefile.shlib' /usr/bin/install -c -m 644 ./nls-global.mk '/usr/local/pgsql/lib/pgxs/src/nls-global.mk' make: Leaving directory `/home/student/postgresql-9.3.5/src' make -C config install make: Entering directory `/home/student/postgresql-9.3.5/config' /bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config' /usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh' make: Leaving directory `/home/student/postgresql-9.3.5/config' PostgreSQL installation complete.
To install the whole postgresql server with documentations and additional modules, execute the following command
[root@ap2v postgresql-9.3.5]# make install-world
PostgreSQL installation is successfully completed in your RHEL system. There are few post-installation steps which needs to completed for user convenient and smooth PostgreSQL operation’s.
Step 6: Change to default location for PostgreSQL ( usually /usr/local/pgsql ) and verify the existence of the directory tree.
[root@ap2v ~]# cd /usr/local/pgsql/ [root@ap2v pgsql]# ls -l total 16 drwxr-xr-x. 2 root root 4096 Dec 21 00:39 bin drwxr-xr-x. 6 root root 4096 Dec 21 00:39 include drwxr-xr-x. 4 root root 4096 Dec 21 00:39 lib drwxr-xr-x. 6 root root 4096 Dec 21 00:39 share
Step 7: The directory tree consists directory containing shared libraries and binary files of PostgreSQL. User needs to configure their environments settings accordingly. Use your profile setup files according to your distributions.
In RHEL we have to edit /etc/bashrc for it.
[root@ap2v ~]# cat >> /etc/bashrc LIB_PATH=/usr/local/pgsql/lib export LIB_PATH PATH=/usr/local/pgsql/bin:$PATH export PATH
Step 8: It’s time to configure PostgreSQL and test it. Create a superuser for PG database and it’s data dir which will contains all the contents for your database.
[root@ap2v ~]# useradd postgres [root@ap2v ~]# passwd postgres Changing password for user postgres. New password: Retype new password: passwd: all authentication tokens updated successfully.
To create the data dir which will contains all the contents for your database.
[root@ap2v ~]# mkdir /usr/local/pgsql/data [root@ap2v ~]# chown postgres:postgres /usr/local/pgsql/data [root@ap2v ~]# ls -ld /usr/local/pgsql/data drwxr-xr-x. 2 postgres postgres 4096 Dec 21 21:42 /usr/local/pgsql/data
Step 9: Switch to postgres user and then initiate the DB with initdb command. This will create all necessary configuration files and directory tree in your data dir which you created in earlier step. If you haven’t configured your environment settings, you have to use absolute pathnames for command’s to be used in this step.
[root@ap2v ~]# su - postgres [postgres@ap2v ~]$ initdb -D /usr/local/pgsql/data/ The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /usr/local/pgsql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB creating configuration files ... ok creating template1 database in /usr/local/pgsql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgSQL server-side language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data/ or /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start
Step 10: There you Goo !!! The PostgreSQL is successfully installed and initialize in RHEL 6.3. In next coming blogs, we will understand more about data directory and database operations in PostgreSQL, till then Happy Learning !!!