  Galaxies are expected to accrete pristine gas from their surroundings to
sustain their star formation over cosmic timescales. Its lower abundance
affects the metallicity of the ISM in which stars are born, leaving chemical
imprints in the stellar populations. We measure the amount of pristine gas that
galaxies accrete during their lifetime, using information on the ages and
abundances of their stellar populations and a chemical evolution model. We also
aim to determine the efficiency of star formation over time. We derived star
formation histories and metallicity histories for a sample of 8523 galaxies
from the MaNGA survey. We use the former to predict the evolution of the
metallicity in a closed-box scenario, and estimate for each epoch the gas
accretion rate required to match these predictions with the measured stellar
metallicity. Using only chemical parameters, we find that the history of gas
accretion depends on the mass of galaxies. More massive galaxies accrete more
gas and at higher redshifts than less massive galaxies, which accrete their gas
over longer periods. We also find that galaxies with a higher star formation
rate at z = 0 have a more persistent accretion history for a given mass. The
star formation efficiency shows similar correlations: early-type galaxies and
higher-mass galaxies had a higher efficiency in the past, and it declined such
that they are less efficient in the present. Our analysis of individual
galaxies shows that compactness affects the peak star formation efficiency that
galaxies reach, and that the slope of the efficiency history of galaxies with
current star formation is flat. Our results support the hypothesis that a
steady and substantial supply of pristine gas is required for persistent star
formation in galaxies. Once they lose access to this gas supply, star formation
comes to a halt.
