Share via

How to create a scheduled job to restart an Azure PostgreSQL Flex Service once every 2 weeks?

Farshadfar, Tony 0 Reputation points
2026-01-22T18:58:04.5833333+00:00

Hi. The Restart service icon of PostrgreSQL Flex database service is available but I need to create a job to restart this service once every 2 weeks at a specific day and time. How can I do that?

Azure Database for PostgreSQL

1 answer

Sort by: Most helpful
  1. Anonymous
    2026-01-22T20:04:31.39+00:00

    Hi @Farshadfar, Tony

    This response was AI-generated. If the issue is not resolved, please follow up in the comments so we can assist further.

    It sounds like you want to set up a scheduled job to automatically restart your Azure PostgreSQL Flexible Server every two weeks. Here’s a way to do it using Azure Automation Tasks:

    Create an Azure Automation Account:

    • Go to the Azure portal and create a new Automation Account.

    Create a Runbook:

      - Inside your Automation Account, go to the "Runbooks" section and create a new runbook.
      
         - Choose "PowerShell" as the type.
         
            - Use the following script to restart your PostgreSQL server:
            
            ```powershell
            $resourceGroupName = "<YourResourceGroup>"
    

    $serverName = "<YourServerName>" Stop-AzPostgreSqlFlexibleServer -ResourceGroupName $resourceGroupName -Name $serverName Start-AzPostgreSqlFlexibleServer -ResourceGroupName $resourceGroupName -Name $serverName ```

               - Make sure to replace `<YourResourceGroup>` and `<YourServerName>` with your actual resource group name and server name.
               
               **Schedule the Runbook**:
               
                  - After saving and publishing the runbook, you can schedule it.
                  
                     - Click on "Schedules" and then "Add a schedule".
                     
                        - Set it to trigger every two weeks on your preferred day and time.
                        
                        **Test Your Runbook**:
                        
                           - Ensure to test your runbook manually to verify that it restarts the server correctly.
                           
                           **Monitoring and Alerts**:
                           
                              - Set up alert notifications in case the automation fails.
                              
    

    This setup will automate the start/stop process of your PostgreSQL server according to your desired schedule without the need for manual intervention.

    Additional Helpful References:

    Hope this helps! If you have more questions or need further clarification, feel free to ask!

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.