Custom Postgres Installation

Installing postgres in a non- default directory is something which lots of poeple/comapanies want to acomplish.

In this demo, i will showing four different ways which you could achive this in your environment. Which ever way works for you and you wish to go with it, that is fine.

If you are not able to get the full installation details here, i will advise that you watch the demo video which i have prepared showing how this is done. You can look at the media section of this page to se the video or you can click here to see the video.

First option. If you want to install postgres using the yum installation and you will like to put this in a non default path, there are a couple of things which you could do to archive this. One option will be to create the directory.. like

mkdir /edb ; ln -s /edb /usr/edb ; yum install -y "edb-as13-server" would still install all binaries accessible through /usr/edb, but they would end up in /edb. After this is done, you could create the WAL directory, data directory and change its ownership and permissions to 0700. when running the initdb command, make sure to specify the -D <data directory> –waldir=<Wal directory location>. This should work fine and you can start up your cluster.

Second option. If for some reason you don’t have internet on the server but you do have the all the rpm file for the installation, you could perform the following

Step1:
======
 
You need to download the edb-as-11-server related binary RPM's and place it in the folder in which you have to install the software.
 
Ex:[enterprisedb@localhost EPAS]$ pwd
/tmp/EPAS
[enterprisedb@localhost EPAS]$ ls -lhrt
 
          edb-as11-server-11.5.12-1.rhel7.x86_64.rpm
          edb-as11-server-client-11.5.12-1.rhel7.x86_64.rpm
          edb-as11-server-contrib-11.5.12-1.rhel7.x86_64.rpm
          edb-as11-server-core-11.5.12-1.rhel7.x86_64.rpm
          edb-as11-server-libs-11.5.12-1.rhel7.x86_64.rpm
          libicu-ppas-53.1-11.rhel7.x86_64.rpm
          libicu-edb-53.1-11.rhel7.x86_64.rpm
 
Step2:
======
Install the respective RPMs like below.
 
  rpm2cpio edb-as11-server-11.5.12-1.rhel7.x86_64.rpm | cpio -idmv
  rpm2cpio edb-as11-server-client-11.5.12-1.rhel7.x86_64.rpm | cpio -idmv
  rpm2cpio edb-as11-server-contrib-11.5.12-1.rhel7.x86_64.rpm | cpio -idmv
  rpm2cpio edb-as11-server-core-11.5.12-1.rhel7.x86_64.rpm | cpio -idmv
  rpm2cpio edb-as11-server-libs-11.5.12-1.rhel7.x86_64.rpm | cpio -idmv
  rpm2cpio libicu-ppas-53.1-11.rhel7.x86_64.rpm| cpio -idmv
  rpm2cpio libicu-edb-53.1-11.rhel7.x86_64.rpm | cpio -idmv
  
Step3: 
=====
Following folder(usr, var, etc) gets created inside the respective directory and these contain the edb, lib,libexec subdirectories which holds the required EPAS-11 binaries and libraries.
 
Ex:ls -lhrt /tmp/EPAS/
drwxr-xr-x. 3 root root   17 Sep  2 20:01 var
drwxr-xr-x. 4 root root   39 Sep  2 20:01 etc
drwxr-xr-x. 5 root root   43 Sep  2 20:16 usr
 
Step4:
======
Now create the empty data directory with below ownership and permission.
 
mkdir -p <data_dir_path>
chown -R enterprisedb:enterprisedb <data_dir_path>
chmod 0700 <data_dir_path>
 
Ex: mkdir -p /tmp/data11
chown -R enterprisedb:enterprisedb /tmp/data11
chmod 0700 /tmp/data11

 
Step5:
======
Set the LD_LIBRARY_PATH and run inidb command as below which will create the cluster for you.
 
export LD_LIBRARY_PATH=/tmp/EPAS/usr/edb/as11/lib/:/tmp/EPAS/usr/libexec/icu-ppas-53.1/lib/:/tmp/EPAS/usr/libexec/icu-edb53.1/lib/:$LD_LIBRARY_PATH
[enterprisedb@localhost bin]$ ./initdb -D <data_dir_path>
 
