You can change your PSN Online ID on PS4, PS5, web browser, or PlayStation App. First change is free; subsequent changes cost $9.99 (US) / £7.99 / €9.99 (PS Plus members pay $4.99 / £3.99 / €4.99).
Sony maintains a list: PSN Online ID Change – Game Compatibility. Known problem categories:
Test your most-played games immediately after change. You can revert to old ID once for free within 30 days if issues arise.
Changing your Online ID is safe for most modern (PS4/PS5) games. Do your homework first.