Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging - limit disk usage of logs/<username>.sqlite files, remove old records #2822

Closed
zeten30 opened this issue Oct 3, 2018 · 22 comments · Fixed by #4799
Closed

Logging - limit disk usage of logs/<username>.sqlite files, remove old records #2822

zeten30 opened this issue Oct 3, 2018 · 22 comments · Fixed by #4799
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.

Comments

@zeten30
Copy link

zeten30 commented Oct 3, 2018

Feature Description

Currently, there's no way how to control logs/.sqlite file size. It can grow forever. Although this is usually not an issue, it will be good to have a mechanism that will keep file size under control.

Use-cases

  • deployments with many users
  • deployments in public/private clouds (on OpenShift), where persistent storage for applications is usually limited

Ideas

  • keep max N messages in tables, use maxHistory parameter and run regular cleanups (SQL - delete oldest entries)
  • check sqlite vacuum feature and check if this can help to improve disk space usage of sqlite
@xPaw xPaw added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Oct 3, 2018
@richrd
Copy link
Member

richrd commented Oct 3, 2018

I think it would be great to be able to limit the messages by how old they are.
For example maybe I'd like to configure it to delete messages that are over 365 days old.

@zeten30
Copy link
Author

zeten30 commented Oct 12, 2018

Or the other way around. Add function to clear history. Something like clear browsing history in browsers. Clear message history older than: .

@richrd
Copy link
Member

richrd commented Oct 18, 2018

For the record, this type of query could be used for deleting n days of logs (the example deletes messages that are over 1 year old).

delete from messages where time < strftime('%s', datetime('now', '-365 day'))*1000;

@zeten30
Copy link
Author

zeten30 commented Oct 18, 2018

Agree. I already tried that on my OpenShift deployment -> sqlite dies while executing the query... But I assume it's because resource limits.

@mans3n
Copy link

mans3n commented Jul 22, 2020

Any news about this topic? I've deployed thelounge in a docker container and trying to get rid of some messages to reclaim some space back. How can i execute this command "delete from messages where time < strftime('%s', datetime('now', '-365 day'))*1000;" to sqlite? Commandline?

@xPaw
Copy link
Member

xPaw commented Jul 22, 2020

Add function to clear history.

Latest pre-release has the feature to clear history of a channel.

@Stiefmeister
Copy link

Would be great to have an option to set maximum amount of lines per channel to log - currently having troubles with fast growing log-files

@alekna
Copy link

alekna commented Nov 1, 2020

ssages to reclaim some space back. How can i execute this command "delete from messages where time < strftime('%s', datetime('now', '-365 day'))*1000;" to sqlite? Commandline?

Yes, you need to use sqlite command line tool. You may also want to run vacuum command after a delete.

@richrd
Copy link
Member

richrd commented Nov 2, 2020

@alekna Hi, thanks for the follow up!

Just checking if I understand this correctly, this is what I assume:

  1. DELETE somehow marks the rows as deleted, but doesn't actually purge them from the file
  2. vacuum actually alters the file to remove the deleted rows from disk

Did I get that right?

@alekna
Copy link

alekna commented Nov 2, 2020

@richrd, not exactly. Have a look at https://www.sqlite.org/fileformat.html and https://sqlite.org/lang_vacuum.html if you're curious.

@im-n1
Copy link

im-n1 commented Jan 25, 2021

This feature is highly needed. If you connect to one of those torrent channels where messages are constantly piling up 24/7 you reach 1gig of logs withing a week. Running Lounge on Rpi bricks it within a month.

@Erwyn
Copy link

Erwyn commented Feb 15, 2021

I tried the "clear history" of a channel feature, but I'm not sure it's actually cleaning the sqlite database... It's still more than 600Mo on my side although I actually cleared everyone of my channel's histories

@klausenbusk
Copy link

That is expected, you can try to vacuum the database. Please see: https://sqlite.org/lang_vacuum.html

@Erwyn
Copy link

Erwyn commented Feb 15, 2021 via email

@orliesaurus
Copy link

+1 - I got several gigabytes of logs and I would like to get rid of them natively without having to do it manually

@pbek
Copy link

pbek commented Jul 4, 2021

That is expected, you can try to vacuum the database. Please see: https://sqlite.org/lang_vacuum.html

Maybe thelounge could do that periodically for all databases?

@pbek
Copy link

pbek commented Jul 4, 2021

A temporary workaround could be to use logrotate to archive log-databases when they grow too big.

@orliesaurus
Copy link

I am looking for a solution that doesn't require me to stop thelounge to clean up logs

@pinpox
Copy link

pinpox commented Nov 19, 2021

Any updates or working workaronuds for this? I'm running an instance with several users and the .sqlite files are growing to a point where this is becoming a serious problem.

@brunnre8
Copy link
Member

Sure: https://github.com/thelounge/thelounge/wiki/Purging-logs-older-than-X-days

is a workaround that does just that.

@azeemba
Copy link

azeemba commented May 17, 2023

Is there interest in this feature if someone else provides a solution. I can think of two ways to implement this:

  • On startup, the server uses a setInterval to repeatedly run the delete command. This is nice because each delete operation will be relatively cheap.
  • We use sql triggers, so on each update, sqlite itself will delete old records. This one is a little hard to configure for the user. We probably would need a new commandline "command" to insert/update this trigger.

@brunnre8
Copy link
Member

brunnre8 commented May 17, 2023

Triggers are the wrong tool for the job in this case would be my guess, especially as you want to make this configurable and somewhat dynamic.

I'd also like to have the ability to only delete status messages, while keeping the important stuff like privmsgs around.
In other words some sort of timer on the JS side of things.
We do need to be a bit careful not to hang the rest of the system though by running a huge delete.

My plan is to limit this to N rows per iteration

azeemba added a commit to azeemba/thelounge that referenced this issue May 17, 2023
Adds a new config `dbHistoryDays` which defaults to undefined.

At start up, each database handler reads the config. If the value is
set, then a reoccuring task is scheduled to clean up old events.
Events older than `dbHistoryDays` are targeted but only a few thousand
events are cleaned up per iteration to avoid freezing the server.

Adds unit tests to validate the cleanup logic as well.

Fixes thelounge#2822
azeemba added a commit to azeemba/thelounge that referenced this issue May 17, 2023
Adds a new config `dbHistoryDays` which defaults to undefined.

At start up, each database handler reads the config. If the value is
set, then a reoccuring task is scheduled to clean up old events.
Events older than `dbHistoryDays` are targeted but only a few thousand
events are cleaned up per iteration to avoid freezing the server.

Adds unit tests to validate the cleanup logic as well.

Fixes thelounge#2822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet