A California city which was once a thriving Gold Rush town has become a cautionary tale about financial excess and the still-struggling US economy -- by going bankrupt.

In the 19th century Stockton, which lies two hours east of San Francisco, was a destination for optimistic miners looking to strike it rich in the Wild West.

Last week, in a sobering reminder of the still-painful fallout from the 2008 near economic meltdown, it became the largest US city to ever declare bankruptcy.

The inland agriculture hub has been crushed by the foreclosure crisis, increasingly costly retiree benefits and debt for civic projects taken on in better times.

Connie Cochran, a spokeswoman for the river-port city, said Stockton has been operating on a bare-bones budget for several years that has forced cuts to essential services like police and firefighters.

Officials could not close a $26 million hole in this year's $521 million budget, she said.

"We're at such modest levels of essential services, we had to do this to protect the health and welfare of our city," she said.

Stockton's financial situation, while extreme, is not unusual.

Cash-strapped cities across the Golden State -- the world's eighth largest economy, if it were a country -- are still struggling to recover from the worst economic downturn since the Great Depression.

"Cities are obviously in very difficult times economically," said Eva Spiegel with the League of California Cities. "Lots of cities are really struggling, trying to keep providing the right services."

As officials look for ways to bring local budgets out of the red, cities are watching the unusual Stockton case closely to see whether bankruptcy may provide a solution.

"Everyone is watching to see if someone comes up with a way to quickly, effectively resolve these matters with the least amount of pain," said Chicago bankruptcy attorney Jim Spiotto.

Historically, city bankruptcies are extremely rare, Spiotto said. The process is banned or restricted in many states, he said, and there have been only 641 such filings since it became legal in 1937.

It wasn't supposed to come to this.

Stockton, a city of about 292,000, teemed with eager homebuyers in early 2000s. Some 85 miles inland of San Francisco, the agriculture hub and historic gold rush town offered an affordable alternative to the Bay Area.

As the economy boomed, officials also spent big. They doled out generous benefits to city employees and took on debt for civic improvement projects, like a revamp of the waterfront promenade and a new sports arena.

Today, a retired city employee who worked full-time -- even just for a few weeks -- receives free health care for life. The city now plans to phase out those benefits.

Officials counting on never-ending economic growth had no plan for how to fund such lucrative benefits, city spokeswoman Cochran said.

"There was no funding ever put aside for it," she said. "There's no evidence of any analysis that said how are we going to pay for this."

And when the economy collapsed, Stockton couldn't pay for it. Today, unemployment is nearly 20 percent. Foreclosure rates are among the highest in the country.

While the city is cutting retiree health care, Cochran said officials have no plans to seek cuts to retiree pensions -- a major financial liability for the city.

Michael Sweet, a San Francisco bankruptcy attorney, said the Stockton case could break new legal ground in addressing whether cities can use bankruptcy to break unaffordable promises regarding retiree health benefits and pensions -- expenses that are crushing many local economies.

"That's going to be the big issue," he said. "Those are huge strains on the city budget."