Your stomach pH is in the range of 1 to 3 (Wikipedia). If it goes into the very acidic rage and you develop heartburn, antacids can be used to raise the pH and soothe the irritation.
Antacids aren't used to raise the pH above 7, just to move it above 1 or 2. The amount of NaHCO3 you would ingest is so small that it would not do more than this, and even tho its pH in plain water is 8.5, it is quite harmless.
Magnesium hydroxide is only very slightly soluble, but it will raise the pH of plain water to about 9; still pretty harmless, but it will dissolve in strong acid and neutralize it. The amounts ingested are small enough not to raise the stomach pH much, and it won't hurt the esophagus when going down. Aluminum hydroxide is similar.
Very strong and very soluble alkalies would burn the esophagus going down, so are not used. Antacids don't need to bring the pH into the alkaline range, just to increase the pH enough to be less irritating. Commercial proton pump inhibitors can decrease stomach acid by up to 99% (equivalent to about 2 pH units). That's all that's needed.