Srimad-Bhagavatam: Canto 2 - Chapter 1 - Verse 8


धर्मार्थ उत्तमश्लोकं तन्तु: तन्वन् पितृन् यजेत् ।रक्षाकाम: पुण्यजनानोजस्कामो मरुद्गणान् ॥ ८ ॥


dharmārtha uttama-ślokaṁtantuḥ tanvan pitṝn yajetrakṣā-kāmaḥ puṇya-janānojas-kāmo marud-gaṇān


One should worship Lord Viṣṇu or His devotee for spiritual advancement in knowledge, and for protection of heredity and advancement of a dynasty one should worship the various demigods.


The path of religion entails making progress on the path of spiritual advancement, ultimately reviving the eternal relation with Lord Viṣṇu in His impersonal effulgence, His localized Paramātmā feature, and ultimately His personal feature by spiritual advancement in knowledge. And one who wants to establish a good dynasty and be happy in the progress of temporary bodily relations should take shelter of the Pitās and the demigods in other pious planets. Such different classes of worshipers of different demigods may ultimately reach the respective planets of those demigods within the universe, but he who reaches the spiritual planets in the brahmajyoti achieves the highest perfection.