web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Is it OK to delete rows from Sysdatabaselog directly in SQL Server

(0) ShareShare
ReportReport
Posted on by

Just wanting to confirm if I can use a SQL job to delete data from Sysdatabaselog periodically.  I know the official way would be to set up a batch job, but just checking to see if it's OK to do it ad hoc with SQL.

 

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    There are no delete actions, delete() isn't overridden and nobody will log it. But SysDatabaseLogCleanup (the class that you should actually use) includes some logic regarding electronic signature; SQL query would also bypass AOS authorization and AX cache won't be aware of the deletion.

    My recommendation is sticking to the SysDatabaseLogCleanup class. It's there for exactly this purpose and you can run it on ad-hoc basis as well.

  • Ebbe Høeg Jensen Profile Picture
    150 on at

    I checked table SIGSignatureLog and table SysSignatureSetup. They were empty. As the logging has been disabled for the tables I want to delete records for in SysDatabaseLog table, I see no problem deleting the SysDatabaselog records directly in SQL Server. We got millions of these records.

  • Aparisi82 Profile Picture
    2,188 on at

    Hello, 

    did you eventually run the deletion from sql using delete _from or using the clean up functionality?

    I tested the same in a TEST environment and it took almost 2 hours for 20 million records.

    The issue is that it will lock  the table  and potentially stop any AX process that needs to delete,update,insert on the sysdatabaselog.

    How did you do it?  DId you plan a maintenance window?

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    delete_from is not an optimal solution to be honest, unless you want to remove a subset of records only. If you want to remove all entries, and you do not have connected records like the above mentioned signatures, why not just truncate the table? It would be instantaneous.

    docs.microsoft.com/.../truncate-table-transact-sql

    If you want to keep entries from the past year but nothing before, I would recommend a sliding window partitioning, then truncate old partition data.

  • Aparisi82 Profile Picture
    2,188 on at

    Thanks for the quick reply.

    Actually I need to delete only a certain amount of records ( assigned to a specific user).

    Is there another way to delete these records quickly>

  • Vilmos Kintera Profile Picture
    46,149 on at

    See above, by setting up SQL partitions for date range/user (or however you want to split it).

  • Aparisi82 Profile Picture
    2,188 on at

    Interesting.. I will play with this. Thanks and regards

  • Suggested answer
    Ebbe Høeg Jensen Profile Picture
    150 on at

    I'm sorry but I can't remember what I did exactly. But I believe I did some batching to prevent locking the tables. Look at this stackoverflow.com/.../will-delete-sql-locks-the-table-which-prevents-new-data-insert-into-sql-server-2

    And it was carried through outside working hours.

    Best regards, Ebbe

  • Ebbe Høeg Jensen Profile Picture
    150 on at

    Now I've found the script I used for deleting the 125 mio. records. Sample:

    DECLARE @Deleted_Rows INT;
    SET @Deleted_Rows = 1;
    WHILE (@Deleted_Rows > 0)
    BEGIN
        BEGIN TRANSACTION
        -- Delete some small number of rows at a time
        DELETE TOP (10000)  SYSDATABASELOG 
        WHERE TABLE_ = 110188 -- table OioublReceivedDocs
        SET @Deleted_Rows = @@ROWCOUNT;
        COMMIT TRANSACTION
        CHECKPOINT -- for simple recovery model
    END
     

    Best regards, Ebbe

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans