When databases live inside a private subnet, direct connections aren’t an option. Traffic must move through a secure path without exposing the database to the public internet. Setting up Pgcli in this environment requires a precise workflow: configure the VPC, provision a bastion or proxy, secure credentials, and tunnel the connection.
Configuring the VPC starts with ensuring your database instance has no public IP. Place it in a private subnet with the correct route tables. This reduces the attack surface and keeps compliance checks simple.
Deploying the proxy is next. Use a lightweight, isolated VM or managed service in a public subnet that can talk to your database. Lock it down with security groups that only allow specific inbound IPs and the necessary outbound PostgreSQL port. The proxy becomes the single controlled entry point.
Building the secure SSH tunnel is the final step before Pgcli comes into play. Forward local ports from your development machine to the database host through the proxy. Keep authentication tight with SSH keys, and avoid password prompts in workflows by using agents.