why do I need \connect hostdb In the answer to How to manage DEFAULT PRIVILEGES for USERs on a DATABASE vs SCHEMA? 

I see the line \connect hostdb why and when do I need this line? 

I'm executing role creations SQL line from a .sql file
That's needed because the target database for the rest of that script is created just in the line above that statement. However creating a new database doesn't automatically switch to that database. In order for all following statements to be executed against that new database, the connection needs to be switched to that database.