I am creating a platform in java, where one of the needs is to create a new bd using the template of another existing one. For this I try to use the following query:
CREATE DATABASE bd_copia WITH TEMPLATE bd_original;
When executing the script it fails because it is being accessed. To "kill" the connections to the bd_original you should use:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'bd_original' AND pid <> pg_backend_pid();
But that's where my problem comes from, since I'm closing the current connection with which I'm working from the web platform.
Is there any way to achieve this or an alternative?