Hi,
For one of our azure Db's which was around 400 gb is now only 50 gb... My question is should i drink the database from 400 to 150 gb
(1) Do you speak about the database size (the size of the files) or the size of the data ?!?
When you are using sp_helpfile
the value of the [size] is NOT the size of the data but the size of the database file, which less help you know what is the size which you should use.
You can get the size of the files and the space size which is used for the ROWS in the file, you can use sys.database_files
and the function FILEPROPERTY
.
SELECT name,
size/128.0 FileSizeInMB,
SpaceUsed = FILEPROPERTY(name, 'SpaceUsed')/128.0
FROM sys.database_files;
GO
Note: You can also get the information using sp_spaceused or using sys.resource_stats
(2) Shrinking the database is NOT the main parameter to reduce the cost directly, since you pay according to the type of service tier, amount of DTUs, and the Database max size - less according to the actual size of the data or the data files (the storage size).
(3) Shrinking the transaction log file is HIGHLY not recommended in most cases.
Using On-premises database it is usually a bad idea to shrink the log file since it can impact performance, but using Azure SQL Database it even make less sense in most cases, since Azure SQL Database automatically shrinks transaction log file to avoid excessive space usage.
If you still decide to shrink the log file, then you should probably use the parameter TRUNCATEONLY to releases the free space at the file's end to the operating system but without perform any page movement inside the file !
(4) In order to to reduce the cost you will need to change the Compute + storage
of the database, which mean (as I mentioned above) to change the service tier, the DTUs, the Max size of the database, number of vCores or memory, and so on (depending on the type of pricing tier you use).
In some cases in order to change the parameters of the Compute + storage
you will have to first reduce the size of the database - in this case and only in this case it will probably make sense to shrink the database file size to fit the new configuration you want to use.