When a whale gets buried, it’s not 6 feet under. It’s more like 15 feet under. The deeper the better, according to the whale undertakers who were wearing face masks on Tuesday for the first double seaside cetacean service in Pacifica history.

An excavator jabbed its giant claw into the beach shortly after 8 a.m., carving out the first of two holes in the sand that were to become burial sites for a pair of whales that washed ashore and then became too stinky for neighbors’ liking.

“It would have been fine just to let it rot, but it became a quality-of-life concern as far as the smell,” said Steve Castile, a manager with the San Francisco Recreation and Park Department.

The big dig at Sharp Park State Beach is expected to continue through Wednesday and will cost Pacifica and San Francisco taxpayers about $40,000. San Francisco was on the hook because it maintains the property, while Pacifica was on the hook because its residents objected to the stench.

It took the giant yellow excavator about an hour to dig the first of the holes about 50 feet inland from the carcass of the northernmost — and smelliest — of the two whales, a 42-foot female humpback. Onlookers holding their noses watched the operation from behind strands of yellow caution tape, which weren’t really necessary because the odor served as its own deterrent.

“It doesn’t smell that bad, but I grew up on a ranch in Montana, so I’m used to it,” said whale mourner Thomas Clark, an operatic tenor who said the whale interment was the highlight of his morning constitutional. He had never attended one before, and neither had the workers hired to do it.

Burying a whale is like burying anything else — first you dig the hole, then you pick up the body, then you put it in the hole. But with a whale, each step must be thought through.

The excavator operator first laid wooden planks beneath the treads, to prevent the excavator from becoming as stuck on the beach as the whale. The whale was buried well inland from the water line to prevent a high tide from uncovering it and forcing the crews to return.

“You want to bury it deep enough so no bones stick out,” said one of the pallbearers in a yellow safety vest.

The actual picking up of the carcass was tricky. The plan was to use the excavator to break it into pieces and place those parts in a large metal bin, but the remains were held together by skin and did not readily yield to repeated shaking and jabbing by the giant power shovel, which resembled nothing so much as a

T. rex.

The whole operation looked like something out of “Jurassic Park,” and watching was not for the faint of heart, nose or stomach.

“You don’t see something like this every day,” said passerby Petra Schumann of Pacifica. “Actually, you never see it.”

But it may happen again soon, because on Tuesday a third whale floated ashore in Half Moon Bay. Thought to be a gray whale, 25 to 30 feet long, it was found near Poplar Beach. A spokeswoman for the California Academy of Sciences said researchers would perform a partial necropsy — if the whale wasn’t carried back out by the tide.

In Pacifica, the humpback whale washed up May 5 with injuries consistent with blunt force trauma, and it might have been hit by a ship, said researchers after performing a necropsy on the beach. They found four broken vertebrae, surrounding hemorrhaging and a broken rib.

A 48-foot sperm whale washed up April 14 about a quarter-mile south of the humpback. Scientists could not pin down a cause of death in the earlier case but ruled out a ship strike.

The precise location of the carcasses was key to figuring out who was obliged to pay the undertaking bill. The sperm whale at first came to rest at Mori Point, within the jurisdiction of the Golden Gate National Recreation Area, but shortly after a necropsy was performed, the tides moved the carcass north and into San Francisco’s jurisdiction, according to city park spokeswoman Connie Chan.

That bit of oceanic happenstance shifted the bill for the sperm whale’s burial to San Francisco taxpayers. The other whale, the humpback, was always San Francisco’s responsibility.

The city would have been within its rights to do nothing and save the $40,000, Chan said. Allowing the whales to decompose naturally, she said, posed no health or safety concerns. Burying the whales was a public relations gesture, and San Francisco and Pacifica agreed to split the cost.

“San Francisco definitely wants to be a good neighbor,” she said. “That’s why we arrived at this solution.”

The demise of the giant creatures was a sad thing but, said Castile, if two whales were going to wash up on the beach, it was a good thing they washed up at about the same time and the same place. That way, the city only had to hire one excavator for both burials, which probably saved about $5,000 compared with the cost of two separate whale burials.

“Two at once is a better deal,” Castile said.

Steve Rubenstein is a San Francisco Chronicle staff writer. E-mail: srubenstein@sfchronicle.com