Ex:
export LD_LIBRARY_PATH=/tmp/EPAS/usr/edb/as11/lib/:/tmp/EPAS/usr/libexec/icu-ppas-53.1/lib/:/tmp/EPAS/usr/libexec/icu-edb53.1/lib/:$LD_LIBRARY_PATH
[enterprisedb@localhost bin]$ ./initdb -D /tmp/data11/
The files belonging to this database system will be owned by user "enterprisedb".
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 /tmp/data11 ... 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
creating edb sys ... ok
:
:
:
finalizing initial databases ... 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 /tmp/data11/ -l logfile start
 
[enterprisedb@localhost bin]$ ./pg_ctl -D /tmp/data11/ status
pg_ctl: server is running (PID: 17118)
/tmp/EPAS/usr/edb/as11/bin/edb-postgres "-D" "/tmp/data11"

So the above will work very well for this.

Third option. If for some reason you do not have the rpm file for the installation but instead have the .run file which is mostly use for interactive postgres installation which is mostly available from EPAS10 and below, you might want to do the following..

-bash-4.2# cd /home/benson/Downloads/
-bash-4.2# ll
total 319164

-rw-rw-r--. 1 benson benson 115849482 Mar  4 22:03 edb-as10-server-10.15.24-1-linux-x64(1).run
-rwxrwxrwx. 1 benson benson 115849482 Jan 11 13:21 edb-as10-server-10.15.24-1-linux-x64.run


-rw-r--r--. 1 root   root         248 Oct 28 12:16 EDB_slient_Installation.txt
12.1.0.2.0-1.x86_64.rpm
-rw-r--r--. 1 root   root      634803 Nov 10 09:16 oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
-bash-4.2# 
-bash-4.2# ./edb-as10-server-10.15.24-1-linux-x64.run --mode unattended --extract-only yes --prefix /opt/edb/as10/
-bash-4.2# 
-bash-4.2# ll /opt/edb/as10/
total 204
drwxr-xr-x.  2 root root  4096 Mar  4 22:17 bin
drwxr-xr-x.  4 root root    38 Mar  4 22:17 doc
-rw-r--r--.  1 root root 72341 Nov 10 16:59 edb-as10-server_commandlinetools_3rd_party_licenses.txt
-r--r--r--.  1 root root 15216 Nov 10 16:58 edb-as10-server_license.txt
drwxr-xr-x.  3 root root    23 Mar  4 22:17 etc
drwxr-xr-x.  6 root root  4096 Mar  4 22:17 include
drwxr-xr-x.  5 root root    55 Mar  4 22:17 installer
drwxr-xr-x.  4 root root  8192 Mar  4 22:17 lib
drwxr-xr-x. 10 root root   164 Mar  4 22:17 pgAdmin4
-rwxr-xr-x.  1 root root 90620 Nov 10 16:59 runAsRoot.sh
drwxr-xr-x.  5 root root    73 Mar  4 22:17 scripts
drwxr-xr-x. 10 root root  4096 Mar  4 22:17 share
-bash-4.2# 
-bash-4.2# su - enterprisedb 
Last login: Thu Mar  4 22:11:20 EST 2021 on pts/0
-bash-4.2$ 
-bash-4.2$ /opt/edb/as10/bin/initdb -D /edb/as10   -----> if you created the WAl directory, you might run something like /opt/edb/as10/bin/initdb -D /edb/as10 --waldir=/pgwal10
The files belonging to this database system will be owned by user "enterprisedb".
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 /edb/as10 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... America/New_York
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
creating edb sys ... ok
loading edb contrib modules ...
edb_redwood_bytea.sql ok
edb_redwood_date.sql ok
dbms_alert_public.sql ok
dbms_alert.plb ok
dbms_job_public.sql ok
dbms_job.plb ok
dbms_lob_public.sql ok
dbms_lob.plb ok
dbms_output_public.sql ok
dbms_output.plb ok
dbms_pipe_public.sql ok
dbms_pipe.plb ok
dbms_rls_public.sql ok
dbms_rls.plb ok
dbms_sql_public.sql ok
dbms_sql.plb ok
dbms_utility_public.sql ok
dbms_utility.plb ok
dbms_aqadm_public.sql ok
dbms_aqadm.plb ok
dbms_aq_public.sql ok
dbms_aq.plb ok
dbms_profiler_public.sql ok
dbms_profiler.plb ok
dbms_random_public.sql ok
dbms_random.plb ok
dbms_lock_public.sql ok
dbms_lock.plb ok
dbms_scheduler_public.sql ok
dbms_scheduler.plb ok
dbms_crypto_public.sql ok
dbms_crypto.plb ok
dbms_mview_public.sql ok
dbms_mview.plb ok
dbms_session_public.sql ok
dbms_session.plb ok
edb_bulkload.sql ok
edb_gen.sql ok
edb_objects.sql ok
edb_redwood_casts.sql ok
edb_redwood_strings.sql ok
edb_redwood_views.sql ok
utl_encode_public.sql ok
utl_encode.plb ok
utl_http_public.sql ok
utl_http.plb ok
utl_file.plb ok
utl_tcp_public.sql ok
utl_tcp.plb ok
utl_smtp_public.sql ok
utl_smtp.plb ok
utl_mail_public.sql ok
utl_mail.plb ok
utl_url_public.sql ok
utl_url.plb ok
utl_raw_public.sql ok
utl_raw.plb ok
commoncriteria.sql ok
waitstates.sql ok
installing extension edb_dblink_libpq ... ok
installing extension edb_dblink_oci ... ok
installing extension pldbgapi ... ok
snap_tables.sql ok
snap_functions.sql ok
dblink_ora.sql ok
edb_infinitecache.sql ok
sys_stats.sql ok
finalizing initial databases ... 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:

    /opt/edb/as10/bin/pg_ctl -D /edb/as10 -l logfile start

