Database

Setting Up Your Database on PostgreSQL in Your Cloud

Your cloud’s own PostgreSQL on Azure, AWS or Google Cloud, or a server of yours, with the small Pental gateway beside it. One command builds it all, and it applies Pental’s signed updates itself.

10 min read · Updated

Nothing from Supabase is involved. The Pental gateway is one small service that runs beside your PostgreSQL and gives the portal what it needs: the tables under the schema’s row-level security, sign-in, files and live updates. The schema in your database is the portal’s own, unchanged. Pental never holds your database’s password or the gateway’s setup token: only the gateway’s address, its publishable key and a provisioning credential your database records every use of.

Pros and cons

Pros

  • Your cloud’s own managed database (Azure Database for PostgreSQL, Amazon RDS or Cloud SQL), under the contract and controls you already have, with daily backups on from the first command.
  • One command creates the database, deploys the gateway and prints what the setup asks for.
  • On Azure the database has no public address, and on AWS it sits in private subnets.
  • Updates apply themselves every day, only when Pental has signed them, and your dashboard applies one at once.

Cons

  • Your cloud bills you for the database and for a gateway that is always running.
  • The setup token is yours to keep safe: it applies an update on demand, and a move needs it.
  • The gateway is one more service to keep current: a new version is the same command, pasted again.

What each cloud needs and makes

Each script runs on your own computer, Windows, macOS or Linux, signed in to your cloud (for your own server, on that server), and makes everything in your own account. A cloud’s command line that your computer does not have, the script puts in for you once you say yes. Azure and Google Cloud give the gateway an https address of their own, so there is nothing to set up in your DNS; AWS and your own server need a name on your firm’s domain, explained below.

WhereWhat you need, and what it makes
Microsoft AzureThe Azure CLI. Not signed in yet, the script signs you in from your browser (az login), or on a computer with no browser with a code you type at microsoft.com/devicelogin on any device. It makes Azure Database for PostgreSQL (Flexible Server) in a private network of its own with no public address, the gateway on Azure Container Apps with https on an Azure address, and a container registry for its image.
Amazon Web ServicesThe AWS CLI, and nothing else: the gateway’s image is built in your account by AWS CodeBuild. Not signed in yet, the script signs you in from your browser with your AWS console sign-in (aws login, with no access key to make; it updates the AWS CLI first when that is older than 2.32), or with single sign-on (aws sso login) where your AWS profile uses it. It makes Amazon RDS for PostgreSQL in private subnets, the gateway on ECS Fargate behind a load balancer with a certificate for a name of yours, and the secrets in Secrets Manager.
Google CloudThe gcloud CLI, and billing on the project. Not signed in yet, the script signs you in from your browser (gcloud auth login), or on a computer with no browser with a link you open on any device, and with no project chosen (gcloud init chooses one) it takes your only one or asks which. It makes Cloud SQL for PostgreSQL, the gateway on Cloud Run with https on a Google address, and the secrets in Secret Manager.
Your own serverA Linux server you can sign in to with ssh, a DNS name pointed at it and ports 80 and 443 open; Docker is put on it for you if it is not there. It makes PostgreSQL 16, the gateway and Caddy (https from Let’s Encrypt) as containers on that server.

The gateway’s name on your domain

It is a name you make up, under a domain your firm owns, such as db.yourfirm.com. Nothing needs to exist yet. AWS gives a load balancer no https address of its own, so there the gateway answers on this name, with a certificate AWS issues for it; your own server answers on it with a certificate of its own. The Database step fills one in from your firm’s domain, looks it up as you type, and says where the domain’s DNS is managed and what to do there:

Where your DNS isWhat happens
Route 53, in the AWS account you deploy toNothing to add: the AWS script makes the certificate’s record and the name itself.
Anywhere else (Cloudflare, GoDaddy, your IT provider)While the AWS script runs, it shows two records to add there, one that proves the name is yours and one that leads it to the gateway, with their names as your DNS provider wants them typed. It watches for both, says when each is in place or what is wrong with it, and carries on by itself once they are in. At Cloudflare, add them as DNS only.
Your own serverOne A record, the name to the server’s public IP address, which the paste on the server shows you with the Name as your DNS provider wants it typed. The server gets its certificate by itself.

Run one command

The Database step writes the command for your cloud and your computer, with your portal’s address, the region nearest you (another is a choice from the list) and the name, where the cloud needs one, already in. One paste downloads the newest gateway into a pental-gateway folder in your home folder, showing it come in, trying again by itself if your connection drops, and checking it against the SHA-256 pental.io publishes, then runs its deploy script, which says what it is doing at every step and counts the time while your cloud works. Keep that folder: the secrets the script makes are kept in it. Download the Pental gateway there is the same file, to look inside first. These are its shapes:

Commands for
Windows, in PowerShell
# Microsoft Azure: resource group, region, portal
cd ~; curl.exe -fsSLO --retry 3 --retry-all-errors https://pental.io/downloads/pental-gateway.ps1; if ($?) { powershell -ExecutionPolicy Bypass -File pental-gateway.ps1 azure pental-rg uksouth https://yourfirm.pental.io }

# Amazon Web Services: stack, region, portal, the name on your domain
cd ~; curl.exe -fsSLO --retry 3 --retry-all-errors https://pental.io/downloads/pental-gateway.ps1; if ($?) { powershell -ExecutionPolicy Bypass -File pental-gateway.ps1 aws pental eu-west-2 https://yourfirm.pental.io db.yourfirm.com }

