I have a PostgreSQL database and my app is coded with VB.NET, For my purpose I do Copy my DB(called orginladb
) in same server by taking backup of orginladb
and create new db(orginladb_copy
) and restore orginladb
to orginladb_copy
I've written 4 separate code for Bakcup
,Drop DB
,Create DB
and Restore
,following is the methods
/* Backup */
--------
pg_dump --format=c --username "postgres" originaldb > "D:\Backup\originaldb .backup"
/*Drop*/
------
psql -U postgres -d postgres -c "DROP DATABASE if exists "\"originaldb_Copy"\""
/*Create Copy Of Database*/
----------------------------
psql -U postgres -d postgres -c "CREATE DATABASE "\"originaldb_Copy"\""
/*Restore originaldb.backup to originaldb_Copy*/
---------------------------------------------------
pg_restore -d originaldb_Copy "D:\Backup\originaldb .backup"
So my question is how to copy original db to the same server in a single step or using a single function
?