How to Manage PostgreSQL Users and Databases in a Database Cluster
Validated on 8 Aug 2019 • Last edited on 8 Jul 2024
PostgreSQL is an open source, object-relational database built for extensibility, data integrity, and speed. Its concurrency support makes it fully ACID-compliant, and it supports dynamic loading and catalog-driven operations to let users customize its data types, functions, and more.
PostgreSQL database clusters come configured with a default database (defaultdb) and a default administrative user (doadmin). These defaults are necessary for cluster replication and administration, so you can’t delete them, but you can add additional users and databases.
If you connect to the database cluster with preconfigured connection details from the cluster’s Overview page, you can edit them to use a different user and password or a different database.
Add or Delete a Database User Using the CLI
How to Create a Database User Using the DigitalOcean CLI
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
delete_resp = client.databases.delete_user(database_cluster_uuid="aba134a", username="backend_user1")
Add or Delete a Database User Using the Control Panel
To add or delete users or databases to a database cluster, click the name of the database to go to its Overview page, then select the Users & Databases tab.
Create a new database in the Databases section by entering a name in the Add new database field and clicking Save. You can also delete a database here by opening its More menu, clicking Delete, and then confirming the deletion.
Create new users in the Users section by entering a name in the Add new user field and clicking Save. New users receive minimal permissions by default. You can then add user privileges using third-party tools like psql. However, you cannot grant users some superuser permissions.
You can also delete a user here by opening the user’s More menu, clicking Delete, and then confirming the deletion. Similarly, to reset a user’s password, open the user’s More menu and select Reset password.