How to Install PostgreSQL Database Server using compressed file in CentOS 8

Posted on

Introduction

This is an article for showing how to install PostgreSLQ database server in Linux CentOS 8. The installation process is using a compressed file installer. It is available in this link. It will use PostgreSQL 12.0 in the .tar.gz tarball compressed file. The installation process is in a virtual machine running Linux CentOS 8. It will download the installation source file into the directory path of ‘/home/admin’. Actually, it is the home directory of ‘admin’ user. Just feel free to choose another path for storing the file. Moreover, the target installation path will be in ‘/opt/postgresql-12.0/app’. Similarly, just feel free to choose another destination installation path. As for the process, there are preparation part and installation part for installing PostgreSQL database server.

Preparation Part

This part is just a preparation part before the actual installation process begin. The preparation is focusing on downloading the PostgreSQL database server’s installer. It is in the form of a compressed file. Download it and then extract it.

  1. First of all, just download the source installer. In this context, just download it in any path or location available. So, use any available account in the operating system.  As an example, this article is using root account. Download and store it in any possible places. The example in this article is using one of the user home available. It is not a best practice, but the main purpose is to have a source installation of the PostgreSQL database server. The installer file is a compressed file of PostgreSQL database server with the format of either .tar.gz or .tar.bz. The following is the execution of the download process using ‘wget’ program or utility available in the form of command :

    [root@10 admin]# wget https://ftp.postgresql.org/pub/source/v12.0/postgresql-12.0.tar.gz
    --2021-06-16 10:04:32--  https://ftp.postgresql.org/pub/source/v12.0/postgresql-12.0.tar.gz
    Resolving ftp.postgresql.org (ftp.postgresql.org)... 72.32.157.246, 147.75.85.69, 217.196.149.55, ...
    Connecting to ftp.postgresql.org (ftp.postgresql.org)|72.32.157.246|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 26393892 (25M) [application/octet-stream]
    Saving to: ‘postgresql-12.0.tar.gz’
    
    postgresql-12.0.tar.gz                     100%[========================================================================================>]  25.17M   113KB/s    in 3m 18s
    
    2021-06-16 10:07:52 (130 KB/s) - ‘postgresql-12.0.tar.gz’ saved [26393892/26393892]
    
    [root@10 admin]#
    
  2. After successfully download the installer source in the tarball compressed format, extract it with the following command :

    [root@10 admin]# tar -zxvf postgresql-12.0.tar.gz
    postgresql-12.0/
    postgresql-12.0/.dir-locals.el
    postgresql-12.0/contrib/
    ...
    postgresql-12.0/doc/src/sgml/xplang.sgml
    postgresql-12.0/doc/src/Makefile
    postgresql-12.0/doc/KNOWN_BUGS
    postgresql-12.0/doc/Makefile
    postgresql-12.0/doc/TODO
    postgresql-12.0/doc/MISSING_FEATURES
    postgresql-12.0/HISTORY
    postgresql-12.0/Makefile
    postgresql-12.0/README
    postgresql-12.0/COPYRIGHT
    postgresql-12.0/GNUmakefile.in
    postgresql-12.0/.gitattributes
    postgresql-12.0/aclocal.m4
    postgresql-12.0/configure.in
    postgresql-12.0/INSTALL
    [root@10 admin]#
    

 

Installation Part

After finishing the preparation part, continue on to the installation part.  Actually, the execution part consists of several parts. Those parts are the script configuration part, building part and installation part. The script configuration part is the execution of a script with the name of ‘configure’. It is a script which is responsible for getting ready to build the software on your specific system. By executing the configure script, it will make sure that all of the dependencies for the rest of the build and install process are available. Moreover, it will find out whatever it needs to know to use those dependencies.

The next part is is invoking the ‘make’ command to build the software. It will runs a series of tasks defined in the file with the name of ‘Makefile’ in order to build the finished program from its source code. Actually, the tarball or the downloaded file in the compressed format of the PostgreSQL installer usually does not include a finished Makefile. Instead, it comes with a file as a template with the name of Makefile. So, the configure script will  produces a customized Makefile specifically for the system.

The part after is the last part. After building the software and it is ready to run, the files will be available for further copy processes to the final destinations defined in the prefix. The command ‘make install’ will copy the built program, and its libraries and documentation, to the specified locations.

Configure the script

So, this is the first step of the installation. In this first step, it will focus on preparing or configuring script for building the installer. Execute the following command to create a Makefile file for the build process. Execute the following command pattern to create a Makefile file :

./configure --prefix=path_for_installation

Just replace the value of the parameter ‘–prefix’ with the destination path of the installation. In this context, the replacement value is ‘/opt/postgresql-12.0/app’. The following is the execution of the command :

[root@10 postgresql-12.0]# ./configure --prefix=/opt/postgresql-12.0/app
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 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 gcc... gcc
...
checking for bison... no
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from Git nor
*** change any of the parser definition files.  You can obtain Bison from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this, because the Bison
*** output is pre-generated.)
checking for flex... no
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from Git nor
*** change any of the scanner definition files.  You can obtain Flex from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this because the Flex
*** output is pre-generated.)
checking for perl... /usr/bin/perl
configure: using perl 5.26.3
checking for a sed that does not truncate output... /usr/bin/sed
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether gcc is Clang... no
...
configure: using CPPFLAGS= -D_GNU_SOURCE
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
[root@10 postgresql-12.0]#

Building the installer

In this part, after generating a script for building the installer, just run the next command to build it. The command for building the installer is ‘make’. So, using that command, just execute it as follows :

