Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Task 01 - Configure the migrated database for connectivity from the web application connection

Description

In this task, you will connect to the migrated database in the Azure Database for PostgreSQL Flexible Server. You will configure the database to allow connectivity from the web application running on the VM to connect to the migrated PostgreSQL database.

Success Criteria

  • The database is configured for the web application to connect to it.

Solution

Expand this section to view the solution
  1. In the Azure Portal, navigate to the Resource Group that you created for this lab, then select the Azure Database for PostgreSQL Flexible Server you just created.

  2. Go to Networking in the left hand pane or search for Networking in search

    Networking is hihghlighted.

  3. Click on the Private Endpoin link

    Click on the private endpoint link

  4. Click on DNS configuration or use search to find it

    Click on the DNS configuration option

  5. This will bring up the IP address that the private endpoint for PostgreSQL Flexible Server is using. You will use this IP address to connect via the bastion session.

    Obtaining the IP address for connecting to the Private Endpoint

  6. In the Azure Portal, navigate to the Resource Group that you created for this lab, then select the On-premises APP VM named similar to terrafirm-onprem-app-vm.

    The Resource group with on-premises workload VM highlighted.

  7. On the Virtual Machine blade, either use the Search function in the left hand menu or click on Bastion. We will use a bastion host as the method to connect to our VMs as this is a more secure method.

    The Virtual machine blade searching for "Bastion".

    The Virtual machine blade with Bastion selected.

  8. Within the Bastion page, enter the following:
    1. Authentication Type VM Password
    2. Username demouser
    3. VM Password <the secure password you created when you created the VMs in Task01>

    The Bastion Connection page.

    Note: You may need to allow popups if they are blocked in your browser.

  9. When connectioned to the VM via the Bastion host you will get a screen like this:

    Copnnection via Bastion host.

  10. Once connected via Bastion, run the following command to install the git utility on the server by using the clipboard within the session:

    Clipboard within the Bastion session.

  11. Click the arrows which will expand the window

    Clipboard within the Bastion session.

  12. Within the clipboard windows enter the following (replacing 10.2.0.4 with the IP address of your private endpoint)

     psql -h 10.2.0.4 -p 5432 -U pgadmin northwind
        
    

    Enter the password for the PGAdmin login you created in the previous task.

    Connecting to the Flexible Server within the Bastion session.

  13. You need to bring across the user and permissions for the web application to connect to the database. Which requires running a setup script in the migrated database. Run the script below in the bastion clipboard:

     CREATE USER demouser WITH PASSWORD 'demopass123';
     GRANT SELECT ON ALL TABLES IN SCHEMA public TO demouser;
     GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO demouser;
    

    Running the SQL script when connected to the database using Cloud Shell

  14. You can quit out of the psql client session by typing the following:

     \q
    

At this point, things are ready for you to configure the web application to use the migrated database.