Skip to content
cPanel Guides

How to Create a PostgreSQL Database in cPanel

Create a PostgreSQL database and user in cPanel with the wizard, connect your app on localhost, and manage and back up your database.

PostgreSQL connection details in cPanel: localhost, port 5432 and your database name

To create a PostgreSQL database in cPanel, open PostgreSQL Database Wizard, give the database a name, create a user with a strong password, and give that user access to the database. Your app then connects on localhost with the full database name and user name, which both start with your cPanel username. At HostGrap, PostgreSQL is included on cPanel Plus and bigger plans in Europe and Singapore, and on every Business cPanel plan. This guide shows each step.

Which HostGrap plans include PostgreSQL?

Plan rangePostgreSQL databases
cPanel hosting, EuropePlus: 5, Prime and Max: unlimited
cPanel hosting, SingaporeSG Plus: 5, SG Pro and SG Max: unlimited
Business cPanel hostingBusiness Lite: 5, Business Plus: 10, Business Pro and Business Elite: unlimited

The smallest plans, Core and SG Lite, include MySQL but not PostgreSQL. cPanel hosting on our Sri Lanka servers includes MySQL only, so for PostgreSQL choose Europe or Singapore, or a VPS where you install the database yourself.

When should I use PostgreSQL instead of MySQL?

Use the database your app was built for. WordPress, WooCommerce and most PHP apps need MySQL. Many Python, Node.js and Ruby apps, and frameworks such as Django, work best with PostgreSQL, and some only support it. If your app's install guide asks for PostgreSQL, use PostgreSQL.

How do I create a PostgreSQL database with the wizard?

  1. Log in to cPanel and open PostgreSQL Database Wizard in the Databases section.
  2. Type a name for the database, for example shop, and click Next Step. cPanel adds your cPanel username to the start, so the full name becomes something like cpuser_shop.
  3. Create a database user: type a user name and a strong password, or use the password generator, and click Create User. The user name also starts with your cPanel username.
  4. Give the user access to the database. Tick All Privileges for an app that manages its own tables, and click Next Step.

Copy the full database name, user name and password somewhere safe. You need them for your app.

How do I connect my app to the database?

Your app runs on the same server as the database, so it connects locally:

SettingValue
Hostlocalhost
Port5432
DatabaseYour full database name, such as cpuser_shop
UserYour full database user name
PasswordThe password you set

Many apps use a single connection string instead. It looks like this:

postgresql://cpuser_appuser:YOUR_PASSWORD@localhost:5432/cpuser_shop

Keep this string in an environment variable or a settings file outside public_html, never in a public file. For a Node.js app, add it under Environment variables in Setup Node.js App: see how to host a Node.js app in cPanel.

How do I manage databases and users later?

Open PostgreSQL Databases in cPanel. There you can create more databases and users, change a user's password, add a user to another database and delete a database you no longer need. Deleting a database removes all its data, so take a backup first.

How do I back up and restore a PostgreSQL database?

HostGrap backs up your account, including your databases, with daily and weekly backups on Europe, Singapore and Business plans. If you need a database restored from a backup, message our team. For your own copy, you can export the database from the terminal with pg_dump:

pg_dump -U cpuser_appuser -h localhost cpuser_shop > shop-backup.sql

If your database connection fails, check that the user has been added to the database and that you used the full names with your cPanel username at the start. If it still fails, message HostGrap AI on live chat or WhatsApp, or open a ticket, and our team will check it with you.

Share this article

More from the blog

All posts