When installing PostgreSQL, it defaults to creating its data directory in /var/lib/postgresql.
For better performance, reliability, and management, it is often recommended to relocate the PostgreSQL data directory to a dedicated disk or separate mount point. This can help with I/O performance, backup management, and isolation of database operations from the rest of the system.
drop and create new dp_cluster ubuntu
the steps for PostgreSQL 15 different version may differ
we will first create directory and with b owner be postgres
user.
and the permission should be sit to 600
| sudo mkdir postgresqldata sudo chown -R postgres:postgres postgresqldata/ sudo chmod 600 postgresqldata/ | 

the directory is mount on separate disk
df -h

we will start stop the cluster then dropping it
| pg_lsclusters — view cluster name and status sudo pg_ctlcluster stop 15 main ——– [stop,start,] [version] [clustername] pg_dropcluster 15 main — drop the cluster and it will also delete its config directory | 

create cluster
| sudo pg_createcluster -d postgresqldata/ -u postgres -p 5432 15 myclsuter #pg_createcluster -d [data dir path] -u [ownerexit username] -p [port number] [version][cluster name ] sudo pg_ctlcluster start 15 myclsuter pg_lsclusters | 



drop and create new dp_cluster redhat
in redhat its dirent you need to first stop PostgreSQL services
| systemctl stop postgresql | 
then remove default data dir directory completely
| sudo rm -r /var/lib/postgresql/15/main | 
Remove the configuration files
| rm -r /etc/postgresql/15/main | 
then create new cluster after that start the services
| initdb -D /usr/local/pgsql/data pg_ctl start -l logfile |