In this paper, we present the construction and analysis of an interior solution for a compact star in Rastall gravity. The space–time considered is static and spherically symmetric, meanwhile, the source of matter is that of a perfect fluid. The solution of the equations system which describes the model is obtained from a specific form of the red shift factor function and its result is physically acceptable. The analysis of the solution is focused on the description of the star PSR [Formula: see text], for which we know the observational data of mass [Formula: see text] and radius [Formula: see text][Formula: see text]km, a comparison with the behavior of the solution in the frame of Einstein’s general relativity theory, [Formula: see text], shows that for [Formula: see text] the density, pressure and speed of sound are greater, meanwhile for [Formula: see text] their values are lower. The analysis of the generalized TOV equation to the case of the Rastall gravity implies that the contribution of the force associated to the Rastall parameter can generate an attractive ([Formula: see text]) or repulsive ([Formula: see text]) force, showing the relevance and the effect that the Rastall parameter has in stellar models.