How to Create PostgreSQL Managed Database at DigitalOcean
Managed Database is a cloud service that provides a database engine. With a managed database, users no longer need to install and configure databases, including monitoring and maintaining server infrastructure.
Managed database services aim to make users, especially developers, focus on application development, without having to be bothered with managing databases.
DigitalOcean provides managed database services that support 3 database engines, namely MySQL, PostgreSQL, and Redis.
Get started on DigitalOcean with $200, 60-day credit for new users.
Create a PostgreSQL Managed Database
- Click the Create->Databases menu
- Choose a database engine, select PostgreSQL
- Choose a cluster configuration, here I use the specifications of 1GB RAM, 1vCPU, 10GB disk, without Standby Nodes. Standby Nodes are the nodes that become the backup server, if a failure occurs on the main database server, the database service is switched to the standby node (automatic failover)
- Choose a datacenter, here I use Singapore
- Choose a unique database cluster name, enter a name for the cluster database
- Finally, click the Create a Database Cluster button
Connection to the Database Cluster
- Secure this database cluster, in the field Add trusted sources, enter the name of the droplet, kubernetes cluster, tags, or IP address that is granted access to the database. Here I enter the ubuntu droplet that is in the same region and private network. Then click Allow these inbound sources only
- Connection details, displayed connection information to the cluster database, and connections via public and private networks. Click Continue
- Next steps, a command is displayed to perform a database migration. Click Great, I’m done
Create User and Database
Create a user and database can be done directly in the tab Users & Databases.
Create User
- Add new user, enter a new user
- Password is provided automatically
Create Database
- Add new database, enter a new database name
Connect to Database
Previously the database cluster was set up so that it could only be accessed by the ubuntu droplet, therefore database access tests were run on that droplet.
Connect to database using psql, install the PostgreSQL client on Ubuntu.
1 | apt install postgresql-client -y |
Copy the command to connect to the database (flags) shown in the connection details.
Testing database access via the public network.
1 | PGPASSWORD=cew2dcuz9vnt4kqq psql -U webapp -h db-postgresql-sgp1-30834-do-user-4254703-0.b.db.ondigitalocean.com -p 25060 -d webapp --set=sslmode=require |
Testing database access via private network.
1 | PGPASSWORD=cew2dcuz9vnt4kqq psql -U webapp -h private-db-postgresql-sgp1-30834-do-user-4254703-0.b.db.ondigitalocean.com -p 25060 -d webapp --set=sslmode=require |
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin