15
devTea
6y

Is there automation tool for postgres or mysql to fire a query? I got a db that will reset the row column value after 1 month of the created date

Edit: I know this is not SO

Not clearing the rows, just resetting the value of some rows if the criteria is met

Comments
  • 4
    Use ansible
  • 2
    @m0nk noted, thanks for the answer
  • 3
    A trigger on column reset will help?
  • 4
    @asgs does it trigger automatically? Can I put a schedule with it or something?

    Edit: nvm my friend tried using cron @jespersh
  • 1
    @devTea I'm not sure about scheduling (think it is not possible), but yes it is automatic. It happens automatically based on some condition you specify.

    Ref - https://dev.mysql.com/doc/refman/...
  • 3
    Usually such things are done by a layer managing the database. Either a manual cron on the server itself, or a higher level managing tool like ansible, or the backend framework like Laravel (kernel job scheduling) or Django (django-cron), or on Amazon you'd set up a scheduled lambda function, etc.

    So it kind of depends what kind of systems the DB is interacting with :)
  • 5
    Write a script to make the update. Then add it to the applicable user's crontab. The following line will run it at 2:15AM on the 10th of every month.

    15 2 10 * * /home/shirtpants/bin/fixdb
  • 3
    Not sure about Postres, but MySQL has built-in scheduler. There is really no need for cron or even some external server for simple thing like that. If the server provider allows it ofc.
  • 1
  • 1
  • 1
    @bahua @hitzoR Depends on who/what manages the DB server.

    If you have a backend web framework with a scheduler, it might be a better place -- easier to find, stored in git, transparent to other devs. Seemingly random changes in your database might be puzzling to other maintainers, unless they know about "show events from database".
  • 1
    @bittersweet and more importantly access should already be securely arranged
Add Comment