shredding,
RE: "Dont you have longer sustain when you have more gain?". Yeah, you usually do, but as fishyfishfish explained, it's not an exact 1:1 ratio. The Rectos actually have more raw gain than is useable on tap, in that, with the gain knob all the way up, the tone is actually too muddy for most uses. Yes, the sustain is improved, but in the case of the Recto, it is still not particularly impressive. Therefore, it may not be possible to achieve desireable levels of sustain merely by turning up the amp's gain.
The most common, and the most powerful, way that sustain is increased, regardless of the method to achieve it, is to add compression to the raw signal. An amp's preamp tubes do this by adding more gain to the signal and taking advantage of the fact that vacuum tubes will naturally compress a distorted signal. Boosters will add sustain by simply increasing this process in the amp's preamp tubes by providing a more powerful signal to the preamp. The preamp then adds gain, and the resulting compression, to the signal, resulting in more sustain.
Overdrives work somewhat differently. While they do provide a net signal boost (in most cases), they also boost and distort the original signal and additional harmonics, thereby adding in compression within the pedal itself. The compressed and boosted signal then leaves the pedal and hits the preamp tubes where, as before, even more gain, and therefore compression, can be added.
Another option is to rely exclusively on distortion and compression of the signal by the use of a distortion pedal. Such pedals usually offer a net increase in overall signal level (i.e., a gain boost), but rely primarily on the creation of signal distortion by 1) the addition of harmonics above the fundamental of the signal, and 2) the conversion of the entire signal to (usually) square-wave signal output. The circuitry of most distortion pedals is such that it adds significant amounts of compression to the distorted signal. Running the pedal's distorted signal into the clean channel of an amp does not usually result in any further appreciable amounts of either gain or compression, but distortion pedals are quite often capable of generating impressive amounts of sustain by themselves.
The addition of a compressor pedal, whether relying on the amp alone, an overdrive + amp, or a distortion + amp, will add even further amounts of compression and therefore sustain.
The choice of method in achieving the sustain you want is often a matter of tone preference as much as a strict comparison of which method produces the most sustain. For example, a compressor pedal run into a distortion pedal then into a high-gain preamp with the gain knob maximized will yield the greatest sustain of the options described. However, tonally, most people would consider the sound of such a signal to be completely unuseable, with no dynamics, indistinguishable note articulation, and a noise floor so high that the signal itself is hard to discern.