more correct way optimizing sqlite database

This commit is contained in:
Your Name 2025-01-04 02:36:06 +03:00
parent e762f1e7f6
commit 8c81fe5c5e

13
ubot.py
View file

@ -115,12 +115,19 @@ async def main():
)''')
conn.commit()
logger.debug('sqlite3 database initialized')
logger.debug('optimizing database...')
c.execute('PRAGMA optimize')
c.execute('PRAGMA optimize=0x10002')
c.execute('PRAGMA journal_mode = WAL')
c.execute('PRAGMA synchronous = normal')
logger.debug('Vacuuming database...')
c.execute('VACUUM')
logger.debug('optimized')
logger.debug('Vacuum done')
async def optimize_sqlite_db():
while True:
c.execute('PRAGMA optimize')
logger.debug('database optimized')
await asyncio.sleep(12 * 60 * 60)
asyncio.ensure_future(optimize_sqlite_db())
####################################################################