Maryland, historically one of the Democratic Party's most reliable states, appears up for grabs on the eve of a second and final presidential debate that Democrats and Republicans alike say could be the deciding factor in how the state votes.

While polls show the president well ahead, politicians of both parties, aware of the state's heavily Democratic registration, expect his lead to shrink.

A new poll published today -- the first in Maryland since President Reagan's somewhat faltering performance in his initial debate with Democratic candidate Walter F. Mondale -- shows that the Democratic challenger has failed to gain any ground on the president recently.

The survey, taken by the Baltimore News-American and WBAL-TV, gives Reagan a 12-point lead over Mondale, 54 percent to 42 percent, with just 4 percent of the polled undecided. The poll tested the sentiments of 820 probable voters during the week immediately following the Oct. 8 debate.

The survey contradicts the findings of most national polls taken in the wake of the debate during which Mondale was found to be chipping away at Reagan's lead as a result of his strong performance. But it is consistent with earlier polls taken by The Baltimore Sun and the University of Maryland Survey Research Center that showed Reagan ahead by nine and 13 points.

Democratic and Republican party officials reacted predictably to the poll.

GOP chairman Allan C. Levey said the poll "shows everything we've been doing is a success. This late in the campaign, 12 points is pretty good."

Democratic State Party chairman Howard Thomas said, "The polls have really been all over the lot . . . This doesn't reflect what we've been getting from our workers."

The poll also contradicts the intuitive soundings of other top Maryland Democrats who, after two weeks of barnstorming the state for the Mondale-Ferraro ticket, profess confidence that the state is swinging back toward the Democratic column.

After traveling to almost every part of Maryland in recent days, Democratic politicians such as Gov. Harry Hughes, state Comptroller Louis Goldstein and Sen. Paul Sarbanes are beginning to sound as if they have a new lease on life.

"Things are picking up, you can feel it," said the always ebullient Goldstein as he gave a pep talk to party regulars in Anne Arundel County one morning last week.

"There really is a new campaign since the debate," added Hughes. "I'm very optimistic now we can carry the state."

That Maryland's Democrats should have to testify to their optimism at all is revealing of a phenomenon unusual in a state where they outnumber Republicans 3 to 1. But the state's Republicans, embarrassed four years ago when Maryland was one of just six states that supported President Carter, are fairly drooling at the thought of getting off probation on Nov. 6.

If they fear anything, it is a 50-state landslide for Reagan in which a Maryland turnaround will go unheralded.

"We have an excellent chance to win in Maryland," proclaims Levey, who expects the race to narrow considerably by election day.

Levey and other members of Maryland's minority party say they are benefiting from what is, for the GOP, an unusually energetic and well-manned volunteer effort.

"In my opinion, you have to go back a long, long way to find as well organized a grass-roots Republican campaign in Maryland, maybe back to the Gov. Theodore R. McKeldin days," said Michael Owen, an aide to Rep. Marjorie Holt, who is the Reagan-Bush chairman in Maryland. McKeldin, a Republican, was governor from 1951 to 1959.

"We've had more volunteers this year than all the years put together that I have been involved," said Levey. Those troops, backed by about $100,000 in national, state and local campaign funds, have allowed the local Reagan-Bush campaign to mount what Levey termed a "massive" phone bank and direct-mail operation targeted at independents and wavering Democrats. And though final figures are not available, Maryland Republicans feel they have more than held their own with the Democrats in registering new voters.

Though it has not yet been reflected in the polls, Democrats say that Mondale's strong performance in the first presidential debate two weeks ago gave them a major shot in the arm.

"The first debate was a major turnaround," said state Del. Gary Alexander, chairman of the Prince George's County Democratic State Central Committee. "We're getting a lot of calls from people who have not been involved in anything before who now want to work the polls and distribute literature."

Alexander added that the debate also energized Democratic officeholders in the well-disciplined Prince George's party organization. "Those who were lukewarm can now hold their heads up and say we have a credible candidate who can go toe-to-toe with the president. We have nothing to be ashamed of," said Alexander.

For the first time in many years, the Democratic campaign in Maryland is organized primarily around the existing party structure -- the state headquarters and the 24 central committees -- rather than a separate campaign organization. Though the national Mondale-Ferraro campaign has three paid staff members in Maryland, the nitty-gritty of campaigning has been left to the central committees.

The national Mondale-Ferraro campaign has left much of the field work to local Democratic organizations in order to divert as much money as possible into use of the media. "It allows normal, everyday, hard-working Democrats to become truly involved," said Mike Frazier, the national campaign's Maryland coordinator. "It pulls more people into the process."

One factor that could favor the Democrats on Nov. 6 is the drawing power of local referendum questions in their two most important jurisdictions, Baltimore and Prince George's County. When Carter carried the state in 1980 by just 46,000 votes, he did so largely because of pluralities of 120,000 and 20,000 votes in Baltimore and Prince George's.

A key element in those areas is the black vote, which went heavily for Jesse L. Jackson in the May 8 primary. The state's Jackson campaign chairman, Prince George's County businessman Bennie Thayer, says that the Mondale campaign has not sufficiently exploited the potential of the Jackson partisans.

"I truthfully feel that those voters are there and are ready to be electrified to come out," said Thayer. "Unfortunately, Mr. Mondale's campaign prior to the debate did not lend itself to keeping the fervor of Democratic voters high. But I'm hoping that in the next two weeks, the fervor will perk up again."

Both Democrats and Republicans say that tonight's second and final presidential debate could determine the outcome in Maryland.

"Maryland is not as pro-Reagan as the nation," said Owen. "But all things considered, I think the president has an awfully strong shot in Maryland. If the debate comes out well, we'll be solidly in the saddle. We can win this state."