The question of carrying a gun, and even more important, using it, is not easily answered. Everyone has to evaluate their own abilities and moralities. Once a bullet leaves the barrel it can't be called back.
I retired from Law Enforcement and was asked this question many times by homeowners. I always answered with telling them to get several good can's of pepper spray. Keeping them within easy reach of the areas they spend the most time in.
The goal was to disengage from the attack or intrusion and effect an escape from harm. It's not worth dying over, just isn't.
Pepper spray can be washed off. The accidental shooting of the wrong person can't as easily be taken back. I'm sure if you sprayed the wrong person with pepper spray amends could be made over a few beer's.
Some countries consider pepper spray a weapon, so check first.
I did see one suggestion that I truly like and have adopted. When in a questionable anchorage I scatter a handful of carpet tacks on the
deck by the stern ladder. Even folded up it is still the best way to board. Most of the banditos are barefoot. Only takes about 30 seconds to sweep them over into a corner and recover them until needed again.
Let the bad guy be his own burglar
alarm.
Cheers,