FAQ | This is a LIVE service | Changelog

Skip to content
  • Dr Catherine Pitt's avatar
    Make database connections short-lived · e40c1a55
    Dr Catherine Pitt authored
    The code used to open a database connection for each thread and leave
    them open for as long as the scheduler ran. This worked reasonably well
    until we moved to PostgreSQL 13 on Focal, although the scheduler would
    fail if the database was restarted because there was no logic to
    reconnect after a connection dropped.
    
    On Focal/PG13 the connection for the 'cron' thread steadily consumes
    memory until it has exhausted everything in the machine. This appears to
    be a Postgres change rather than a Perl DBI change: the problem can be
    reproduced by sitting in psql and running 'select * from backup_queue'
    repeatedly. Once or twice a minute an instance of this query will cause
    the connection to consume another MB of RAM which is not released until
    the database connection is closed. The cron thread runs that query every
    two seconds. My guess is it's something peculiar about the view that
    query selects from - the time interval thing is interesting.
    This needs more investigation.
    
    But in the meantime I'd like to have backup servers that don't endlessly
    gobble RAM, so this change makes the threads connect to the database
    only when they need to, and closes the connection afterwards. This
    should also make things work better over database restarts but that's
    not been carefully tested.
    e40c1a55