In Spain the main source is Seguridad Social, the same agency and tax which cover healthcare, disability and unemployment benefits. If you’re a third-party employee, you pay 7.5% of your salary and your employer the other 7.5% (there is a cap); if you’re self-employed you tell SS what number to use as the basis for your calculations. It is very common for the self-employed to use the minimum value for most of our working life and raise it to a more accurate level or to the cap once we’re getting closer to retirement, as the benefits are based on your last several years (currently it’s the last 20 years).
You can also have “retirement plans”, usually by joining one organized by your bank or by a Mutua (a mutual-aid association / insurance group). Some companies offer a retirement plan but I’ve never seen matches like some US companies offer. The benefits from these are additional to your SS pension. As the government wants to incentivize these, they are deductible from your Income Tax (there’s a cap); any earnings the plan makes gets added to your portion of the plan and is reported but not taxed.
People receiving a pension, either because of disability, age or unemployment, pay less for prescribed medication than non-pensioners.