In his first interview since departing as its director in 2008, Sir David told BBC2 programme Who's Watching You that the agency had "very sophisticated targets".
"There are plenty of people who will do all they can to make themselves difficult to find.
"It puts enormous pressure on you. Everybody in the agency is acutely aware that if they don't do their job properly one of the consequences may be another terrorist outrage.
"The thing you worry about most is the attack that you haven't seen coming."
Last year, then Home Secretary Jacqui Smith announced plans for a database to record details of the times and dates of messages and phone calls but said the content of conversations would not be kept.
She said such data was used as "important evidence in 95% of serious crime cases" and in almost all security service operations.
Details of the times, dates, duration and locations of mobile phone calls, numbers called, website visited and addresses e-mailed are already stored by telecoms companies for 12 months under a voluntary agreement.
However, the Liberal Democrats said the government's plans were "incompatible with a free country and a free people".
In February, the Lords constitution committee said electronic surveillance and collection of personal data had become "pervasive" in British society.
Its members said the situation threatened to undermine democracy.
However, Sir David said he was speaking out to help people understand that agencies were there to protect them.
Who's Watching You? will be broadcast Monday 8 June at 9pm on BBC Two and will also be available on BBC iPlayer.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.