One verse

Srimad Bhagavatam 2.3.8

2.3.8

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

dharmartha uttama-slokam tantuh tanvan pitrn yajet raksa-kamah punya-janan ojas-kamo marud-ganan

dharma-arthah
for spiritual advancement
uttama-slokam
the Supreme Lord or persons attached to the Supreme Lord
tantuh
for offspring
tanvan
and for their protection
pitrn
the residents of Pitrloka
yajet
must worship
raksa-kamah
one who desires protection
punya-janan
pious persons
ojah-kamah
one who desires strength should worship
marut-ganan
the demigods.

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