'Allegedly' the earliest identified use of the exact phrase "the whole 9 yards" dates from 1942, in the Investigation of the National Defense Program: Hearings Before a Special Committee Investigating the National Defense Program, by Admiral Emory Scott Land, who said "You have to increase from 7.72 to 12 for the average at the bottom of that fifth column, for the whole nine yards". This use refers to the total output statistics for the nine new shipyards that produced "Liberty Ships" with unprecedented speed, crucial to the course of World War II. I don't know what gave rise to the phrase.
The most frequently quoted explanation of the term "the whole 9 yards" came from WWII fighter pilots in the South Pacific. When arming their airplanes on the ground, the .50 caliber machine gun ammo belts measured exactly 27 feet, before being loaded into the fuselage. If the pilots fired all their ammo at a target, it got "the whole 9 yards." There are several claims for this phrase. The yard is quite an old measurement.
The whole 9 yards... In early Scotland, a gentleman wore a kilt. There were two types of kilts, one for casual wear, and one for formal affairs. The formal one took 9 yards of tartan. The tailor would inquire to which kilt was needed, and the reply…if it was for a formal one was “I’ll take the whole 9 yards” This one could be fairly old.