Hi Aishwarya Shukla,
python manage.py dbshell calls the system psql client, which isn’t installed in the built-in App Service runtime image. Because your database is on a private network, the easiest, safest options are:
- run
psqlfrom a machine that has network access to the private DB (Cloud Shell only if it can reach the private endpoint), or - add the
psqlclient to the environment that runs your app (use a custom container that includes the client), or
create a temporary jumpbox (Linux VM) inside the same VNet and run psql / manage.py dbshell from there.
Below I give step-by-step options and sample commands so you can pick the one that fits your setup.
Option A : use Azure Cloud Shell (if it can reach the DB)
Azure Cloud Shell (Bash) commonly includes the psql client already. Try:
# check if psql exists in Cloud Shell
psql --version
# connect (replace placeholders)
export PGPASSWORD='YourDbPassword'
psql -h <db-hostname-or-ip> -U <db-username> -d <db-name>
If the DB is on a private endpoint and your Cloud Shell cannot reach it, this will fail. Cloud Shell runs in Microsoft-managed infra and typically cannot access private endpoints unless you have configured network peering or a Cloud Shell VNet integration scenario — so test first.
Option B : create a temporary jumpbox VM in the same VNet
Create a small Linux VM in the same VNet (or subnet) that has network access to the private DB. Install postgresql-client then use psql or run python manage.py dbshell there.
Example (az cli):
# create VM (Ubuntu), in resource-group and vnet that can reach your DB
az vm create \
-g <resource-group> -n jumpbox-vm \
--image UbuntuLTS \
--size Standard_B1s \
--admin-username azureuser \
--generate-ssh-keys \
--vnet-name <your-vnet> --subnet <your-subnet>
# SSH into VM
ssh azureuser@<vm-public-ip-or-private-ip-if accessed via VPN>
# on the VM:
sudo apt-get update
sudo apt-get install -y postgresql-client python3 python3-venv
# test psql
psql --version
# connect
export PGPASSWORD='YourDbPassword'
psql -h <db-private-ip-or-host> -U <db-username> -d <db-name>
# or run your Django dbshell (ensure your app code & env are present)
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt python manage.py dbshell
This works because the VM sits in the same private network and can reach the DB.
Option C — Add psql to App Service runtime by using a custom container
If you prefer to run python manage.py dbshell on the App Service itself, build and deploy a custom Docker image that includes the postgresql-client package and your app. Example Dockerfile
FROM mcr.microsoft.com/azure-app-service/python:3.11-python3.11-appservice
# or FROM python:3.11-slim if you prefer
RUN apt-get update && apt-get install -y postgresql-client
# copy app
WORKDIR /home/site/wwwroot
COPY . .
# install python deps
RUN pip install -r requirements.txt
CMD ["gunicorn", "yourproject.wsgi:application", "--bind", "0.0.0.0:$PORT"]
Deploy this container to App Service for Linux. The container will have psql available so python manage.py dbshell will work inside the container (via SSH into container).
Option D — Use Azure Database for PostgreSQL built-in tools / Data Tools
If your integrated PostgreSQL is an Azure PaaS (Flexible Server / Single Server) and is not private endpoint only, you can use:
Azure Data Studio or pgAdmin from a machine with network access (or via a VM/jumpbox),
Or enable temporary public access (not recommended for production) to perform one-off admin tasks.
Extra tips for dbshell & credentials
python manage.py dbshell uses your DATABASES settings (in settings.py). Ensure ENGINE is django.db.backends.postgresql and HOST, PORT, USER, PASSWORD are reachable from where you run the command.
To avoid interactive password prompts you can use .pgpass on the client machine:
# ~/.pgpass format: hostname:port:database:username:password
echo "<db-host>:<port>:<db-name>:<db-user>:<db-password>" >> ~/.pgpass
chmod 600 ~/.pgpass
psql -h <db-host> -U <db-user> -d <db-name>
Why you couldn’t just apt-get install psql inside App Service
- The built-in App Service runtime images are managed by Azure and are mostly readonly for system package installs; you generally cannot use
sudo apt-getthere. That’s why you must either use a custom container (so you control packages) or an external machine with network access.
What I recommend
If you only need psql once or occasionally: create a small temporary VM in the same VNet and use that as a jumpbox.
If you want to regularly run dbshell or need extra admin tooling from the App itself: switch to a custom container that includes postgresql-client.
If Cloud Shell can reach the DB, try that first — it’s quickest.