Git Product home page Git Product logo

Comments (6)

jvehent avatar jvehent commented on July 24, 2024

Some numbers:

command records

mig=> select count(*) from commands;
20417300

agent records

mig=> select count(*) from agents;
21086710

Agent records that don't have any commands:

mig=> SELECT COUNT(*) from (SELECT id FROM agents WHERE agents.heartbeattime < NOW() - INTERVAL '30 days' EXCEPT SELECT agentid FROM commands) as q;
15033316

About 71% of agents never get targeted and can be deleted. I'm calling this a win :)

@ameihm0912 , @gdestuynder : any thoughts?

from mig.

gdestuynder avatar gdestuynder commented on July 24, 2024

Best would probably be to make this configurable to accommodate different people's retention needs (including "0" for forever) - but yes i noticed the db was getting big before.
I also wonder how much space it would take if exported + compressed (for those who need long term history)

from mig.

jvehent avatar jvehent commented on July 24, 2024

Running this manually right now.

DELETE FROM agents
WHERE id IN (SELECT id FROM agents
             WHERE agents.heartbeattime < NOW() - INTERVAL '30 days'
             EXCEPT SELECT agentid FROM commands);

from mig.

jvehent avatar jvehent commented on July 24, 2024

Query to delete commands after 1 year:

SELECT COUNT(*) FROM commands WHERE finishtime < NOW() - INTERVAL '365 days';
 1076359

Query to delete agentdestroy commands after 90 days:

SELECT COUNT(*) FROM commands
WHERE actionid IN (SELECT id FROM actions
            WHERE operations->0->>'module'='agentdestroy'
            AND expireafter < NOW() - INTERVAL '90 days');
 74699

from mig.

jvehent avatar jvehent commented on July 24, 2024

Running now:

DELETE FROM commands
WHERE finishtime < NOW() - INTERVAL '365 days';

DELETE FROM commands
WHERE actionid IN (SELECT id FROM actions
                   WHERE operations->0->>'module'='agentdestroy'
                   AND expireafter < NOW() - INTERVAL '90 days');

DELETE FROM agents
WHERE id IN (SELECT id FROM agents
             WHERE agents.heartbeattime < NOW() - INTERVAL '30 days'
             EXCEPT SELECT agentid FROM commands);

VACUUM ANALYZE;

from mig.

jvehent avatar jvehent commented on July 24, 2024

The queries above deleted millions of records, but no space was reclaimed. This may be an AWS RDS quirk, or a Posgres one, I'm not sure yet.

from mig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.