2 Samuel 8:1
And after this it came to pass, that David smote the Philistines, and subdued them: and David took Metheg-ammah out of the hand of the Philistines. And after this it came to pass, that David smote the Philistines, and subdued them: and David took Metheg-ammah out of the hand of the Philistines.
2 Samuel 8:1 belongs to the clear narrative record of the wars connected with David's rise to rule all Israel, set within the conflict between Saul's son and David that ended with David's triumph and kingship over all the tribes. It falls within the record covering almost the entire reign of David over all Israel. It records David striking and subduing the Philistines and taking Metheg-ammah out of their hand, as one of his victories over various kingdoms.
That history begins with the long war between the house of Saul and the house of David and continues through the capture of the city of Zion, the defeat of the Philistines, the bringing up of the ark, the plan to build a temple with prayer and thanksgiving, kindness to Mephibosheth, wars with Ammon and Syria, and troubles over Uriah and over Amnon and Absalom. The verse shows David fighting the Philistines and other enemies of Israel, and even during his time in Philistine territory much of his effort was spent warring against Israel's enemies. After he became king over all Israel he subdued his enemies and greatly extended the kingdom's boundaries, so that Israel's dominion grew tenfold under him and was never extended as far by his successors.
He subdued the Philistines and other neighboring peoples, took the Syrian kingdom and garrisoned Damascus, and extended Israel's frontier eastward to the Euphrates, though perhaps not beyond it. This victory belongs to the period when Israel became a consolidated and powerful kingdom and the Lord gave David rest from surrounding enemies. With that rest, David, living in a cedar house while the ark was in a tent he had pitched, considered building a permanent house for God's ark, though the tabernacle itself remained at Gibeon.
By the time David fell into sin, the prosperity and the ease and wealth gained through these victories may have fostered the pride and luxury that preceded his fall.