What's the best weapon for civilian home security, a shotgun or a pistol?
Typically a deadbolt on the front door and an alarm. If you're in a really bad part of town get a solid wood or metal door for your bedroom (interior doors are typically hollow-core) and get a deadbolt lock for it too. Don't get a lock too complicated that you would fumble around with it in a burning smoke filled room though :)
Shooting people for any reason is generally a stuffty idea even when it's legal, and should be saved if you don't have another option. If you manage to kill someone in self defense there's a good chance that you will still get in trouble. Even if you're legally absolved you're not necessarily going be forgiven by your assailant's family. There's been instances where some rowdy teenagers broke into a house (teenagers with nothing to do on a Saturday break into homes all the time) and were shot and killed. Their families would probably make your life so miserable you'd shoot yourself eventually.
From another angle, you should keep weapons unloaded and the guns and ammo locked up whenever you're not using them. If your gun is in a place where you can reach and fire it in 10 seconds, it's also in a place where your nephew can accidentally blow his head off on Christmas while everyone else is unwrapping presents. Or hell, take this very unlikely case: your next door neighbor's 4 year old kid wanders into your house through a dog door, gets into your bedroom, finds your gun, and shoots himself. Guess what, you'd still be liable for the injury! Keep a wood bat around instead.
That being said, and this is coming from someone who knows very little about guns, I would say a handgun, because it's probably more convenient for storage. Things like accuracy, range, and stopping power shouldn't even factor into a residential setting unless you're being robbed by a trained SWAT team or something.
Finally, interior walls should stop bullets if you bought a small handgun anyway, bedrooms are typically laid out in a pattern that would make it near impossible to accidentally shoot your sleeping family (bedroom doors open into halls, not other bedrooms. because of this someone coming into your bedroom would be coming through a door or a window, not the next bedroom's wall, so you wouldn't be shooting towards nearby sleeping people anyway), and accidentally shooting your family is all the more reason NOT to use a gun for self defense in your house. Save it for sport. Don't try to defend your house, just leave it, it's not worth putting yourself in danger (or a lifetime of litigation and court fees).