[root@10 postgresql-12.0]# make
make -C ./src/backend generated-headers
make[1]: Entering directory '/home/admin/postgresql-12.0/src/backend'
make -C catalog distprep generated-header-symlinks
make[2]: Entering directory '/home/admin/postgresql-12.0/src/backend/catalog'
make[2]: Nothing to be done for 'distprep'.
prereqdir=`cd './' >/dev/null && pwd` && \
cd '../../../src/include/catalog/' && for file in pg_proc_d.h pg_type_d.h pg_attribute_d.h pg_class_d.h pg_attrdef_d.h pg_constraint_d.h pg_inherits_d.h pg_index_d.h pg_operator_d.h pg_opfamily_d.h pg_opclass_d.h pg_am_d.h pg_amop_d.h pg_amproc_d.h pg_language_d.h pg_largeobject_metadata_d.h pg_largeobject_d.h pg_aggregate_d.h pg_statistic_ext_d.h pg_statistic_ext_data_d.h pg_statistic_d.h pg_rewrite_d.h pg_trigger_d.h pg_event_trigger_d.h pg_description_d.h pg_cast_d.h pg_enum_d.h pg_namespace_d.h pg_conversion_d.h pg_depend_d.h pg_database_d.h pg_db_role_setting_d.h pg_tablespace_d.h pg_pltemplate_d.h pg_authid_d.h pg_auth_members_d.h pg_shdepend_d.h pg_shdescription_d.h pg_ts_config_d.h pg_ts_config_map_d.h pg_ts_dict_d.h pg_ts_parser_d.h pg_ts_template_d.h pg_extension_d.h pg_foreign_data_wrapper_d.h pg_foreign_server_d.h pg_user_mapping_d.h pg_foreign_table_d.h pg_policy_d.h pg_replication_origin_d.h pg_default_acl_d.h pg_init_privs_d.h pg_seclabel_d.h pg_shseclabel_d.h pg_collation_d.h pg_partitioned_table_d.h pg_range_d.h pg_transform_d.h pg_sequence_d.h pg_publication_d.h pg_publication_rel_d.h pg_subscription_d.h pg_subscription_rel_d.h schemapg.h; do \
  rm -f $file && ln -s "$prereqdir/$file" . ; \
done
touch ../../../src/include/catalog/header-stamp
make[2]: Leaving directory '/home/admin/postgresql-12.0/src/backend/catalog'
...
make[2]: Entering directory '/home/admin/postgresql-12.0/src/backend/utils'
make[2]: Nothing to be done for 'distprep'.
prereqdir=`cd './' >/dev/null && pwd` && \
cd '../../../src/include/utils/' && for file in fmgroids.h fmgrprotos.h errcodes.h; do \
  rm -f $file && ln -s "$prereqdir/$file" . ; \
done 
...
make[1]: Entering directory '/home/admin/postgresql-12.0/config'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/admin/postgresql-12.0/config'
All of PostgreSQL successfully made. Ready to install.
[root@10 postgresql-12.0]#

Executing the installer

So, after building the installer using the Makefile file in the previous part,  next part is to execute it. It is a command to install the PostgreSQL database server. The installer is available from the previous process which build the installer. Execute the command ‘make install’ as follows :

[root@10 postgresql-12.0]# make install
make -C ./src/backend generated-headers
make[1]: Entering directory '/home/admin/postgresql-12.0/src/backend'
make -C catalog distprep generated-header-symlinks
make[2]: Entering directory '/home/admin/postgresql-12.0/src/backend/catalog'
make[2]: Nothing to be done for 'distprep'.
make[2]: Nothing to be done for 'generated-header-symlinks'.
make[2]: Leaving directory '/home/admin/postgresql-12.0/src/backend/catalog'
...
make -C ../../../src/port all
make[3]: Entering directory '/home/admin/postgresql-12.0/src/port'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/admin/postgresql-12.0/src/port'
make -C ../../../src/common all
make[3]: Entering directory '/home/admin/postgresql-12.0/src/common'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/admin/postgresql-12.0/src/common'
make[2]: Leaving directory '/home/admin/postgresql-12.0/src/test/isolation'
make -C test/perl install
make[2]: Entering directory '/home/admin/postgresql-12.0/src/test/perl'
make[2]: Nothing to be done for 'install'.
make[2]: Leaving directory '/home/admin/postgresql-12.0/src/test/perl'
/usr/bin/mkdir -p '/opt/postgresql-12.0/app/lib/pgxs/src'
/usr/bin/install -c -m 644 Makefile.global '/opt/postgresql-12.0/app/lib/pgxs/src/Makefile.global'
/usr/bin/install -c -m 644 Makefile.port '/opt/postgresql-12.0/app/lib/pgxs/src/Makefile.port'
/usr/bin/install -c -m 644 ./Makefile.shlib '/opt/postgresql-12.0/app/lib/pgxs/src/Makefile.shlib'
/usr/bin/install -c -m 644 ./nls-global.mk '/opt/postgresql-12.0/app/lib/pgxs/src/nls-global.mk'
make[1]: Leaving directory '/home/admin/postgresql-12.0/src'
make -C config install
make[1]: Entering directory '/home/admin/postgresql-12.0/config'
/usr/bin/mkdir -p '/opt/postgresql-12.0/app/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/opt/postgresql-12.0/app/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/opt/postgresql-12.0/app/lib/pgxs/config/missing'
make[1]: Leaving directory '/home/admin/postgresql-12.0/config'
PostgreSQL installation complete.
[root@10 postgresql-12.0]#

Finally, the installation is complete. It exist in the formation from above output command in the last line. Furthermore, in order to run it, there are several additional steps available. Just read it in the other article for starting the PostgreSQL database server.

2 thoughts on “How to Install PostgreSQL Database Server using compressed file in CentOS 8

Leave a Reply