Solved pkg upgrade -- pkg: Cannot get an advisory lock on a database, it is locked by another process

I checked what was running and saw this:
Code:
# ps -auwx | grep 'USER\|pkg' | grep -v grep
USER   PID %CPU %MEM    VSZ    RSS TT  STAT STARTED    TIME COMMAND
root 55747  0.0  0.0  11804   2612  -  IJ   07:50   0:00.00 /bin/sh - /usr/local/etc/periodic/security/460.pkg-checksum
root 58051  0.0  0.0  11804   2608  -  IJ   07:50   0:00.00 /bin/sh - /usr/local/etc/periodic/security/460.pkg-checksum
root 58319  0.0  0.0  20192   9580  -  IJ   07:50   0:00.01 /usr/local/sbin/pkg check -qsa
root 59596  0.0  0.6 201792 185968  -  DJ   07:50   0:23.05 /usr/local/sbin/pkg check -qsa

The state says Idle ( Jail). I infer from the commands that these are periodic tasks. Why might they still be running hours later? Do I just kill them?
 
They might all be stuck for the same reason (the lock). Kill the pkg-check(8) processes. That should finish those scripts.

If you have many jails on a single machine it'll be a good idea to spread the time periodic(8) runs at a bit. So they don't all start running at the same time, bogging down the machine with a high I/O load.
 
As it turns out these completed without intervention. I will look at periodic's scheduling.
 
I will look at periodic's scheduling.
It's in /etc/crontab:
Code:
# Perform daily/weekly/monthly maintenance.
1       3       *       *       *       root    periodic daily
15      4       *       *       6       root    periodic weekly
30      5       1       *       *       root    periodic monthly
Just shift the time-of-day around a bit. None of these scripts actually have to run at a specific time, so you can move them around a bit. If you have 30 jails for example you don't want all of them starting their daily job at exactly 3:01, all at the same time.
 
I am trialing this:
Code:
# Perform daily/weekly/monthly maintenance.
# start times staggered for jail
1   3 * * * root  sleep $(jot -r 1 30 180) ; periodic daily
15  4 * * 6 root  sleep $(jot -r 1 30 180) ; periodic weekly
30  5 1 * * root  sleep $(jot -r 1 30 180) ; periodic monthly
#
 
Back
Top