I used to have very bad posture.
One way I corrected it was figure skating. Figure skating requires your back to be straight, for more power, as alot of your power actually comes from your back muscles. You can do it with any skating, but figure skates are the only skates that require it. Hockey skates encourage a forward stance too much, for stickhandling and shooting, whereas figure skates force you to put your weight back due to the toepicks in front, if you rock forward accidentally too much, you'll just go flying forward and fall. Inline skating accomplishes the same exercise, too, just you'd probably want either a flat or rockered setup, and not a hi-lo (at least I think not a hi-lo.)
For a sorta primitive way to get better posture, squats. Do squats, don't go crazy, only do what you can do 10 reps in a row of sorta comfortably, and do a few sets a day. That helps my skating power and my posture. Squats also help flexibility in general. Try to go for a 90 degree knee bend when you do it with your legs spread out. Squats actually alot is from the back muscles, doing good squats, as your back supports the bar obviously.
Pullups can help if you can do them or attempt to do them, pullups a lot of it comes from the back muscles, but it's more the upper back muscles, and not lower back like squats.
Yoga, Tai Chi, etc, are also very good, too, just I have no real experience in that realm. Oddly Tai Chi and skating actually have a lot in common as far as form goes.
One random thing that helped, crazy man Alex Chiu's immortality rings actually corrected my posture somewhat, but not as dramatic as exercise. I've had mine for years, and still wear them. I mean, they're not as good as Alex claims, he claims that his stuff will make you immortal, but, they're helpful, imo. I can understand people's aversion to them, though, as the man is insane.
Other than that, just try being mindful of your posture. I ended up correcting my off ice posture to help my on ice posture, so just be mindful of how your posture is and correct it.