-bash-4.2$ /opt/edb/as10/bin/pg_ctl -D /edb/as10 -l logfile start
waiting for server to start.... done
server started
-bash-4.2$ 
-bash-4.2$ ps -ef|grep postgres  
enterpr+  5167     1  0 22:19 pts/1    00:00:00 /opt/edb/as10/bin/edb-postgres -D /edb/as10
enterpr+  5169  5167  0 22:19 ?        00:00:00 postgres: checkpointer process   
enterpr+  5170  5167  0 22:19 ?        00:00:00 postgres: writer process   
enterpr+  5171  5167  0 22:19 ?        00:00:00 postgres: wal writer process   
enterpr+  5172  5167  0 22:19 ?        00:00:00 postgres: autovacuum launcher process   
enterpr+  5173  5167  0 22:19 ?        00:00:00 postgres: stats collector process   
enterpr+  5174  5167  0 22:19 ?        00:00:00 postgres: bgworker: dbms_aq launcher   
enterpr+  5175  5167  0 22:19 ?        00:00:00 postgres: bgworker: logical replication launcher  
enterpr+  5183  4936  0 22:19 pts/1    00:00:00 grep --color=auto postgres
-bash-4.2$ 
-bash-4.2$ 
-bash-4.2$ psql
psql (server 10.15.24)
Type "help" for help.

edb=# show data_directory;
 data_directory 
----------------
 /edb/as10
(1 row)

edb=#

Fourth option. For some reason, if you want to take advantage of the source code installation, you might want to do the following.

# yum install gcc zlib-devel readline-devel     [On RHEL/CentOS]
# wget https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.bz2
# tar -xvf postgresql-10.0.tar.bz2
ll
total 19236
-rw-------. 1 root root      933 Mar 18  2015 anaconda-ks.cfg
-rw-r--r--. 1 root root     8823 Mar 18  2015 install.log
-rw-r--r--. 1 root root     3384 Mar 18  2015 install.log.syslog
drwxrwxrwx  6 1107 1107     4096 Oct  3  2017 postgresql-10.0
-rw-r--r--  1 root root 19639147 Oct  3  2017 postgresql-10.0.tar.bz2
# cd postgresql-10.0
# mkdir /opt/PostgreSQL-10/
# ./configure --prefix=/opt/PostgreSQL-10
# make
# make install
# useradd postgres
# passwd postgres
# mkdir /pgdatabase/data
# chown -R postgres. /pgdatabase/data
# echo 'export PATH=$PATH:/opt/PostgreSQL-10/bin' > /etc/profile.d/postgres.sh
# su postgres
$ initdb -D /pgdatabase/data/ -U postgres -W

After initializing database, start the database cluster or if you need to change port or listen address for server, edit the postgresql.conf file in data directory of database server.

$ pg_ctl -D /pgdatabase/data/ -l /pglog/db_logs/start.log start

You can check it out here . You can look at the video for simplicity and step by step demo.

Please leave us a comment after watching it so we know if this was helpful to you.

Thanks

About the author

User Avatar

bensonyerima

Hi, I'm Benson Yerima, a database administrator with an obsession for all things tech. This blog is dedicated for helping people learn about database technology.

View all posts