what is database cluster
database cluster is collection of database managed by single instance
don’t get confused by cluster that tied up by high availability
initdb
initdb : is utility used to create database cluster
initdb create setup directory called (data directory ) where we store our data .
initdb need to be installed , and once installed you have to initialize storage area
data directory path
typically the location of data directory in Linux will be
/var/lib/pgsql/data/
initdb syntax
you have to execute initdb using the postgres user
syntax:initdb -D /usr/var/lib/pgsql/main
pg_ctl -D /usr/var/lib/pgsql/main
-D this option refer to data directory-W we can use this option to force the super user to provide password before initialize DB
before you start make sure add binary of postgreasql commandexport PATH=/usr/lib/postgresql/13/bin/:$PATH
to test this we will create directory in root folder called /postgresql/data/
and we will assigned the permission
chmod 770 /postgresql/data/
the we will run the command 
if get this error means the initdb is not added in environment of OS
usually the binary are located at ls /usr/lib/postgresql/13/bin/
to run the command you will have to put the full path of initdb binary
with follow up with the option and directory
make sure that command is not executed using the root user
if you ran to the below issue you also have to change the owner of the folder using chownchown postgres:postgres /postgresql/data/
then try to run the command again and it should execute correctly/usr/lib/postgresql/13/bin/initdb -D /postgresql/data/
now go to the file you created and you will see there files created on new directory
starting the cluster
once we created the cluster it wont start automatically , we need to start the cluster using the command
same issue as INITDB command you have to give the full path of the command or edit the environment to include the pg_ctl pathpg_ctl start/usr/lib/postgresql/13/bin/initdb -D /postgresql/data/
if will ran to error as showing below , because the cluster is using the same port 5432 as default cluster
you need to change it to random one
edit the postgresql.conf using nano and edit the port and enable listening to local host
now if you ran the command again it will execute successfully 

how to connect to the cluster
to connect to the new cluster we have created use the below syntax , and make sure to provide the correct port for the cluster
psql -U postgres [or any user you want] -p 5444[port number]\q
how to check the status of cluster
you can check if the cluster is runinng by using the below command/usr/lib/postgresql/13/bin/pg_ctl status -D /postgresql/data/

shutdown option
below command is related to shutdown the cluster
1- smart : the server disallow new connection , but the existent session work normally , its shutdown only after all session terminated.
2- fast (default) : the server disallow new connection and abort their current transaction and exit gracefully.
3-  immediate : quits/abort without proper shutdown which lead to recovery on next startup 
syntax
for the propose i will use smart option in shutdown the new cluster we have created , for the rest of shutdown option is basically the same .
pg_ctl stope -m smart[also you can uses immediate or fast] -D[data directory]
reload vs restart
reload is used when we did some changes on configuration files to , reload only load new config with restarting the services .
Some changes in config wont reflect unless we restart the services
restart : gracefully shutdown all activity , close all open files and start again with new configuration .
reload & restart syntax
reload : system reload postgresql-11
restart : systectl restart postgresql
pg_controldata
its used to provide information about cluster
such as version number , last checkpoint 
syntax
pg_contrldata /var/lib/pgsql/main

see data directory
to see the data directory connect psql client and use the below command
show data_directory;
