Well, I'll guess I'll revive this thread after a long absence. The Starfleet Security personnel could be trained like Air Force Security Forces personnel. My brother does this job. They usually carry out law enforcement duties on base, but do get trained up to do patrolling in Iraq too. They went to some extra training for a month or so and then went to Iraq for 6 months. So Starfleet Security could also do this, in peace time they act as security and law enforcement. During war time they shift into a more infantry type mode. Afterward, they go back to being "regular" security. They also have their specialized units too; spec ops and SWAT teams, combat controllers, and para rescue. So Starfleet Security can do all these jobs, just during wartime their numbers would swell exponentially.
A ship usually carries enough security personnel to maintain security on ship, the larger the ship, the larger the security contingent. Maybe a platoon sized element on a Constitution-class and a company or two for a Galaxy-class.
"Retreat?! Hell, we just got here!", annonymous American Marine, WWI
"Gravity is a harsh mistress....", The Tick