The following op-ed by Jonathan Waldman ran in The New York Times on Friday, March 6, 2015. Mr. Waldman is the author of the forthcoming book “Rust.”

TWO years ago, I spent a month watching engineers inspect the Trans-Alaska Pipeline, one of the world’s biggest, most remote and most complicated pipelines. The endeavor entailed sending a five-ton “smart pig” — a rust-detecting robot — 800 miles across the length of Alaska, like a spitball in a giant straw, as it hunted for signs of metal loss.

Federal law mandates such inspections on all interstate pipelines every five years, but the Alyeska Pipeline Service Company, the operator of the Trans-Alaska Pipeline, inspects its pipeline nearly twice as often. The $2 million pig was capable of scanning the pipe inch by inch, and the company wanted data on every one of the pipeline’s seven billion square inches.

Like all major pipelines, the Trans-Alaska Pipeline is monitored by leak-detecting software, which compares the flow of oil going in one end with the flow coming out the other, and scans for sudden pressure drops. And like all major pipelines, it has suffered its share of such leaks and other maintenance woes. But unlike other pipelines, it has never, in nearly 40 years, suffered a leak induced by corrosion — a major threat to aging pipelines. That’s because threats like pits, dents and weld misalignments have been discovered and quickly repaired.

Last week, President Obama vetoed legislation that would have pushed forward the construction of the controversial Keystone XL pipeline. A Senate vote to override the veto fell short on Wednesday. But even foes of the pipeline, which would run from Canada to Texas, have begun to concede that blocking it won’t actually prevent Canada from extracting its tar sands oil. Ours is an energy-thirsty world, and when demand eventually drives up the price of oil, out it will come. If the oil is going to be consumed one way or another, then the only remaining argument against the Keystone pipeline is that of preventing local environmental catastrophes that result from spills. But we’ve got it all backward.

Pipelines are the safest way to move oil. They’re an order of magnitude more reliable than trains, and trains are an order of magnitude more reliable than trucks. So the banners that say “If you build it, it will leak” should also be followed by “But if you don’t build it, you’ll have a lot more leaks.”

That said, there is much we can do to make pipelines even safer. This is especially important now that our pipelines are aging: More than half of them were built before 1980.

We started this debate, before Congress, in the 1960s, when federal oversight of pipelines was first on the table. That followed the explosion of a gas pipeline in Natchitoches, La., that left 17 people dead. The oil and gas industry adamantly opposed new regulations, and since then a sad pattern has emerged: dramatic explosion, calls for reform and powerful resistance.

Twenty years passed before federal law first mentioned the use of smart pigs. In the generation since, regulations have actually gotten laxer, while smart pigs have gotten a lot, well, smarter. They can record tons of information, and capture unprecedented levels of detail, by monitoring magnetic flux leakage, ultrasonic transduction or acoustics. They’re also more agile: They can traverse narrow pipelines and take tight turns. Coatings on pipelines have gotten a lot better, too. Furthermore, leak-detection software isn’t as hiccupy as it used to be, and because operators can now examine smart pig data digitally in one big database, they can monitor corrosion over time, much as a dentist monitors decay on your teeth.

I’m not pro-pipeline or anti-pipeline; I’m for infrastructure we can maintain.

If Mr. Obama wants to take a bold stand, he should agree to accept the construction of Keystone in exchange for demanding stricter pipeline inspection standards, like the ones Alyeska abides by. This would include more frequent inspections (at least as frequent as emissions tests for automobiles in most states), lower criteria for intervening in response to corrosion and requirements that the information be made public. He should ensure that the Pipeline and Hazardous Materials Safety Administration is properly funded, protected from industry influence and granted increased enforcement powers, including the ability to impose higher penalties. Fines need to be proportional to the oil dollars flowing out of pipelines if they’re going to serve as a deterrent.

This would be a great way to “set our sights higher than a single oil pipeline,” as Mr. Obama himself said in his State of the Union address. It’s also what Senator Warren G. Magnuson of Washington, who in 1967 introduced the legislation that granted federal oversight of pipelines, would have wanted. His slogan: “Keep the Big Boys Honest.”

As we continue to debate the merits of a pipeline down the middle of the lower 48, we ought to look at the one that runs down the middle of Alaska. That one, which happens to be the most regulated pipeline in the world, owes much of its good condition to that status. Getting behind a law holding pipelines to higher standards seems an executive act far more courageous than a veto.