15

Lately I've been getting a mail from the server every day,

Subject

Cron <root@host> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

Body

/etc/cron.daily/apt:
DB Update failed, database locked

If i just run the /etc/cron.daily/apt part it just stays there with no output, i tried running tail -f /var/log/apt/*.log /var/log/syslog & and then running /etc/cron.daily/apt but no output either

Which database is locked and by what, i'm able to do apt-get update successfully.

Did some updates yesterday and had to restart, so the microsoft fix wont work here (this has been going on since before the updates so not related)

What else can I look into?

This is a amazon instance incase it matters

3 Answers 3

8

What really properly fixed this problem for me was uninstalling apt-xapian-index package. None of the other suggested fixes did anything in my situation.

You may read more details from my little blog post.

1
  • 2
    Thanks, I had the same experience—changing the timeout as in other answers didn't change anything except how long it took to give up. I'd like to quote a bit from your blog post (the reason I clicked through): "it seems that Synaptic, the Ubuntu graphical package manager probably uses Xapian. On my Ubuntu server I don’t use Synaptic so I don’t care if the Apt Xapian index is not updated. The usual apt-tools should still work perfectly." As your post says, YMMV. Works for me, not using Synaptic.
    – Vaz
    Feb 18, 2016 at 22:03
4

Long story short, change RandomSleep=1800 to something more pleasent. I chose RandomSleep=5

ref: https://lists.ubuntu.com/archives/ubuntu-users/2009-February/175474.html & http://ubuntuforums.org/showthread.php?t=1071892#post_6747612

2
  • This did nothing to fix my problem, which is the same as the OP. If you look at the code, the RandomSleep time is used as a limit for the actual time, which is chosen nominally randomly. Hmm. Looking at the code, there seems to be a bug. RandomSleep is possibly reset to either 1 or 0, by the apt-config call. (If it's even set, mine wasn't.) The apt call either stomps the variable, or does nothing to it. It doesn't actually act on it's value in a useful way.
    – Hack Saw
    Jul 4, 2013 at 12:37
  • It seemed to fix my problems for a few days which I think was coincidence more than anything else. Jul 4, 2013 at 21:38
1

This happens when you have multiple APT/DPKG instances running at the same time. If you run something that blocks apt-get like aptitude in GUI mode, and type sudo /etc/cron.daily/apt eventually it will fail with the same message.

2
  • Thanks for the insight. Doesn't apply to those of us running Ubuntu servers without GUI but it's sure to be useful to someone.
    – Vaz
    Feb 18, 2016 at 22:05
  • 2
    @Vaz actually, it does, another example would be apt-cron or unattended-upgrades
    – Braiam
    Feb 18, 2016 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .