postgreSQL restoration simple 4 steps
Before Restoring & creating the database you have to restore the appropriate roles and have to give appropriate roles permission
Step 1.bakup the roles by using following command
Taking postgres Roles only backup :
pg_dumpall -h localhost -p 5432 U enterprisedb -v --roles-only -f "/path/to/Preprod_roles_01012019.sql"
Step 2. Restoring the database roles it is the prerequest of postgres database restoration :
psql -U enterprisedb -d edb -f "D:\tutorialdba\Preprod_roles_01012019.sql"
Step 3. create the database with granting roles permission:
CREATE DATABASE "tdba_dc"
WITH OWNER = enterprisedb
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'English_United States.1252'
LC_CTYPE = 'English_United States.1252'
CONNECTION LIMIT = -1;
GRANT ALL ON DATABASE "tdba_dc" TO public;
GRANT ALL ON DATABASE "tdba_dc" TO crm;
GRANT ALL ON DATABASE "tdba_dc" TO adt;
GRANT ALL ON DATABASE "tdba_dc" TO ahc;
GRANT ALL ON DATABASE "tdba_dc" TO amb;
GRANT ALL ON DATABASE "tdba_dc" TO bb;
GRANT ALL ON DATABASE "tdba_dc" TO billing;
GRANT ALL ON DATABASE "tdba_dc" TO digital;
GRANT ALL ON DATABASE "tdba_dc" TO ehis;
GRANT ALL ON DATABASE "tdba_dc" TO ehisinterface;
GRANT ALL ON DATABASE "tdba_dc" TO es;
GRANT ALL ON DATABASE "tdba_dc" TO fb;
GRANT ALL ON DATABASE "tdba_dc" TO formgen;
GRANT ALL ON DATABASE "tdba_dc" TO hl7;
GRANT ALL ON DATABASE "tdba_dc" TO hr;
GRANT ALL ON DATABASE "tdba_dc" TO lab;
GRANT ALL ON DATABASE "tdba_dc" TO labequip;
GRANT ALL ON DATABASE "tdba_dc" TO lhk;
GRANT ALL ON DATABASE "tdba_dc" TO mis;
GRANT ALL ON DATABASE "tdba_dc" TO mm;
GRANT ALL ON DATABASE "tdba_dc" TO mnm;
GRANT ALL ON DATABASE "tdba_dc" TO ot;
GRANT ALL ON DATABASE "tdba_dc" TO payroll;
GRANT ALL ON DATABASE "tdba_dc" TO pharmacy;
GRANT ALL ON DATABASE "tdba_dc" TO prm;
GRANT ALL ON DATABASE "tdba_dc" TO process;
GRANT ALL ON DATABASE "tdba_dc" TO radiology;
GRANT ALL ON DATABASE "tdba_dc" TO registration;
GRANT ALL ON DATABASE "tdba_dc" TO security;
GRANT ALL ON DATABASE "tdba_dc" TO timecard;
GRANT ALL ON DATABASE "tdba_dc" TO wards;
####################################################
CREATE DATABASE "tdba_lc"
WITH OWNER = crm
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'English_United States.1252'
LC_CTYPE = 'English_United States.1252'
CONNECTION LIMIT = -1;
GRANT ALL ON DATABASE "tdba_lc" TO public;
GRANT ALL ON DATABASE "tdba_lc" TO crm;
GRANT ALL ON DATABASE "tdba_lc" TO adt;
GRANT ALL ON DATABASE "tdba_lc" TO ahc;
GRANT ALL ON DATABASE "tdba_lc" TO amb;
GRANT ALL ON DATABASE "tdba_lc" TO bb;
GRANT ALL ON DATABASE "tdba_lc" TO billing;
GRANT ALL ON DATABASE "tdba_lc" TO digital;
GRANT ALL ON DATABASE "tdba_lc" TO ehis;
GRANT ALL ON DATABASE "tdba_lc" TO ehisinterface;
GRANT ALL ON DATABASE "tdba_lc" TO es;
GRANT ALL ON DATABASE "tdba_lc" TO fb;
GRANT ALL ON DATABASE "tdba_lc" TO formgen;
GRANT ALL ON DATABASE "tdba_lc" TO hl7;
GRANT ALL ON DATABASE "tdba_lc" TO hr;
GRANT ALL ON DATABASE "tdba_lc" TO lab;
GRANT ALL ON DATABASE "tdba_lc" TO labequip;
GRANT ALL ON DATABASE "tdba_lc" TO lhk;
GRANT ALL ON DATABASE "tdba_lc" TO mis;
GRANT ALL ON DATABASE "tdba_lc" TO mm;
GRANT ALL ON DATABASE "tdba_lc" TO mnm;
GRANT ALL ON DATABASE "tdba_lc" TO ot;
GRANT ALL ON DATABASE "tdba_lc" TO payroll;
GRANT ALL ON DATABASE "tdba_lc" TO pharmacy;
GRANT ALL ON DATABASE "tdba_lc" TO prm;
GRANT ALL ON DATABASE "tdba_lc" TO process;
GRANT ALL ON DATABASE "tdba_lc" TO radiology;
GRANT ALL ON DATABASE "tdba_lc" TO registration;
GRANT ALL ON DATABASE "tdba_lc" TO security;
GRANT ALL ON DATABASE "tdba_lc" TO timecard;
GRANT ALL ON DATABASE "tdba_lc" TO wards;
Step 4. restore the database backup by following psql utility :
psql -U enterprisedb -d "tdba_dc" -f "D:\InCampusDB\HealthCraft_DC_daily_5.sql"
psql -U enterprisedb -d "tdba_lc" -f "D:\InCampusDB\HealthCraft_LC_daily_5.sql"