Knowledge Base

How to manage PostgreSQL databases and users in cPanel

This article describes how to use cPanel to manage PostgreSQL databases and users.

Managing database users

To access PostgreSQL databases, you must first create at least one user. The following procedures describe how to manage PostgreSQL database users using cPanel.

Creating a database user

To create a PostgreSQL user, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Add New User, type the PostgreSQL username in the Username text box.
  3. In the Password text box, type the user password.
  4. In the Password (Again) text box, retype the user password.
    You can click Password Generator and cPanel generates a random, strong password for you.
  5. Click Create User.
Changing a user's password

You can change a database user's password. You may want to do this for security reasons (changing passwords periodically is a good security practice), or you may need to do this if you forget the password.

To change a PostgreSQL user's password, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Current Users, locate the user for which you want to change the password, and then click Set Password.
  3. In the Password and Password (Again) text boxes, type the new password.
    You can click Password Generator and cPanel generates a random, strong password for you.
  4. Click Change Password. The new password takes effect immediately.
Renaming a user

To rename a PostgreSQL user, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Current Users, locate the user that you want to rename, and then click Rename.
  3. In the text box, type the new name, and then click Proceed.
  4. In the Password and Password (Again) text boxes, type the password for the user, and then click Change Password.
    You can use the same password—you do not have to specify a new password.
Deleting a user

To delete a PostgreSQL user account, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Current Users, locate the user that you want to delete, and then click the red X icon.
  3. Click Remove User to confirm the deletion.

Managing databases

After you create a database user, you are ready to create a database and associate the user with the new database.

Creating a database

To create a PostgreSQL database, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Create New Database, type the name of the database in the Database Name text box.
    You cannot use capital letters in a PostgreSQL database name.
  3. Click Create Database.
    When you create a database, your username is added to the database name. For example, if your username is username, and you create a database named database, the actual PostgreSQL database name is username_database.
Adding a user to a database
Managing PostgreSQL user permissions can be tricky. You should import all PostgreSQL data as the primary PostgreSQL user (that is, by using your A2 Hosting account username). If you import PostgreSQL data as a regular user, you will be unable to see or manipulate the data properly using phpPgAdmin. After you have imported the data as the primary PostgreSQL user, you can create a regular database user and grant the user access to the data. Then you do not have to use the primary domain username and password in scripts that access the database.

To add a PostgreSQL user to a database, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Add User to Database, select the user that you want to add in the User list box.
  3. In the Database list box, select the database.
  4. Click Submit.
Removing a user from a database

When you remove a user from a database, the user is no longer able to access the database.

To remove a PostgreSQL user from a database, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Current Databases, locate the user that you want to remove, and then click the red X icon.
  3. Click Delete User from Database to confirm the deletion.
Deleting a database

Before you delete a database, make sure that you have a backup copy if you want to save any information that it contains.

When you delete a database, its associated users are not deleted. However, all permissions that users have for that database are deleted.

To delete a PostgreSQL database, follow these steps:

  1. In the Databases section of the cPanel home screen, click PostgreSQL Databases.
  2. Under Current Databases, locate the database that you want to delete, and then click Delete Database.
  3. Click Delete Database to confirm the deletion.

More Information

For more information about PostgreSQL, please visit http://www.postgresql.org.