I have a requirement in which I need to take a database snapshot and restore it on the same machine with some other predefined name in postgres. I tried to complete the above task with the following command.
CREATE DATABASE destniationDb TEMPLATE sourceDb;
But this parameter fails if a connection / session with source code exists. Therefore, I need to truncate this parameter, since there is a high probability that the user will perform a read operation. All command line options like restore_db, backup_db meet my requirements. I need some kind of console command / function / storage procedure to achieve it, i.e. I need to connect to the database and call some storage command / function / procedure that accomplishes this.
Can any of you suggest any solution for my requirement?
source share