The church grim is a guardian spirit in English and Scandinavian folklore that oversees the welfare of a particular Christian church and protects the churchyard from those who would profane and commit sacrilege against it. It often appears as a black dog but is known to take the form of other animals.

In the 19th century, folklorists believed that it had once been the custom to bury a dog alive under the cornerstone of a church as a foundation sacrifice so that its ghost might serve as a guardian.

More Info: en.wikipedia.org