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/']
This depends a lot on the managers/directors in questions. 

Are you positive that they actually take longer to perform XX task?

I have had directors & managers from both sides of the competence scale in regards to being able to perform the work of the people under them. You will find that in some cases while they may appear 'slower' than you or your peers they are checking up on the quality of other work, if they are on the lower end of the competence scale they may be simply doing it as exercises to familiarize themselves with day to day operations or trying to figure out where bottlenecks are. ( remember at Mcdonalds a manager is someone who knows every single job in the store inside and out. ) 

Now if its a director that is doing this you have to be aware that "its their company", you just happen to be there because it suits them to have you around. They were there long before you started and will be there long after you leave. and more likely than not when the company first started it was them that did the lions share of the work, and as time progressed more and more staff got added because their workload increased.
EDIT: this answer as written when OP's original version implied they were an individual contributor, before the crucial detail that they are a manager managing a team of 10, which completely changes the question.
Moreover this makes the boss a level-2 manager, which is a different situation.

---

I'd bloody rejoice.

A manager who wants to keep their hand in the game? Consider yourself lucky. This is a blessing in disguise.

I don't see that this a problem, certainly no more than a manager who spends too much time in meetings, presentations, reviews, conferences, executive lunches, politicking, MBA classes, playing golf, drinking, betting on the horses or other sanctioned modes of slacking.

Even if we conclude it's a problem, it's at most a small problem and it's certainly not ***your*** problem.
One good side-effect is that they will still be competent at hiring good technical people, which is something that PowerPoint warriors lose (or delegate to the HR dept, or stop caring, and the organizational rot sets in).

(**What's their motivation?** Need to present credible data to higher-ups? Want to stay technical and deny the cloak of management being thrust upon them? Technically insecure? Impostor syndrome? Afraid of being laid off, or that their role has become obsolete? Want to understand what you or their subordinates are doing better? Want to know how to hire or manage you better? or hire your replacement if you leave? They may have several of these motivations, and don't expect them to tell you.)
Most of those are fine, and even the ones that aren't can work to your advantage.

***You can (privately) show them you that you can do their work faster*** (or some automated script, or query tool, or GUI).
Implement it yourself. If they're a chart person, give them charts. If they're a KPI person, give them numbers. If they like doing it interactively, install a query tool and write a wiki of frequently-used queries. If they want to tie things to the build/SCM process, implement that.
Consider this a hidden opportunity to both do something productive and "get recognition" at multiple levels of the hierarchy.
This is how useful internal tools generally happen. Show them a functional prototype then see if they approve spending further time on it.
a

> 
> I know that for some people giving up the "getting my hands dirty" is difficult
> 
> 
> 

Honestly that's a badge of being a good engineer, if somewhat unrealistic about their productivity. (Read about *"Engineer-not-Manager"*)

> 
> How can I convince them to stop "doing", without being rude, annoying, or worse? 
> 
> 
> 

**It's not your %#@& job to.** If you must, be very oblique. Just offer them a higher-productivity alternative, and privately walk them through it, only if they show interest. Then if they still insist on doing it themselves, then let it be.
They may have some unresolved identity or competence crisis; if so, don't force it.

> 
> but I really feel this is becoming a problem and I want to try to improve the situation.
> 
> 
> 

But it's not, based on anything you've said! Anyway it's not your perception that matters as to whether it's a problem. Don't let your ego be threatened, don't feel insecure.

***tl;dr: Rejoice, let it go, use it to your career advantage, keep them happy while nudging them towards a mutually useful point, boost their managerial self-esteem***