Handling technical matters related to a server are never easy, especially for those that are technically inept. So, for the convenience of the users of servers and to enhance the technical expertise of all our readers, we have made sure to explain in full detail how to install or update PostgreSQL on a server. Regardless of the efficacy of this content, we strongly recommend that you avail the services of a competent and experienced PostgreSQL database administrator for carrying out this process successfully.
Before proceeding further, it is important to mention that the content here is relevant for only those versions of PostgreSQL that are installed with the /usr/local/cpanel/scripts/installpostgres script, and not for the versions of PostgreSQL that have been installed via any other method.
Back up Databases
Prior to installing or updating PostgreSQL on a server, the server’s databases need to be backed up. This helps to restore the databases post installing or updating PostgreSQL.
In order to back up the databases, you are required to log in to your server as the root user.
This log in can be ensured via SSH. Next you need to carry out the below-mentioned steps.
Run the following command to back up the PostgreSQL databases on your server –
Pg_dumpall -U postgres > db.out
Here, the database backup file is represntated by db.out
You need to move your current PostgreSQL data directory in order to revert to your previous version of PostgreSQL. Run the below-mentioned commands for this purpose.
service postgresql stop
mv /var/lib/pgsql /var/lib/directory_file_name
Here, the actual directory name is represented by /directory_file_name
If you enabled the option, “Monitor”, via the Service Manager interface of WHM, then you need to deselect the checkbox that is present in the Monitor column, prior to running this command. This aids in preventing an automatic restart of the service of PostgreSQL, after you stop it.
Install/Upgrade and Configure PostgreSQL
For installing or upgrading, and configuring PostgreSQL on your server, you need to perform the following steps-
Run the below-mentioned command to install or upgrade PostgreSQL
/usr/local/cpanel/scripts/installpostgres
Access the Configure PostgreSQL interface of WHM
Click Install Config, if PostgreSQL is not present on your server. Here, it needs to be mentioned that if a PostgreSQL configuration exists on your server, then this action will overwrite your configuration authentication file.
Click Create Users for adding current cPanel users to PostgreSQL
Now you need to enter a new password in the text box, Enter New Password
Confirm your new password
Click Change Password
Next you need to import your databases. Run the below-mentioned command for this purpose.
psql -U postgres dbname < dumpfile.sql
Restore a Previous Version of PostgreSQL
You can revert to your earlier version of PostgreSQL and subsequently restore the previous PostgreSQL data directory, if the new installation fails. For this purpose you should run the following commands-
service postgresql stop
mv /var/lib/pgsql /var/lib/directory_file_name
mv /var/lib/pgsql.old /var/lib/pgsql
service postgresql restart
Equipped with this information you can easily install or update PostgreSQL on your cPanel Server. Here, we would like to add that HTS Hosting provides servers and web hosting services that are extremely affordable, efficient, and highly sought-after globally for the outstanding quality of service delivered by us. Our clients frequently describe us with terms such as the, “Best Windows Hosting Company”, the “Best Website Hosting Company”, the “Best Cloud Hosting Company” etc. HTS Hosting’s commitment to constantly deliver top-tier quality is reflected in the popularity of and demand for our services throughout the world.
Comentários