0% found this document useful (0 votes)
54 views5 pages

Create A New Cluster in Postgres V16

How to create New cluster in PostgreSQL v16

Uploaded by

Ravindra Malwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views5 pages

Create A New Cluster in Postgres V16

How to create New cluster in PostgreSQL v16

Uploaded by

Ravindra Malwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Topic: Create a new cluster in Postgres V16

O nce you complete the PostgreSQL installation. You will get the default cluster with data location

/var/lib and port number 5432. If you want to configure the new cluster as per your requirements like
specific port number and storage location you can configure it. In this section, we are deploying the new
cluster with port 5433 and storage location /u01.

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 :

• Prerequisite Steps
- Validate cluster is up and running, current cluster port number
- Create the directory to store new cluster configuration and database files and folder
- Provide appropriate permission to Postgres user on the newly created folder
• Create and initialize the cluster
• Validation
Step-1 Prerequisite Steps

- Validate cluster is up and running, current cluster 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 ~]$

- Let's make some changes in Postgresql.conf file like port which is not in use. In this
deployment, I choose the 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 new 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
- Connect the newly created cluster using the default user and password which we entered
in step-2
[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.

You might also like