- You can use pg_dump tool (see pg_dump doc ) and pg_restore (pg_restore doc)
- You do not need to create new database name "A" on new server .
*Basic example :
I create "dump.bat" & "restore.bat" files in window to dump/restore
1/ Backup:
"C:\Program Files\PostgreSQL\9.1\bin\pg_dump.exe" --host localhost --port 5432 --username "postgres" --role "postgres" --format plain --encoding UTF8 --schema-only --file "dump_resul.sql" --schema "name_schema_B" "name_database_A"
Results:
-- PostgreSQL database dump
-- Dumped from database version 9.1.4
-- Dumped by pg_dump version 9.1.4
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
CREATE TABLE abtb_temp (
id bigint NOT NULL,
app_code character varying(100)
); ....
*Note: some important options: --data-only, --format=format (ex: format=tar -> if you have a big database), --schema-only, --table=table (ex: --table=schema_name.table_name) ...
2/ Restore:
"C:\Program Files\PostgreSQL\9.1\bin\pg_restore.exe" --host localhost --port 5432 --username "postgres" --dbname "any_database" --no-password --no-owner --no-privileges --schema name_schema_B --verbose "C:\dump_resul.sql" (**)
(**) In reality, if your format file is *.sql, you can use pgAdmin (or psql) to restore . You should use pg_restore to restore a file .tar (.bakup ...)