Install or Update PostgreSQL® on Your cPanel & WHM Server
Last modified: March 1, 2024
Overview
This document explains how to install or update PostgreSQL® on a server. However, we strongly recommend that you allow an experienced PostgreSQL database administrator to perform this process.
- We only support versions of PostgreSQL that you install with the
/usr/local/cpanel/scripts/installpostgres
script. We do not support versions of PostgreSQL that you install via any other method. - cPanel & WHM functions with the version of PostgreSQL that ships with your operating system.
- This script does not run on servers that use the Ubuntu® operating system.
Back up databases
Before you install or update PostgreSQL on your server, back up your server’s databases. This action allows you to restore your databases after you install or update PostgreSQL.
To back up your databases, log in to your server as the root user via SSH and perform the following steps:
-
Back up the PostgreSQL databases on your server. To do this, run the following command:
pg_dumpall -U postgres > db.out
Note:In this example,db.out
represents the database backup file. -
To revert to your previous version of PostgreSQL, move your current PostgreSQL data directory. To do this, run the following commands:
1 2
systemctl stop postgresql.service mv /var/lib/pgsql /var/lib/directory_file_name
Note:- In this example,
/directory_file_name
represents the actual directory name. - If you enabled the Monitor option through WHM’s Service Manager interface (WHM » Home » Service Configuration » Service Manager), deselect the checkbox in the Monitor column before you run this command. This action prevents an automatic restart of the PostgreSQL service after you stop it.
- In this example,
Install or upgrade and configure PostgreSQL
To install or upgrade and configure PostgreSQL on your server, perform the following steps:
-
Run the
/usr/local/cpanel/scripts/installpostgres
command to install or upgrade PostgreSQL. -
Access WHM’s Configure PostgreSQL interface (WHM » Home » Database Services » Configure PostgreSQL).
- In cPanel & WHM version 118 and earlier, we title the Configure PostgreSQL interface’s section in the WHM interface SQL Services.
- In cPanel & WHM version 120 and later, we title the Configure PostgreSQL interface’s section in the WHM interface Database Services.
-
Click Install Config if PostgreSQL does not exist on your server.
Warning:If a PostgreSQL configuration already exists on your server, this action overwrites your configuration authentication file. -
Click Create Users to add current cPanel users to PostgreSQL.
-
Enter a new password in the Enter New Password text box.
-
Confirm your new password, and click Change Password.
Warning:Only use letters and numbers. Non-alphanumeric characters can cause errors to occur. -
Import your databases. To do this, run the following command:
psql -U postgres dbname < dumpfile.sql
Restore a previous PostgreSQL version
If the new installation fails, revert to your previous version of PostgreSQL and restore the earlier PostgreSQL data directory. To do this, run the following commands:
|
|
For more information about PostgreSQL, visit the PostgreSQL website.