CLUSTER AND MULTICLUSTERS IN POSTGRESQL

Share via:
CLUSTER AND MULTICLUSTERS IN POSTGRESQL:

In PostgreSQL Before you can start a PostgreSQL server, you need to create a cluster. A cluster refers to a collection of databases managed by a single instance of the PostgreSQL server.

When you install PostgreSQL, It doesn’t automatically create a cluster. You have to initialize a cluster first, which involves following setup.

1. Firstly, creation of a directory. The cluster directory typically resides in a designated location on your system. Here run the commands to create a directory and transfer owner privileges to ‘Postgres’ user.

2. Switch to the Postgres user to create the cluster. Run the following command:

3. Use the ‘initdb command, which initializes the data directory and essential system files for the PostgreSQL server. The initdb command also sets up the default template database, configuration files, and other necessary components. Run the following command:

Here, PostgreSQL creates the necessary files and directories within the specified location. i.e., /u01/data. Verify files in the data directory:

Customize the PostgreSQL configuration files, such as postgresql.conf and pg_hba.conf, based on your specific requirements.

4. Start the PostgreSQL server using the ‘pg_ctl’ command, which is used to start, stop, or check the status of the cluster. Run following command to start the cluster:

5. To list running processes, run the command ‘ps -ef | grep postgres, it will display a list of processes related to PostgreSQL. The ‘grep command filters the output of ‘ps -ef and only shows the lines containing the keyword “postgres”. This is useful for Identifying PostgreSQL-related processes running on the system.

After the cluster is created and the server is started, you can connect to the you can connect to server using a client application, such as ‘psq1, and begin creating databases, tables, and performing various database operations.

 

MULTICLUSTER CONFIGURATION:
In PostgreSQL, each cluster is associated with a specific PostgreSQL version and runs on a specific port. Here we run the multiple PostgreSQL instances on the same machine, you need to create separate clusters for each instance, ensuring they use different ports and data directories.
1. Firstly, create the new data_directory as shown above. (/u01/data1)
2. Run the ‘initdb’ command to intialize the cluster
3. Customize the PostgreSQL configuration file ‘postgresql.conf’i.e changing the port number from default port number (5432) to different port number (5433). By doing the following steps :

5. Run below command to verify the list of active processes.

6. To connect to the particular psql application of a cluster. Run the command with the port number.

 

Author    : Prudhvi Teja
LinkedIn  : http://linkedin.com/in/prudhvi-teja-nagabhyru-715052224
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTExperts is always active on social media platforms.
Facebook  : https://www.facebook.com/ktexperts/
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment