# Accessing PostgreSQL Using pgAdmin with a Dockerized Apache Airflow Setup

In this blog, i will guide you through the process of accessing your PostgreSQL database using pgAdmin in a Dockerized Apache Airflow setup. pgAdmin is a powerful and user-friendly tool that allows you to manage and interact with your PostgreSQL databases efficiently. By the end of this tutorial, you'll be able to visualize your database schema, run queries, and manage your database objects with ease.

### **Setup Airflow**

Refer to my previous article [https://vipinmp.hashnode.dev/quick-and-easy-apache-airflow-setup-tutorial](https://vipinmp.hashnode.dev/quick-and-easy-apache-airflow-setup-tutorial) on setting up Airflow in the dockerizd environment.

### **Setting Up pgAdmin**

**Turn Down the Existing Airflow Service:** If your Airflow setup is already running, you need to stop the service first. Use the following command in your terminal:

```bash
docker-compose down
```

**Update Your Docker Compose Configuration:** Next, let's add the pgAdmin service to your Docker Compose setup. Open your `docker-compose.yml` file and update it with the following content to include pgAdmin:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735428403066/90d37cc6-d543-4c2b-8914-89987e71f6f7.png align="center")

```yaml
pgadmin:
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - "5050:80"
```

### **Access pgAdmin**

After updating the `docker-compose.yml` file, restart the services:

```bash
docker-compose up
```

Open your browser and go to [`http://localhost:5050`](http://localhost:5050) to access pgAdmin. Use the email [`admin@admin.com`](mailto:admin@admin.com) and the password `admin` to log in.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735428674982/a1e6ec04-d617-4a60-a93a-95a28f349d00.png align="center")

### **Connect pgAdmin to PostgreSQL**

1. **Get the IP address of postgres container.**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735429148685/0831e1a0-fbea-4538-a303-cc9449915da9.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735429301269/bbe604c9-b885-4032-8fc5-ffd0def34f34.png align="center")
    
2. **Create a New Server:**
    
    * Right-click on "Servers" in the pgAdmin interface and select "Register" -&gt; "Server...".
        
3. **Configure the Connection:**
    
    * **General Tab:** Name your server (e.g., "postgreSQL\_airflow").
        
    * **Connection Tab:**
        
        * **Hostname/Address:** `172.19.0.2`
            
        * **Port:** `5432`
            
        * **Maintenance database:** postgres
            
        * **Username:** `airflow`
            
        * **Password:** `airflow`
            
4. **Save the Configuration:**
    
    * Click "Save" to create the server connection.
        

Now, you should be able to see your PostgreSQL database in pgAdmin. You can browse the schema, run queries, and manage your database objects.

### **Practice task:**

Create a database called `ecommerce`. With the help of Query Tool(Right Click e-commerce database →Query Tool), create a table called `employees`, insert some records, and execute queries on this table.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735430648116/b120b77a-3fb6-4666-93c8-701b8010c17c.png align="center")

### **Conclusion**

By following these steps, you can set up a Dockerized Apache Airflow environment and access your PostgreSQL database using pgAdmin. This setup allows you to easily manage and interact with your databases, enhancing your workflow and data analysis capabilities.