# Google Cloud: region and portal, in the project gcloud is set to
# (or the project ID first, then the region and the portal)
cd ~; curl.exe -fsSLO --retry 3 --retry-all-errors https://pental.io/downloads/pental-gateway.ps1; if ($?) { powershell -ExecutionPolicy Bypass -File pental-gateway.ps1 gcp -Region europe-west2 -PortalUrl https://yourfirm.pental.io }
macOS and Linux, in a terminal
# Microsoft Azure: resource group, region, portal
curl -fsSL --retry 3 https://pental.io/downloads/pental-gateway.sh | sh -s -- azure pental-rg uksouth https://yourfirm.pental.io

# Amazon Web Services: stack, region, portal, the name on your domain
curl -fsSL --retry 3 https://pental.io/downloads/pental-gateway.sh | sh -s -- aws pental eu-west-2 https://yourfirm.pental.io db.yourfirm.com

# Google Cloud: project ("" for the one gcloud is set to, or its ID), region, portal
curl -fsSL --retry 3 https://pental.io/downloads/pental-gateway.sh | sh -s -- gcp "" europe-west2 https://yourfirm.pental.io

Each runs pental-gateway.ps1 on Windows or pental-gateway.sh on macOS and Linux, there to read first. On Windows each is one line, as Windows PowerShell’s own window runs a pasted block of lines bottom to top. -ExecutionPolicy Bypass lets Windows run the downloaded script that once and changes no setting; Windows 10 and 11 come with curl.exe. For your own server, sign in to it (ssh you@db.yourfirm.com, from PowerShell or Terminal) and paste this there. It puts in Docker if the server does not have it, downloads the gateway, makes its secrets and starts it (pental-server.sh, to read first):

curl -fsSL https://pental.io/downloads/pental-server.sh | sh -s -- gateway db.yourfirm.com https://yourfirm.pental.io
  • It is safe to run again: it keeps the secrets it made, in a .deploy-*.env file beside the script that only you can read, and updates in place.
  • On AWS the gateway answers on a name of yours. If that name’s DNS zone is in Route 53 in the same account, the certificate and the record are made for you; otherwise the script shows the two records to add and waits for them.
  • When it finishes it prints the gateway’s address and a setup token.

Put it in your password manager. It applies an update on demand, and a move uses it later. It goes from your browser to your gateway and nowhere else: Pental never sees it and never stores it.

Connect it on pental.io

On the Database step choose PostgreSQL in your cloud and paste what the script printed, whole. The address and the token are taken from it, the box empties itself, and the gateway is asked at once whether it answers. Then press Set up and connect: your browser applies the portal schema through your gateway, reads its publishable key, has Pental check every service, and connects your portal. The token field is emptied after the run.

Keeping it updated

The gateway fetches Pental’s signed schema bundle every day and applies it itself, checked against the key the setup planted in your database; anything unsigned is refused. An update goes in whole or not at all, and never over a newer version. To apply one straight away, open Database on your pental.io dashboard, press Check for updates now, paste the setup token and choose Check and apply.

The gateway itself updates the way it installs. When your dashboard says a newer gateway is out, paste the same command again: it fetches the newest gateway over the same folder, where the script keeps the gateway’s secrets, and updates in place. On your own server, the same on the server.

If something is not right

What you seeWhat to do
No Pental gateway answers there yetIf the script has only just finished, give it a minute: the setup keeps asking by itself.
The gateway answers but cannot reach its databaseThe database may still be starting. If it carries on, run the same command again from the same folder: it updates the deployment in place.
The gateway does not accept this setup tokenCopy it again from the script’s output or your password manager. It is also in the .deploy-*.env file beside the script.
The script stops: the gateway exists but this folder has no secretsRun it from the folder you deployed from, where its .deploy-*.env file is. New secrets would lock the gateway out of its own vault.
The script says the gateway is the gateway for another portalOne gateway serves one firm, and that name is in use for one. Press Enter for a gateway and database of this portal’s own (the script carries on, named for it). Choose 2 to take that one over and start it fresh, or 3 if it is the same firm at a new portal address, moving it with its data.
The script says the stack is the gateway at another nameThat gateway answers at the name it has, and giving it the new one would stop that. Press Enter for a second gateway and database at the new name, as a new home for a move needs (the script carries on, named after it). Choose 2 only to give this one the new name, with its data.
An earlier gateway answers thereThe name led to another gateway before, and this computer still has its old DNS answer: the page waits for the new one by itself. To hurry it, clear this computer’s copy (ipconfig /flushdns on Windows, sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on a Mac) and close the browser and open it again. The script says so too, and which stack the name led to. If it is a gateway you deployed earlier and mean to use, paste its setup token.
Set up and connect says the database already holds a portal’s dataA portal was moved away from it, or it was set up for one before. To use it for this portal, type the gateway’s name where the step asks and press Delete everything and set up: everything in it is deleted and it is set up as new. If that data is still wanted, connect another database instead.

Moving later

Move it to a self-hosted stack, Supabase Cloud or a second gateway whenever you like, with everything in it. The move uses the gateway’s setup token, and names a second gateway apart from this one.


Set It Up in the Trial

The Database step picks the region nearest you, offers a name on your own domain and puts both in the one command, then sets the database up through your gateway from your browser.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, on your own server.


Also Worth Reading

Setup guide

Prefer to watch it?

This step is in the recording as “Your database on PostgreSQL in your cloud”, from 0:43. Every other step is a chapter away.

  • 0:43 · Your database on PostgreSQL in your cloud
  • 3:15 · Email from your own address
  • 4:04 · Branding, and finishing setup
  • +4 more