You can get one as a pet from Gourmet after you meet him at the egg festival for the first time. Additionally, you must own one animal barn before you are able to get the pig. Go inside the animal barn for a cutscene of Gourmet giving you the pig. You will be able to name the pig and it will live inside your home with your dog.
If you are lucky, you can use your pig to sniff out truffles for you. This is done by bringing the pig outside, and leaving it around a tree – Fall is the most successful season for this. You can use a hoe to till up the land around a tree (two squares away in each direction). You can find truffles more effectively this way. If you are going for all of the musical notes in the game, owning a pig and having him dig up a truffle is essential. Note #45 (Oink-Oink Note) requires the player to ship a truffle.
If you leave the pig outside, it will eat weeds on your property.