Installation of PostgreSQL 11.4 in Linux Platform.
Installation of PostgreSQL in Linux We love to make it easy for you.
Follow the steps below and you are done.
STEP 1 :
As a first step, we need to download the PostgreSQL by using the below link.
Click on the Download.
Go to the Red Hat family Linux and click on it.
Go to the Build from source and click on the file browser.
Choose the version and click on it.
Choose the software and click on it.
STEP 2 :
Transfer the downloaded file into Linux machine using WinScp.
The file has been copied into /opt directory.
1 2 3 4 5 6 7 8 9 |
Last login: Tue Jul 30 11:42:20 2019 from 192.168.0.5 [root@localhost ~]# pwd /root [root@localhost ~]# cd /opt [root@localhost opt]# ls -lart total 25317 -rwxrwxrwx. 1 root root 25915738 Jul 26 18:57 postgresql-11.4.tar.gz drwxrwxrwx. 1 root root 0 Jul 26 18:58 . dr-xr-xr-x. 1 root root 4192 Jul 30 11:54 .. |
STEP 3 :
Unzip the software.
It will take some time and wait for till complete.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
[root@localhost opt]# tar -xvf postgresql-11.4.tar.gz postgresql-11.4/ postgresql-11.4/.dir-locals.el postgresql-11.4/contrib/ postgresql-11.4/contrib/tcn/ postgresql-11.4/contrib/tcn/tcn.control postgresql-11.4/contrib/tcn/Makefile postgresql-11.4/contrib/tcn/tcn.c postgresql-11.4/contrib/tcn/tcn--1.0.sql postgresql-11.4/contrib/sslinfo/ postgresql-11.4/contrib/sslinfo/sslinfo--1.0--1.1.sql postgresql-11.4/contrib/sslinfo/sslinfo.control postgresql-11.4/contrib/sslinfo/sslinfo.c postgresql-11.4/contrib/sslinfo/sslinfo--unpackaged--1.0.sql postgresql-11.4/contrib/sslinfo/Makefile postgresql-11.4/contrib/sslinfo/sslinfo--1.2.sql postgresql-11.4/contrib/sslinfo/sslinfo--1.1--1.2.sql postgresql-11.4/contrib/unaccent/ postgresql-11.4/contrib/unaccent/sql/ postgresql-11.4/contrib/unaccent/sql/unaccent.sql postgresql-11.4/contrib/unaccent/.gitignore postgresql-11.4/contrib/unaccent/unaccent.rules postgresql-11.4/contrib/unaccent/unaccent.c postgresql-11.4/contrib/unaccent/unaccent.control postgresql-11.4/contrib/unaccent/unaccent--1.1.sql postgresql-11.4/contrib/unaccent/expected/ postgresql-11.4/contrib/unaccent/expected/unaccent.out postgresql-11.4/contrib/unaccent/unaccent--unpackaged--1.0.sql postgresql-11.4/contrib/unaccent/Makefile postgresql-11.4/contrib/unaccent/unaccent--1.0--1.1.sql postgresql-11.4/contrib/unaccent/generate_unaccent_rules.py postgresql-11.4/contrib/cube/ postgresql-11.4/contrib/cube/sql/ postgresql-11.4/contrib/cube/sql/cube.sql postgresql-11.4/contrib/cube/sql/cube_sci.sql postgresql-11.4/contrib/cube/cube--1.2--1.3.sql postgresql-11.4/contrib/cube/cube--1.3--1.4.sql postgresql-11.4/contrib/cube/.gitignore postgresql-11.4/aclocal.m4 postgresql-11.4/configure.in postgresql-11.4/INSTALL |
After the unzip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@localhost opt]# ls postgresql-11.4 postgresql-11.4.tar.gz [root@localhost opt]# cd postgresql-11.4 [root@localhost postgresql-11.4]# ls aclocal.m4 config configure configure.in contrib COPYRIGHT doc GNUmakefile.in HISTORY INSTALL Makefile README src [root@localhost postgresql-11.4]# ls -lart total 739 -rwxrwxrwx. 1 root root 1212 Jun 18 02:45 README -rwxrwxrwx. 1 root root 1682 Jun 18 02:45 Makefile -rwxrwxrwx. 1 root root 284 Jun 18 02:45 HISTORY -rwxrwxrwx. 1 root root 3848 Jun 18 02:45 GNUmakefile.in -rwxrwxrwx. 1 root root 504 Jun 18 02:45 .gitignore -rwxrwxrwx. 1 root root 1622 Jun 18 02:45 .gitattributes -rwxrwxrwx. 1 root root 730 Jun 18 02:45 .dir-locals.el -rwxrwxrwx. 1 root root 1192 Jun 18 02:45 COPYRIGHT -rwxrwxrwx. 1 root root 84451 Jun 18 02:45 configure.in -rwxrwxrwx. 1 root root 561752 Jun 18 02:45 configure -rwxrwxrwx. 1 root root 522 Jun 18 02:45 aclocal.m4 drwxrwxrwx. 1 root root 8192 Jun 18 03:00 contrib drwxrwxrwx. 1 root root 0 Jun 18 03:00 doc drwxrwxrwx. 1 root root 4096 Jun 18 03:00 config -rwxrwxrwx. 1 root root 74257 Jun 18 03:01 INSTALL drwxrwxrwx. 1 root root 4096 Jun 18 03:01 src drwxrwxrwx. 1 root root 4096 Jun 18 03:01 . drwxrwxrwx. 1 root root 0 Jul 30 12:00 .. [root@localhost postgresql-11.4]# |
STEP 4 :
Make the directory to install the software to it.
1 2 3 4 |
root@localhost postgresql-11.4]# mkdir -p /postgres/11.4 [root@localhost ~]# cd [root@localhost ~]# cd /postgres/11.4/ [root@localhost 11.4]# ls |
STEP 5 :
Configure the software into the directory
Here we are not installing the zlib and read line modules
–Zlib module is used for the compression
–Read line module is used for the documentation support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@localhost postgresql-11.4]# ./configure --prefix /postgres/11.4 --without-readline --without-zlib 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 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 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 for g++... g++ 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 for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for gawk... gawk |
STEP 6 :
To run the make command to compile all the libraries and it will take 10 minutes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@localhost postgresql-11.4]# make make -C ./src/backend generated-headers make[1]: Entering directory `/opt/postgresql-11.4/src/backend' make -C catalogdistprep generated-header-symlinks make[2]: Entering directory `/opt/postgresql-11.4/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.hpg_type_d.hpg_attribute_d.hpg_class_d.hpg_attrdef_d.hpg_constraint_d.hpg_inherits_d.hpg_index_d.hpg_operator_d.hpg_opfamily_d.hpg_opclass_d.hpg_am_d.hpg_amop_d.hpg_amproc_d.hpg_language_d.hpg_largeobject_metadata_d.hpg_largeobject_d.hpg_aggregate_d.hpg_statistic_ext_d.hpg_statistic_d.hpg_rewrite_d.hpg_trigger_d.hpg_event_trigger_d.hpg_description_d.hpg_cast_d.hpg_enum_d.hpg_namespace_d.hpg_conversion_d.hpg_depend_d.hpg_database_d.hpg_db_role_setting_d.hpg_tablespace_d.hpg_pltemplate_d.hpg_authid_d.hpg_auth_members_d.hpg_shdepend_d.hpg_shdescription_d.hpg_ts_config_d.hpg_ts_config_map_d.hpg_ts_dict_d.hpg_ts_parser_d.hpg_ts_template_d.hpg_extension_d.hpg_foreign_data_wrapper_d.hpg_foreign_server_d.hpg_user_mapping_d.hpg_foreign_table_d.hpg_policy_d.hpg_replication_origin_d.hpg_default_acl_d.hpg_init_privs_d.hpg_seclabel_d.hpg_shseclabel_d.hpg_collation_d.hpg_partitioned_table_d.hpg_range_d.hpg_transform_d.hpg_sequence_d.hpg_publication_d.hpg_publication_rel_d.hpg_subscription_d.hpg_subscription_rel_d.hschemapg.h; do \ rm -f $file && cp -pR "$prereqdir/$file" . ; \ done make[4]: Leaving directory `/opt/postgresql-11.4/src/common' make[3]: Leaving directory `/opt/postgresql-11.4/src/test/regress' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/opt/postgresql-11.4/src/test/perl' make[1]: Leaving directory `/opt/postgresql-11.4/src' make -C config all make[1]: Entering directory `/opt/postgresql-11.4/config' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/opt/postgresql-11.4/config' All of PostgreSQL successfully made. Ready to install. |
STEP 7 :
Install the software.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@localhost postgresql-11.4]# make install make[3]: Entering directory `/opt/postgresql-11.4/src/common' make[3]: Nothing to be done for `all'. make[3]: Leaving directory `/opt/postgresql-11.4/src/common' make -C ../../../contrib/spi make[3]: Entering directory `/opt/postgresql-11.4/contrib/spi' make[3]: Nothing to be done for `all'. /bin/mkdir -p '/postgres/11.4/lib/pgxs/src/test/regress' /usr/bin/install -c pg_regress '/postgres/11.4/lib/pgxs/src/test/regress/pg_regress' make[2]: Leaving directory `/opt/postgresql-11.4/src/test/regress' make -C test/isolation install make[2]: Entering directory `/opt/postgresql-11.4/src/test/isolation' make -C ../../../src/interfaces/libpq all make[2]: Leaving directory `/opt/postgresql-11.4/src/test/perl' /bin/mkdir -p '/postgres/11.4/lib/pgxs/src' /usr/bin/install -c -m 644 Makefile.global '/postgres/11.4/lib/pgxs/src/Makefile.global' /usr/bin/install -c -m 644 Makefile.port '/postgres/11.4/lib/pgxs/src/Makefile.port' make[1]: Entering directory `/opt/postgresql-11.4/config' /bin/mkdir -p '/postgres/11.4/lib/pgxs/config' /usr/bin/install -c -m 755 ./install-sh '/postgres/11.4/lib/pgxs/config/install-sh' /usr/bin/install -c -m 755 ./missing '/postgres/11.4/lib/pgxs/config/missing' make[1]: Leaving directory `/opt/postgresql-11.4/config' PostgreSQL installation complete. |
STEP 8 :
After the installation, make sure bin, doc, include, lib, man and share directories
are created under the /PostgreSQL/11.4 directory as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@localhost 11.4]# cd [root@localhost ~]# cd /postgres/11.4/ [root@localhost 11.4]# ls bin include lib share [root@localhost 11.4]# ls -lart total 24 drwxr-xr-x. 3 root root 4096 Jul 26 19:04 .. drwxr-xr-x. 6 root root 4096 Jul 26 19:33 . drwxr-xr-x. 6 root root 4096 Jul 26 19:33 include drwxr-xr-x. 2 root root 4096 Jul 26 19:33 bin drwxr-xr-x. 6 root root 4096 Jul 26 19:33 share drwxr-xr-x. 4 root root 4096 Jul 26 19:33 lib |
In the bin directory, we can see all the executable files and directories.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
[root@localhost 11.4]# cd bin [root@localhost bin]# ls -lart total 11528 -rwxr-xr-x. 1 root root 7976549 Jul 26 19:33 postgres lrwxrwxrwx. 1 root root 8 Jul 26 19:33 postmaster -> postgres drwxr-xr-x. 6 root root 4096 Jul 26 19:33 .. -rwxr-xr-x. 1 root root 950551 Jul 26 19:33 ecpg -rwxr-xr-x. 1 root root 130830 Jul 26 19:33 initdb -rwxr-xr-x. 1 root root 30692 Jul 26 19:33 pg_archivecleanup -rwxr-xr-x. 1 root root 113582 Jul 26 19:33 pg_basebackup -rwxr-xr-x. 1 root root 72476 Jul 26 19:33 pg_receivewal -rwxr-xr-x. 1 root root 76824 Jul 26 19:33 pg_recvlogical -rwxr-xr-x. 1 root root 30153 Jul 26 19:33 pg_config -rwxr-xr-x. 1 root root 41205 Jul 26 19:33 pg_controldata -rwxr-xr-x. 1 root root 58850 Jul 26 19:33 pg_ctl -rwxr-xr-x. 1 root root 414115 Jul 26 19:33 pg_dump -rwxr-xr-x. 1 root root 169369 Jul 26 19:33 pg_restore -rwxr-xr-x. 1 root root 93453 Jul 26 19:33 pg_dumpall -rwxr-xr-x. 1 root root 53533 Jul 26 19:33 pg_resetwal -rwxr-xr-x. 1 root root 90062 Jul 26 19:33 pg_rewind -rwxr-xr-x. 1 root root 32158 Jul 26 19:33 pg_test_fsync -rwxr-xr-x. 1 root root 26697 Jul 26 19:33 pg_test_timing -rwxr-xr-x. 1 root root 131409 Jul 26 19:33 pg_upgrade -rwxr-xr-x. 1 root root 41269 Jul 26 19:33 pg_verify_checksums -rwxr-xr-x. 1 root root 88419 Jul 26 19:33 pg_waldump -rwxr-xr-x. 1 root root 159213 Jul 26 19:33 pgbench -rwxr-xr-x. 1 root root 470833 Jul 26 19:33 psql -rwxr-xr-x. 1 root root 60963 Jul 26 19:33 createdb -rwxr-xr-x. 1 root root 56599 Jul 26 19:33 dropdb -rwxr-xr-x. 1 root root 64552 Jul 26 19:33 createuser -rwxr-xr-x. 1 root root 56569 Jul 26 19:33 dropuser -rwxr-xr-x. 1 root root 61399 Jul 26 19:33 clusterdb -rwxr-xr-x. 1 root root 68871 Jul 26 19:33 vacuumdb -rwxr-xr-x. 1 root root 64183 Jul 26 19:33 reindexdb drwxr-xr-x. 2 root root 4096 Jul 26 19:33 . -rwxr-xr-x. 1 root root 59240 Jul 26 19:33 pg_isready |
STEP 9 :
Make a directory to create a cluster
1 2 3 4 |
[root@localhost /]# mkdir cluster [root@localhost/]# ls -ld cluster drwxr-xr-x. 2 root root 4096 Aug 1 16:36 cluster |
Change the ownership and change the permissions of the directory from root to postgres user.
1 2 3 4 |
[root@localhost/]# chown -R postgres:postgres /cluster [root@localhost/]# chmod -R 777 /cluster [root@localhost/]# ls -ld cluster drwxrwxrwx. 2 postgres postgres 4096 Aug 1 16:36 cluster |
STEP 10 :
Create a Cluster
Connect to a Postgres user and go to the bin directory and create a cluster.
1 2 3 4 5 6 7 8 9 10 11 |
[root@localhost~]# su - postgres -bash-4.1$ pwd /var/lib/pgsql -bash-4.1$ cd /postgres/11.4/ -bash-4.1$ cd bin -bash-4.1$ pwd /postgres/11.4/bin -bash-4.1$ ls clusterdb dropdb initdb pgbench pg_ctl pg_isready pg_resetwal pg_test_fsync pg_verify_checksums postmaster vacuumdb createdb dropuser pg_archivecleanup pg_config pg_dump pg_receivewal pg_restore pg_test_timing pg_waldump psql createuser ecpg pg_basebackup pg_controldata pg_dumpall pg_recvlogical pg_rewind pg_upgrade postgres reindexdb |
To create a cluster we use the initdb utility.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
-bash-4.1$ ./initdb -D /cluster -U postgres 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 /cluster ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default timezone ... Asia/Kolkata selecting dynamic shared memory implementation ... posix creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... 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: ./pg_ctl -D /cluster -l logfile start |
Check the Cluster directory.
1 2 3 4 |
[root@postgres /]# cd cluster [root@postgres clu]# ls base pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf global pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf |
STEP 11 :
Start the cluster database using pg_ctl utility.
whenever create a new cluster the Postgres will be created a default user and database called postgres.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
-bash-4.1$ ./pg_ctl -U postgres -D /cluster start waiting for server to start....2019-08-01 16:27:56.525 IST [29954] LOG: listening on IPv4 address "0.0.0.0", port 9999 2019-08-01 16:27:56.525 IST [29954] LOG: listening on IPv6 address "::", port 9999 2019-08-01 16:27:56.550 IST [29954] LOG: listening on Unix socket "/tmp/.s.PGSQL.9999" 2019-08-01 16:27:57.011 IST [29960] LOG: database system was shut down at 2019-08-01 16:27:50 IST 2019-08-01 16:27:57.066 IST [29954] LOG: database system is ready to accept connections done server started -bash-4.1$ ./pg_ctl -U postgres -D /cluster status pg_ctl: server is running (PID: 29954) /postgres/11.4/bin/postgres "-D" "/cluster" -bash-4.1$ ./pg_ctl -U postgres -D /cluster status pg_ctl: server is running (PID: 29954) /postgres/11.4/bin/postgres "-D" "/cluster" |
STEP 11 :
Connect to a default cluster database called postgres.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
-bash-4.1$ ./psql -d postgres -U postgres -p 9999 psql (11.4) Type "help" for help. postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) postgres=# select version(); version -------------------------------------------------------------------------------------------------------- PostgreSQL 11.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), 64-bit (1 row) postgres=# select current_database(); current_database ------------------ postgres (1 row) postgres=# select current_user; current_user -------------- postgres (1 row) |