How to initialize db component as lazy as possible?

I don’t known the exact address or port at first because using name service to connect to my database server.So I couldn’t set it in main.php or param.php.I think the better time to initial connection is when using the db component. What shall I do?

It is like that by default.

If I could write “host => xx.xx.xx.xx”,it’s ok.

But I’m user a name service, I need to resolve it by some code.If the code run before params.php, the resolve is always performed.That wastes server performance.

Is there some better solution?

Please be more specific about the use case.