I used to work out deep in the forests of the northern Rockies, where we had grizzlies and black bears.
The biggest issues with trying to shoot an attacking bear is that their head is very big, but the skull inside of it is small. All that fur, meat, and fat make it look huge. You can shoot a bear in the head and miss its skull completely. Doesn't matter what size gun you're using.
Bear attacks are very unlikely. If you find yourself in bear country, I recommend getting a can of bear mace/pepper spray. The stuff made for bear country works, and works well. (Ive experienced it personally. That gun show OC spray is a joke in comparison)
I also recommend looking up techniques for handling a bear should you encounter one. There's good videos out there for hikers. Using the right body language can be all the difference between a bear walking off and a bear attacking you. Cliff's notes version: Should you run up on a bear, don't turn and run, and don't scream. Stop, stand still a moment, and slowly raise your arms up beside you. Face the bear, but don't stare it in the eyes. Try to talk in a loud, but calm voice, and start backing away. I know it all sounds weird, but it shows the bear you're not dangerous, and not a prey animal, and should let you escape. IF the bear tries to charge ya, thats when its pepper spray time.
One quirk about black bears. If they're standing on their hind legs, or look like they're thinking about charging you, they're being territorial. Backing out of their territory should save your bacon. HOWEVER should a wild black bear every approach you acting docile or friendly it has already decided it intends to eat you. A friendly bear is the most dangerous bear of all.
If you're going to pack a gun for bear country, I'd recommend a 357 or 44, loaded with JSP ammo. If you carry a 9mm, make sure you've got some hard ammo that will penetrate deep.