My boss (and, actually, his boss too, which is the company general director) are generally quite good.
But it happens (seldom, but frequently enough) that they start to fiddle with the details: day to day chores that they should not do.

Examples are: DB queries to extract data, scripts to parse excel files, even re-installing software on their workstation, and the like. The problem is that there are people in the company that could do it much better, much faster. Often, we already have programs or libraries to do what they are trying to do in a more efficient way, or we can create them. 

This is not a very urgent problem, per-se (even if they make mistakes - not being their primary job, they may miss or forget important points), but that eats up their time, and that's the real issue: he does have very little time to "manage" (listen to his subordinates, make decisions, planning...)

How can I convince them to stop "doing", without being rude, annoying, or worse?
(he is still my boss, after all :) )
I know that for some people giving up the "getting my hands dirty" is difficult, but I really feel this is becoming a problem and I want to try to improve the situation.

---

EDIT:
Just to clarify: him doing things is both a problem by itself (but that is specific to my case, so I won't bother you with this part), and above all, a problem because it hinders his ability to manage others. Getting an answer by email is very difficult, meet him 1-1 to discuss projects, software to buy, planning, requires days or weeks, etc.

I am a team leader myself, and I strongly believe in leading by example, which means also working with your colleagues, but my first obligation with my people is to lead them, otherwise I may end up blocking 10 developers because they are waiting for an answer from me.
['https://workplace.stackexchange.com/questions/42335', 'https://workplace.stackexchange.com', 'https://workplace.stackexchange.com/users/7408/']
Build trust. Gently explain that other are dedicated to the type of problems that they are trying to solve and offer to be a proxy (i.e. tell them that you want to help them save time and point them in the right direction whenever they have a problem like the ones above). Also gently explain that their time is super valuable and if they spend it doing things that low level drones can and are already doing you (i.e. the company) are losing money.

At the end of the day remember who is signing your paycheck.
It isn't your place to do anything about this. Your manager will manage his time according to his boss and himself. If it's not affecting you then you shouldn't say anything. 

If it is affecting you, for example he hasn't made a decision on which way a project should go, politely ask him for a decision and state that your work is being held up by the lack of a decision. If his queries are impacting on your work then you should point out to him how it is impacting and the right tools / libraries to use to avoid impacting on you in the future, focus on the way for him to stop impacting your work and you might just find he realises he's a bit out of touch and stops on his own. However if he wants to run those queries rather than delegate then that's his right as the Manager.

If it's such a big problem then find another job (and mention why you're leaving in your exit interview), or find a way to become a manager on the same level as him (if that's possible) and then you can talk to him as a colleague rather than your boss.