# PostgreSQL

***<u><span style="font-size: 12.0pt; line-height: 107%;">Note:</span></u>****<span style="font-size: 12.0pt; line-height: 107%;"> Access to PostgreSQL is restricted to students with projects, and it can be accessed via special subnet (not available publicly to all students)</span>*

##### <span style="text-decoration: underline;">**<span style="font-size: 12.0pt; line-height: 107%;">How to Access Your Database:</span>**</span>

- <span style="font-size: 12.0pt; line-height: 107%;">First step, you need to request the creation of a database by sending an email to <accounts@cs.uwindsor.ca></span>
    - <span style="font-size: 12.0pt; line-height: 107%;">Provide details about your project, supervisor, and what is the suggested name of the database and include a list of all students (if applicable).</span>
- <span style="font-size: 12.0pt; line-height: 107%;">Once CS IT confirms the DB creation, you can log in to [https://psql.cs.uwindsor.ca](https://psql.cs.uwindsor.ca)   
    </span>  
    [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/roMimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/roMimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">If it’s your first time, click on “Add New Server”  
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/GZ0image.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/GZ0image.png)
    
    <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">  
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">In the (Register - Server) Windows:</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Name: localhost</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Hostname/address: localhost</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Maintenance database: Your DB name</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Username: your UWINID</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Password: your UWIN password</span>
    - <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Click on "Save"   
          
        </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/8tGimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/8tGimage.png)  
          
        [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/vdzimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/vdzimage.png)

##### <span style="text-decoration: underline;">**<span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Connect to PostgreSQL from console: </span>**</span>

- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Login/SSH to your project’s VM, then issue this command:</span>  
    `<span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">psql -h psql.cs.uwindsor.ca -U username -d db_name</span>`

#####  **<span style="text-decoration: underline;"><span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Connect to a database from your application:</span></span>**

- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">When connecting to a database from your application, e.g:  
      
    </span>```php
    <?php
    $pdo = new PDO(
        'pgsql:host=psql.cs.uwindsor.ca;dbname=db_name,
        'app_testuser',
        'myPassword'
    );
    $stmt = $pdo->query("SELECT current_user, current_database()");
    print_r($stmt->fetch());
    ?>
    
    ```
    
    <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">  
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">The password, must be provided in the code, we <span style="text-decoration: underline;">DO NOT</span> recommend to use your UWIN username and password here!</span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Alternatively, create a custom username/role for the application. (as explained in the next steps)</span>

##### <span style="text-decoration: underline;">**<span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Create New username/role for your application (Using the web interface):</span>**</span>

- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Login to [https://psql.cs.uwindsor.ca](https://psql.cs.uwindsor.ca) </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Right click on "Login/Group Roles" and Create a new Role  
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/9GAimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/9GAimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">In the new windows, select the username (always start with **app\_**): </span>  
    [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/25simage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/25simage.png)
    
    [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/DCFimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/DCFimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">In the "Privileges" tab, you must enable "Can Login" </span>  
    [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/CQOimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/CQOimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"> In the "Membership" tab, add "app\_users" (this step is to allow this new user to login remotely)  
      
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/Iptimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/Iptimage.png)
    
    <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"> </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Then, we need to grant this new user, access/privileges on your database. right click on your database, and select "Properties":  
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/sfPimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/sfPimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Make sure you are the owner of the database (contact IT if you cannot change it)  
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/imeimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/imeimage.png)
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">In the "Security" Tab, click on the plus (+) sign, to add the new user to the database:  
    </span>[![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/OXlimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/OXlimage.png)
    
    [![image.png](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/scaled-1680-/JxAimage.png)](https://help.cs.uwindsor.ca/uploads/images/gallery/2026-02/JxAimage.png)

##### <span style="text-decoration: underline;">**<span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Create New username/role for your application (Using the command prompt):</span>**</span>

- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">SSH/Login to your VM  
      
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Connect to the database:  
    `psql -h psql.cs.uwindsor.ca -U username-d database`  
      
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Verify you are the owner of the database:  
      
    </span>```sql
    SELECT datname, pg_catalog.pg_get_userbyid(datdba)
    FROM pg_database
    WHERE datname = 'database';  
    
    ```
    
    If you are not the owner, contact CS IT and ask them to change the owner of the database.
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Create a new application role/username:  
    `CREATE ROLE app_testing LOGIN PASSWORD 'password';`  
      
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Grant the new username/role access to app\_users (so you can login with the new username):  
    `GRANT app_users TO app_testing;`  
      
    </span>
- <span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Grant the new username access to your database:  
    `GRANT ALL ON DATABASE "az-testsis" TO app_testing;`  
    </span>

<span style="font-size: 12.0pt; line-height: 107%; font-family: 'Aptos',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Aptos; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-CA; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Now you can use the new username and password to access your database from your web application.</span>