A few points to clarify: the first £ 12,570 you earn are tax-free (other than for very high earners who see their personal allowance go to zero, which also causes the marginal tax rate to jump to 60ish %, but that's not the case here).
So if you earn, say, £20,570 and have already contributed £3,000 to your pension, the maximum you can contribute while still getting tax relief is £ 5,000 (=£20,570 - £3,000 - £12,570).
You can contribute more, but then you wouldn't get tax relief, because you wouldn't have paid any tax on it, and HMRC cannot refund you tax you never paid in the first place!
So let's say you earn £20ish k and already contribute £3k to your pension. You want to contribute £20k because, for whatever reason, you have £20k lying around somewhere :) Best to do it over 4 years so as to maximise the tax benefits. Oh, and do bear in mind that thresholds can change from year to year.
For defined-contribution, how much you put in is how much you put in.
But, for defined-benefit, there are certain rules to calculate how much your contributions have used up of your allowance. I don't remember them now.