Refiners in the gulf have been getting more light crude from the shale boom than they can process and not enough of the heavier oil for which most of the refining capacity is designed. As a result, they are still importing heavy crude from Mexico and Venezuela, and medium crude from the Middle East, said Rob Smith, an analyst at PFC Energy, a consulting firm.

At the same time, companies like Valero, which is based in Texas, have been altering their refineries to handle the lighter crude from shale fields, which the southern Keystone connection could make even more available.

And since oil prices have been stuck at more than $100 barrel, Canadian oil sands producers have a strong incentive to get their product to market now.

As TransCanada, the company seeking to build the Keystone pipeline, awaits a decision from the Obama administration on whether it can build, producers have been turning to rail. A recent report by RBC Dominion Securities said that shipping crude by rail could pick up the slack if Keystone was not approved, delaying but not stopping the development of the Canadian oil sands.

“Pipeline infrastructure will always lag behind new production, just because you have to have proved production before you can invest billions of dollars in a pipeline,” Mr. Smith said, adding, “so rail steps in to fill the gap.”

In the United States, rail shipments of crude increased to nearly 234,000 carloads in 2012 from 9,500 at the beginning of the boom in 2008, according to the Association of American Railroads. Warren E. Buffett has been a big beneficiary. This year, the railroad BNSF, which he bought in 2010, helped drive the stock price of his company Berkshire Hathaway to a record high.

But North American railroad companies have been scrambling to add new track and loading terminals, as fuel companies buy more cars specially designed to carry the flammable crude.