How to run pgAdmin 4 with Windows IIS
When managing relational databases, especially PostgreSQL, having a user-friendly interface can significantly streamline administration and development tasks. pgAdmin 4 is a powerful, free, open-source graphical management tool designed for PostgreSQL and derivative databases like EnterpriseDBās EDB Advanced Server.
pgadmin can be installed in two primary modes: Desktop mode, which runs as a standalone application, and Server mode, which enables remote access via a web browser. When deployed in server mode, pgadmin can be hosted behind web servers like Apache2 or Nginx, making it a scalable solution for teams and production environments.
This blog will guide you to set up pgadmin in the server mode behind Windows IIS.
A. Setting Up pgAdmin 4 in Server Mode on Windows
To run pgAdmin 4 behind IIS, you'll first need to set it up in server mode.
1. Install Python and pip -
pgadmin is distributed as a Python package and can be installed using pip. So, before installing pgadmin, ensure Python and pip are available on your Windows system.Download the latest version of Python for Windows from the official Python website. During installation, make sure to check the box that says āAdd Python to PATH.ā After installation, verify that Python and pip are available by running the following in Command Prompt:
PS C:\Users\Administrator> python --version
Python 3.13.4
PS C:\Users\Administrator> pip --version
pip 25.2 from C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pip (python 3.13)2. Create a virtual env -
To keep your pgadmin installation isolated from other Python packages create virtual environment and activate it.
PS C:\Users\Administrator> python -m venv pgadminVenv
PS C:\Users\Administrator> .\pgadminVenv\Scripts\Activate.ps1
(pgadminVenv) PS C:\Users\Administrator>3. Install pgadmin4 with the pip command -
(pgadminVenv) PS C:\Users\Administrator> pip install pgadmin4
Collecting pgadmin4
Downloading pgadmin4-9.7-py3-none-any.whl.metadata (2.8 kB)
4. Install the Waitress Python module -
By default, pgadmin uses Werkzeug as Web Server Gateway Interface (WSGI), which is designed for convenience during local development and is not optimized for high traffic or concurrent requests. Waitress is a Python (WSGI) server designed for serving Python web applications in production environments.
(pgadminVenv) PS C:\Users\Administrator> pip install waitress
Collecting pipB. IIS Installation
1. Navigate to Control Panel and select the 'Turn Windows features on or off' option.
2. Select 'Add Roles and Features' and click Next.
3. Select Role feature-based' installation.
4. Select the server pool and click on Next. Select Web server (IIS) and click Next, and again Next.
5. Here, confirm the modules to install and click on install. On successful installation, close the wizard.
6. Download httpPlatformHandler and install it. HttpPlatformHandler is required to manage and proxy requests to external applications like Python, acting as a reverse proxy to bridge IIS.
7. Open IIS Manager and from the Management section, select 'Configuration Editor'.
8. Select system.webserver, select handler, and click on āUnlock sectionā from the right panel.
9. Click on 'Add Website' from the sites context menu.
10. Enter website name and select physical path till the 'pgadmin' site package inside the venv.
11. Change binding settings according to your host, port, etc. Uncheck the check box - 'Start website immediately'.
C. Deploying pgAdmin behind the IIS web server
To enable access to pgAdmin through IIS, you need to configure IIS as a reverse proxy. This setup allows IIS to forward incoming HTTP(S) requests to the pgAdmin web server. By doing so, you can leverage IIS features such as SSL termination, authentication, and load balancing while securely exposing pgAdmin to users.
1. Copy the pgAdmin4.wsgi file and store the new file as pgAdmin4_wsgi.py alongside the original.
2. Add a web.config file to the directory where pgAdmin4_wsgi.py resides. Below is a typical example of a web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler"
path="*"
verb="*"
modules="httpPlatformHandler"
resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform
stdoutLogEnabled="true"
stdoutLogFile="C:\inetpub\logs\pgadmin\pgadmin.log"
startupTimeLimit="10"
processPath="C:\Users\Administrator\Desktop\pgadminVenv\Scripts\python.exe"
arguments="-m waitress --port %HTTP_PLATFORM_PORT% wsgi:application" />
</system.webServer>
</configuration>3. Make sure your log file location mentioned in above is writable by user IIS APPPOOL\PgAdmin. (Here - C:\inetpub\logs\pgadmin\ . You may grant permission to a generic user like IIS_IUSRS).