Get started with Managed PostgreSQL
Create a single-node database, read its password, connect with psql over TLS, and delete it again, in about ten minutes.
Replace orders with a name of your own and ewdb-0123456789ab with the id the create returns.
Prerequisites
- Permission for
rds:CreateDBInstance,rds:DescribeDBInstancesandrds:DeleteDBInstance, andsecrets:GetSecretValueto read the password. - For the CLI steps, the dcloud CLI, signed in. For the connection,
psqlon your computer.
Step 1: Create a database
A single node on a performance-2, reachable from the internet so that you can connect from your
computer. You pay for the database from now on.
- Open Postgres, then choose Create Postgres database.
- For Name, enter orders.
- Under Size, for Nodes, choose Single node.
- For Machine type, choose
performance-2. - Under Security, select Reachable from the internet.
- Choose Create database.
The database page opens with the status creating.
dcloud rds instances create --identifier orders --instance-class performance-2 --publicly-accessiblePOST /rds/api/instances
{ "identifier": "orders", "instanceClass": "performance-2", "publiclyAccessible": true }resource "dcloud_db_instance" "orders" {
identifier = "orders"
instance_class = "performance-2"
publicly_accessible = true
}The status changes from creating to available within a few minutes. Each step appears on the
database's Activity.
Step 2: Read the master password
- On the database page, choose Connection.
- Under Master password, choose Reveal.
The database's masterSecretId names the secret:
dcloud rds instances get ewdb-0123456789ab
dcloud secrets secrets get-value master-secret-idGET /rds/api/instances/ewdb-0123456789abThen read the value of the secret named by masterSecretId with
GET /secrets/api/secrets/{masterSecretId}/value.
dcloud_db_instance.orders.master_secret_id names the secret that holds the password.
Reading a secret value is recorded in the audit log.
Step 3: Connect
The Connection tab shows the connection strings. The CLI downloads the platform's CA and runs
psql with it, so verify-full checks that you reach your own database:
dcloud rds exec -- psql "postgresql://admin:<password>@<endpoint>:6432/appdb?sslmode=verify-full"admin and appdb are the defaults for the master user and the first database. Run
SELECT version(); to see the server answer.
Clean up
Delete the database so that you stop paying for it.
- On the database page, choose Danger zone.
- Under Delete this database, clear Take a final backup and keep the backups for N days.
- Choose Delete database.
- Enter the database name, and choose Delete database.
dcloud rds instances delete ewdb-0123456789abDELETE /rds/api/instances/ewdb-0123456789abterraform destroyThe machine, its volume, its address and its backups are removed.
Next steps
- Connect to a database from an application.
- Create a database as a cluster, in a private network.
- Instances, clusters and endpoints