The United States got another visible sign of the potential impace of the Middle East oil turmoil yesterday as the government reported the nation's foreign trade deficit mushroomed to $3.1 billion in January, up from $1.7 billion in December.

The sharp rise, reflection a large increase in U.S. purchases of foreign oil, came after the Commerce Department changed the way it computes the trade figures to provide a more accurate measure of petroleum imports. Officials said if the figures had been calculated on the old basis, the deficit would have been $1.9 billion, down from $2 billion in December.

Economists said the continued rise in petroleum imports reflected a push by buyers here to beat the Jan. 1 price increase imposed by the Organization of Petroleum Exporting Countries. While most of those orders were placed in December, some shipments did not arrive until January.

Meanwhile, the Agriculture Department reported that farm prices leaped another 3 percent in February following a 5 percent rise the previous month, pointing to continued pressure on retail grocery prices over the next several weeks.

As the same time, the Labor Department announced that wages and salaries of Americans rose an average 7.7 percent last year after jumping 1.5 percent in the final three months of 1978. By comparison, consumer prices rose 9 percent last year, up from 6.8 percent in 1977.

The combination of figures marked disappointing news for the Carter administration, which as late as mid-January had been predicting that the trade balance would improve markedly this year and that farm prices would taper off. January's trade deficit was the largest in 11 months.

Officials stressed that the bulk of the increase in the trade deficit came from changes in the way the Commerce Department computes its figures -- shifts they said it made to improve their accuracy. The changes involved the way the figures are adjusted to compensate for seasonal patterns.

William A. Cox, the department's deputy chief economist, said he still expected to see "continued improvement" in the nationhs underlying trade posture, and saw no reason yet to revise predications that the trade deficit would drop to $24 billion, from $28.45 billion in 1978.

Nevertheless, most private analysts were more pessimistic about the outlook. Although the oil situation in the Middle East still is uncertain, almost everyone expects prices to rise further.And U.S. demand for other products also continues to be strong.

The $3.1 billion trade deficit in January reflected a whopping 8 percent, $1.2 billion jump in imports and a sizable 1.1 percent, $150 billion dip in exports. Import levels rose to a $16.2 billion toatl, while exports fell to $13.13 billion.

Largely because of the effort to beat the price boost, the value of oil imports soared 13.9 percent in January to $3.99 billion, a net rise of $418 million from December's figures. There was no immediate breakdown of how much represented volume and how much reflected price boosts.

But there also were other setbacks: Imports of foreign-made machinery and equipment rose sharply, while exports declined, for a net dip of $744 million. And agricultural exports also fell off visibly, while imports increased.

As in previous months, the increase in farm prices domestically was concentrated primarily in cattle and hog prices, with companion rises in prices of soybeans, oranges and broilers. Prices of cotton, potatoes and turkeys fell.

In all, farm prices in February were some 24 percent above their levels of a year ago, marking one of the better years for farmers in most major livestock and crop categories. Wholesale food prices soared in January, partly in response to previous farm-price boosts.

The $3.1 billion trade deficit was calculated on fthe department's traditional "free-alongside-ship" basis. On another measure, used most often by other nations, the deficit was $4.15 billion, compared with $2.7 billion in December.