Once the PostgreSQL installation is
done. You will get the default cluster with data location /var/lib and the port number default one 5432. After that, you can
configure the new cluster as per your requirements like specific port number and storage location. In this section, we are deploying the new
cluster. We will use port 5433 and storage location /u01 in our new Postgres cluster configuration.
Deployment diagram:
Infrastructure Details:
HOSTNAME: PG_V16.example.com
|
OS version
|
Red Hat Enterprise Linux release 8.6 (Ootpa)
|
PG Version
|
PostgreSQL 16.1
|
Port number
|
5433
|
Cluster location
|
/u01/app/postgres/product/v16
|
In this
QuickStart, we learn how to:
·
Prerequisite
Steps
-
Validate cluster
is up and running and current port number
-
Create the
directory to store new cluster configuration and database files and folder
-
Provide appropriate
permission to Postgres user on newly created folder
·
Create
and initialize the cluster
·
Validation
Step-1 Prerequisite
Steps
-
Validate cluster
is up and running and current port number
[postgres@PG-V16 ~]$ pg_ctl status
pg_ctl: server is running (PID: 766)
/usr/pgsql-16/bin/postgres "-D"
"/var/lib/pgsql/16/data/"
[postgres@PG-V16 ~]$
[postgres@PG-V16
~]$ psql
psql
(16.1)
Type
"help" for help.
postgres=#
show port;
port
------
5432
(1
row)
postgres=#
-
Create the
directory to store new cluster configuration and database files and folder
[root@PG-V16 ~]# mkdir -p /u01
-
Provide appropriate
permission to Postgres user on the newly created folder
[root@PG-V16 ~]# chown postgres:postgres /u01
[root@PG-V16 ~]# chmod 775 /u01
[root@PG-V16 ~]# su – postgres
[postgres@PG-V16 ~]$ mkdir -p
/u01/app/postgres/product/v16
[postgres@PG-V16 ~]$
Step- 2 Create and initialize the cluster
[postgres@PG-V16 ~]$ initdb -D
/u01/app/postgres/product/v16 -W
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.
Enter new superuser password:
Enter it again:
fixing
permissions on existing directory /u01/app/postgres/product/v16 ... ok
creating
subdirectories ... ok
selecting
dynamic shared memory implementation ... posix
selecting
default max_connections ... 100
selecting
default shared_buffers ... 128MB
selecting
default time zone ... America/New_York
creating
configuration files ... ok
running
bootstrap script ... ok
performing
post-bootstrap initialization ... ok
syncing
data to disk ... ok
initdb:
warning: enabling "trust" authentication for local connections
initdb:
hint: 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 /u01/app/postgres/product/v16 -l
logfile start
[postgres@PG-V16 ~]$
-
Make some changes
in Postgresql.conf file like port which is not in use. In this
deployment I choose 5433 port.
-
[postgres@PG-V16 app]$ cd
/u01/app/postgres/product/v16
[postgres@PG-V16 v16]$ ls -ltr postgresql.conf
-rw-------. 1 postgres postgres 29705 Dec 31 17:16
postgresql.conf
[postgres@PG-V16 v16]$
[postgres@PG-V16 v16]$ vi postgresql.conf
[postgres@PG-V16 v16]$ cat postgresql.conf | grep -w
'port'
port = 5433 # (change requires
restart)
# %r = remote host and port
[postgres@PG-V16 v16]$
-
Check
the current cluster status and start it if it is not running
[postgres@PG-V16 v16]$ pg_ctl -D
/u01/app/postgres/product/v16 start
waiting for server to start....2023-12-31
17:27:25.202 EST [1766] LOG: redirecting
log output to logging collector process
2023-12-31 17:27:25.202 EST [1766] HINT: Future log output will appear in directory
"log".
done
server started
[postgres@PG-V16 v16]$ pg_ctl -D
/u01/app/postgres/product/v16 status
pg_ctl: server is running (PID: 1766)
/usr/pgsql-16/bin/postgres "-D"
"/u01/app/postgres/product/v16"
[postgres@PG-V16 v16]$
Step-3 Validation
[postgres@PG-V16
v16]$ psql -p 5433 -d postgres -U postgres
psql
(16.1)
Type
"help" for help.
postgres=#
SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1
row)
postgres=#
INFORMATION:
pg_reload_conf() method shows you the reload configuration status.