Is it possible to attach/detach databases to PostgreSQL on the fly, i.e. while the server is running without having to restart the service? I can't find anything related to this in the documentation.
What I am trying to achieve is to have the user be able to select different data directories from an archive location and then have them loaded into PostgreSQL, and later removed when the user is finished.
Best Answer
No, short answer is no. This has been asked at the PostgreSQL development mailing list at 2011: Detach/attach database and the many replies in summary said "yes, this is feasible to implement but quite complicated to do so.":
Leaving aside all the internal implementation details / problems that would make this possible, the last comment has something that may be helpful to you:
Run a different cluster per database. You would probably need to implement something of an infrastructure so when a user wants to "attach" a database, it would start up the related cluster and stop it when the user wants to "detach" it.