The discovery was made after another child was threatened in the school's playground on 4 March.
A boy was excluded from the school following the incident, in which no-one was injured.
A police spokesman said the child was spoken to and reported to the Reporter to the Children's Panel.
He added: "No-one was injured in the incident and a knife was recovered."
Dumfries and Galloway council described the behaviour as "totally unacceptable".
A spokesman said the local authority took safety in its schools very seriously.
He added: "The school carried out investigations immediately and handled the matter appropriately and sensitively, involving the parents of the children concerned and Police Scotland.
"The incident resulted in an exclusion, with arrangements in place between the pupil, parents and the school in terms of expectations, support and supervision.
"The council is providing support, advice and resources to assist the school deal with this matter."
Police were called to a primary school in Dumfries after a nine-year-old pupil was found with a knife, it has emerged.