Search code examples
pythondatabaseazureazure-functionsazureportal

Azure-Database keeps running and doesn't close


I've set up my first database on the free sql offer by miccrosoft azure. But eventhough the connection should automatically close after 1 hour. the free 100'000 core seconds keep running down. so after a couple of days it's used up.

I have a serverless function that accesses the database once a day for a couple of seconds, but this would not add up to the 100'000 core seconds as quickly as it does.

There are also no open connections that I can find, and the azure function also closes the connection immediately again.

SELECT
c.session_id, c.net_transport, c.encrypt_option,
s.status,
c.auth_scheme, s.host_name, s.program_name,
s.client_interface_name, s.login_name, s.nt_domain,
s.nt_user_name, s.original_login_name, c.connect_time,
s.login_time
FROM sys.dm_exec_connections AS c
JOIN sys.dm_exec_sessions AS s
    ON c.session_id = s.session_id
--WHERE c.session_id = @@SPID;
--WHERE status = 'sleeping'
ORDER BY c.connect_time ASC

Is this the way the free account is set up or am I doing something wrong here?


Solution

  • Thank you @CSharpRocks for your comments.

    Your Free SQL Database is taking up the 100,000 vCore seconds of compute, Cause it is running continously. Even when your function query is not executed to access the database. The Database compute will keep on running even if there is no query execution inside it. As Azure SQL Server Database STOP feature is not yet available. Its not possible to Stop your Database after it is accessed and queried by your Function app.

    As a workaround, You have 2 options:-

    Option 1:-(Cost saving, Not Helpful in your scenario)

    While Creating the Database if you select - Auto-pause the database until next month > This option will automatically pause your database and make it inaccessible after its Free Limit is reached and It will be accessible again for next month the limit is renewed again.

    enter image description here

    But there's a catch here, You cannot Auto-pause the database after 1 hour of its inactivity after enabling this method. As that option is greyed out. And Not possible According to the FAQ here.

    enter image description here

    Option 2:- (Helpful but costly)

    You can select Continue using database for additional charges This will continue your database to be accessible even after its limitations is reached, But you need to pay the extra amount after the end of the month.

    But The option to enable auto-pause is available here, So you can set the auto-pause your Database to 1 hour, So after 1 hour your database will be paused automatically saving your VCores. Along with this Keep on monitoring your VCores limit in the metrics by referring this MS Document. And then stop using your database after the limitations is reached, this way you won't be charged.

    enter image description here

    enter image description here

    Monitor-

    enter image description here

    I have created a Feature request to Enable Stop Feature in Azure SQL Database. Refer here.

    Reference:-

    How to stop Azure SQL Database - Microsoft Q&A

    Serverless compute tier - Azure SQL Database | Microsoft Learn