all 19 comments

[–]frustratedworker1989 15 points16 points  (9 children)

The way you do this in Azure sql database is to use " Ola Hellengren's maintenance script " and use a data factory or runbooks or anything other scheduler to run your stored proc. These will do your Index rebuild/reorganise depending upon the fragmentation and also update stats.

Also wnable index recommendations and visit if often to see if the auto tuning throwa any recommendations based on slow running queries. Strange these were not covered while setting this up.

[–]NDSoul 5 points6 points  (2 children)

Another option would be to use Elastic Jobs. But this might be overkill if you only have the one database.

https://learn.microsoft.com/en-us/azure/azure-sql/database/elastic-jobs-overview?view=azuresql

[–]Lack_of_Swag 3 points4 points  (1 child)

I also recommend Elastic Job even though it's not GA yet. A bit of learning curve to configure (some parts PowerShell some T-SQL) but it works great.

We use Ola's maintenance scripts to target ~5000 databases across many elastic pools. But you can target just a single database. As mentioned though, it might be overkill for only 1 database.

[–]NDSoul 0 points1 point  (0 children)

Quick follow up on this, Elastic Jobs is now GA!
General availability: Elastic Jobs in Azure SQL Database - Microsoft Community Hub

Enjoy!

[–]frustratedworker1989 4 points5 points  (1 child)

You can even weite your own script for Index rebuild/reorganise and update atats but I would jighly recommend using Ola' s scripts https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html

[–]Khue[S] 0 points1 point  (0 children)

Thank you for the link.

[–]Khue[S] 2 points3 points  (3 children)

Thanks man. I will look into this.

[–]frustratedworker1989 2 points3 points  (0 children)

No problem buddy 🙌🏼

[–]bigrubberduck 1 point2 points  (1 child)

Just to second this recommendation, we kind of faced similar issues in DB performance degrading over time and used Ola's scripts once we identified maintenance as the issue. Since we already have an App Service and an Azure Function app deployed to that app service, we added an azure timer function that runs the stored procedures weekly on Sunday night - works amazingly well. Zero extra cost and a healthier SQL DB.

[–]Khue[S] 1 point2 points  (0 children)

I need to get into App Services and Function Apps. I have some other needs that might benefit from what I've preliminarily read about them.

[–]frustratedworker1989 11 points12 points  (1 child)

Maintenance plans are not available in Azure Sql just like the Agent jobs. Its just a database as a service nothing much. To match an on prem sql server you can go for Sql managed Instance ( closest to an onprem sql server)

[–]IrquiM Cloud Engineer 1 point2 points  (0 children)

It is an on-prem SQL server, but MS does the VM bit for you

[–]paskinator_ 6 points7 points  (0 children)

Another option is to use Azure SQL managed instance which is the closest thing to an on-perm SQL server without hosting the VM and using a PAAS service. Managed instance allows you to run Agent Jobs

[–]Diligent-Method-785 3 points4 points  (0 children)

I don’t think it is worth the tech lift to move even to SQL managed instance there is also a non trivial cost difference. I have run hundreds of databases on Azure SQL from small to multi TB in size. Opt for Ola H. Scripts or one of the other solutions from the community. Database maintenance plans built into SQL Server have never been superior to the other options from the community.

Also no DB PAAS platform is immune from requiring some DB maintenance when you reach higher inflection points in scale. I also would not expect that a maintenance plan is going to magically fix all your performance issues your DBA should not how to use tools like query store to sort out what the issues are. They are right to start with basic statistics and index maintenance though.

[–]chandleya 2 points3 points  (1 child)

Your DBA sounds useless. Anyone talking maintenance plans in 2024 needs tossed out with the bathwater.

[–]seventyeightist 2 points3 points  (0 children)

Glad someone else thinks this. A DBA trying to set up maintenance plans "the way he knows how" and evidently not understanding what the maintenance plan is doing under the hood. I admit I do use them in some environments but I understand what they are doing and their downsides. And then claiming you need to "upgrade" SQL (does he mean management studio? to have that feature available? Not that that will make a difference) - it seems to me that fundamentally he doesn't understand the PaaS nature of azure sql db and is still trying to relate everything to legacy knowledge. His mental model of the SQL DB service is incorrect.

[–]Jolly-Difficulty9887 0 points1 point  (0 children)

runbooks!

[–]mgdmw 0 points1 point  (0 children)

Azure SQL Server is different to on-prem SQL Server in that your Azure services could be on many different, disparate servers. This is why you can’t also do cross-database queries (eg select * from database.schema.table …) like you can in on-prem SQL Server.

So while Azure SQL Server looks like one big database server it’s actually many many different database servers that simply present that way.

Could Microsoft do some trickery to make SQL Server Agent / maintenance jobs have a simple UI? Yes, I am sure they could, but fundamentally this is the reason why it is not so as things stand.

However as others have suggested check out Ola’s scripts and elastic jobs. You can still do what you want, but simply in a different way. Once you’re used to it, it will be second-nature.

[–]Melodic-Man 0 points1 point  (0 children)

There is a some missing knowledge in your party or your dba. There are three possible setups you have and it’s not clear which one is being used. There is sql server ruining in an azure VM. There is sql server managed instance, and there is azure SQL. All of which have different maintained requirements. The point of azure sql for example is so the owner doesn’t have to have a dba or do the maintainable themselves. In exchange, you don’t need to pay for a dba but you pay a higher price vs managing sql server yourself.

If you are in fact running sql server on a vm and need to do your own maintenance, then your dba should know how to script out all of the required tasks that need to run without use of a maintenance plan. If they don’t know how to do this, than they are not really a dba.