PPAS上运行pg_dump经过

目前我有两台机器,

分别已经安装了PPAS9.1,安装后建立了OS系统用户enterprisedb和数据库用户enterprisedb。

机器1:master  192.168.10.88

机器2: slave 192.168.10.99

为了可以在机器1和机器2之间方便进行访问,设置pg_hba.conf如下:

机器1和机器2都如此设置:

[root@master ~]# su - enterprisedb
-bash-3.2$ pwd
/opt/PostgresPlus/9.1AS
-bash-3.2$ cd data
-bash-3.2$ cat pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================.

......


# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local   all             all                                     md5
local    all             all                                    trust
# IPv4 local connections:
#host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               trust
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     enterprisedb                                md5
#host    replication     enterprisedb        127.0.0.1/32            md5
#host    replication     enterprisedb        ::1/128                 md5
-bash-3.2$ 

然后分别建立数据库:

机器1:

[root@master ~]# su - enterprisedb
-bash-3.2$ pwd
/opt/PostgresPlus/9.1AS
-bash-3.2$ cd bin
-bash-3.2$ ./createdb -d masterdb --owner=enterprisedb

机器2:

[root@slave ~]# su - enterprisedb
-bash-3.2$ pwd
/opt/PostgresPlus/9.1AS
-bash-3.2$ cd bin
-bash-3.2$ ./createdb -d slavedb --owner=enterprisedb

然后,在机器1上准备数据:

[root@master ~]# su - enterprisedb
-bash-3.2$ cd bin
-bash-3.2$ ./psql -d masterdb
psql (9.1.2.2)
Type "help" for help.

masterdb=# begin;
BEGIN
masterdb=# create table tab01(id integer);
CREATE TABLE
masterdb=# insert into tab01 values(1);
INSERT 0 1
masterdb=# create table tab02(id integer);
CREATE TABLE
masterdb=# insert into tab02 values(2);
INSERT 0 1
masterdb=# end;
COMMIT
masterdb=# \q

然后再在机器1上,建立一个执行中的事务,不提交:

-bash-3.2$ ./psql -d masterdb
psql (9.1.2.2)
Type "help" for help.

masterdb=# begin;
BEGIN
masterdb=# create table tab03(id integer);
CREATE TABLE
masterdb=# insert into tab03 values(3);
INSERT 0 1
masterdb=# 

然后开始pg_dump 动作:

我从机器2上发起命令:在此把pg_dump的输出,重定向到psql,直接完成restore的任务:

[root@slave ~]# su - enterprisedb
-bash-3.2$ cd bin
-bash-3.2$ ./pg_dump -h 192.168.10.88 -s masterdb | ./psql -h 192.168.10.99 slavedb
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
CREATE EXTENSION
COMMENT
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
REVOKE
REVOKE
GRANT
GRANT
-bash-3.2$ 

在机器2上检验效果:

-bash-3.2$ ./psql -d slavedb
psql (9.1.2.2)
Type "help" for help.

slavedb=# \dt
                     List of relations
 Schema |           Name            | Type  |    Owner     
--------+---------------------------+-------+--------------
 public | tab01                     | table | enterprisedb
 public | tab02                     | table | enterprisedb
 sys    | dual                      | table | enterprisedb
 sys    | edb$session_wait_history  | table | enterprisedb
 sys    | edb$session_waits         | table | enterprisedb
 sys    | edb$snap                  | table | enterprisedb
 sys    | edb$stat_all_indexes      | table | enterprisedb
 sys    | edb$stat_all_tables       | table | enterprisedb
 sys    | edb$stat_database         | table | enterprisedb
 sys    | edb$statio_all_indexes    | table | enterprisedb
 sys    | edb$statio_all_tables     | table | enterprisedb
 sys    | edb$system_waits          | table | enterprisedb
 sys    | plsql_profiler_rawdata    | table | enterprisedb
 sys    | plsql_profiler_runs       | table | enterprisedb
 sys    | plsql_profiler_units      | table | enterprisedb
 sys    | product_component_version | table | enterprisedb
(16 rows)

slavedb=# select * from tab01;
 id 
----
(0 rows)

slavedb=# select * from tab02;
 id 
----
(0 rows)

slavedb=# 

 

posted @ 2013-07-17 10:55  健哥的数据花园  阅读(787)  评论(0编辑  收藏  举报