2. Install PostgreSQL
All PostgreSQL installation steps should be performed on all PostgreSQL nodes.
Install Postgres on RHEL
Step 1
Refer to https://www.postgresql.org/download/linux/redhat/ to locate and download the latest minor version of PostgreSQL 10. The rpm referenced in the following yum command should be modified accordingly.
sudo yum install
https://download.postgresql.org/pub/repos/yum/10.x/redhat/rhel-7-
x86_64/pgdg-redhat94-9.4-3.noarch.rpm
sudo yum install postgresql10.x-server postgresql10.x-contrib
Step 2
Production database files are typically stored on a non-OS disk or shared file service. The /db folder will be that storage location in this example.
Create the following folder locations on each PostgreSQL node.
* 
The /db/postgres location is referenced in scripts provided with this example. Modifying the folder location would require updates to the scripts as well.
sudo mkdir /db
sudo mkdir /db/postgres
sudo mkdir /db/thingworx
sudo mkdir /db/install
sudo mkdir /db/bin
sudo chown -R postgres:postgres /db
Create the three archive folders mentioned earlier in the file sharing section of this example and ensure all PostgreSQL nodes can access content within them.
/db/node0archive
/db/node1archive
/db/node2archive
Step 3
As previously mentioned in Database folder setup, the PostgreSQL database will be located under /db/postgres on each PostgreSQL node.
The postgres user profile needs to first be adjusted to the new location before the database is initialized.
sudo su postgres
vim ~/.bash_profile
Sample of ~/.bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/db/postgres
export PGDATA
PATH=$PATH:/usr/pgsql-10.x/bin
export PATH
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source
/var/lib/pgsql/.pgsql_profile
After editing, enact the changes:
source ~/.bash_profile
Initialize the database:
/usr/pgsql-10.x/bin/initdb -D /db/postgres
Step 4
Return to the user with sudo privileges and modify the PGDATA parameter within the PostgreSQL service.
Edit the postgresql-10.x.service file
sudo vi /usr/lib/systemd/system/postgresql-10.x.service
to contain the new PGDATA parameter value.
# Location of database directory
#Environment=PGDATA=/var/lib/pgsql/10.x/data/
Environment=PGDATA=/db/postgres
Then reload, enable, and start the service.
sudo systemctl reload
sudo systemctl enable postgresql-10.x.service
sudo systemctl start postgresql-10.x
Step 5
Verify init installation:
sudo su postgres
psql
Using the command show data_directory to make sure the default database is installed correctly.
postgres=# show data_directory;
data_directory
----------------
/db/postgres
(1 row)
Was this helpful?