Postgresql9 PPAS9流複製配置,postgresql9ppas9

來源:互聯網
上載者:User

Postgresql9 PPAS9流複製配置,postgresql9ppas9

PostgreSQL流複製叢集搭建,這個是翻的陳年舊檔


主機:

PPAS1 PPAS2

1
安裝PPAS 9.0
[root@ppas1 ~]# setenforce 0
[root@ppas1 ~]# ppasmeta-9.0.4.14-linux-x64.run--全部安裝

[root@ppas1 ~]# vim /etc/bashrc
加入:
PATH=$PATH:/opt/PostgresPlus/9.0AS/binexport PATH
--Logout 並重新登陸系統
安裝PPAS 9.0
[root@ppas2 ~]# setenforce 0
[root@ppas2 ~]# ppasmeta-9.0.4.14-linux-x64.run--全部安裝
[root@ppas2 ~]# vim /etc/bashrc
加入:
PATH=$PATH:/opt/PostgresPlus/9.0AS/binexport PATH
--Logout 並重新登陸系統
2
建立archive 目錄
[root@ppas1 ~]# mkdir /opt/ppas_arch
[root@ppas1 ~]# chown enterprisedb.enterprisedb /opt/ppas_arch
建立archive 目錄
[root@ppas2 ~]# mkdir /opt/ppas_arch
[root@ppas2 ~]# chown enterprisedb.enterprisedb /opt/ppas_arch
3
[root@ppas1 ~]# mkdir /opt/PostgresPlus/9.0/.ssh
[root@ppas1 ~]# chown enterprisedb.enterprisedb /opt/PostgresPlus/9.0/.ssh/
[root@ppas1 ~]# ssh root@192.168.122.12 "mkdir .ssh"
[root@ppas1 ~]# su -enterprisedbbash-4.1$ ssh-keygen -t rsabash-4.1$ scp ~/.ssh/id_rsa.pub root@192.168.122.12:.ssh/
id_rsa_ppas1.pub
4
[root@ppas2 ~]# touch /root/.ssh/authorized_keys[root@ppas2 ~]# cat /root/.ssh/id_rsa_ppas1.pub >> /root/.ssh/
authorized_keys
5
bash-4.1$ ssh root@192.168.122.12Last login: Mon Jun 27 22:27:09 2011 from 192.168.122.2
[root@ppas1 ~]# logoutConnection to 192.168.122.12 closed.
bash-4.1$ logout[root@ppas1 ~]#
6
[root@ppas2 ~]# mkdir /opt/PostgresPlus/9.0/.ssh[root@ppas2 ~]# chown enterprisedb.enterprisedb /opt/PostgresPlus/9.0/.ssh/
[root@ppas2 ~]# ssh root@192.168.122.11 "mkdir .ssh"
[root@ppas2 ~]# su -enterprisedbbash-4.1$ ssh-keygen -t rsabash-4.1$ scp ~/.ssh/id_rsa.pub root@192.168.122.11:.ssh/
id_rsa_ppas2.pub
7
[root@ppas1 ~]# touch /root/.ssh/authorized_keys[root@ppas1 ~]# cat /root/.ssh/id_rsa_ppas2.pub >> /root/.ssh/
authorized_keys
8
bash-4.1$ ssh root@192.168.122.11Last login: Mon Jun 27 22:31:14 2011 from 192.168.122.1[root@ppas1 ~]# logoutConnection to 192.168.122.11 closed.
bash-4.1$ logout[root@ppas2 ~]#
9
配置PPAS的Stream Replication
[root@ppas1 ~]# vim /opt/PostgresPlus/9.0AS/data/postgresql.conf
wal_level = hot_standby
archive_mode = on
archive_command = 'cp -i %p /opt/ppas_arch/%f < /dev/null'
max_wal_senders = 1
hot_standby = on
log_statement = 'all' #只用於測試
[root@ppas1 ~]# echo "host replication enterprisedb192.168.122.11/32 trust" >> /opt/PostgresPlus/9.0AS/data/pg_hba.conf[root@ppas1 ~]# echo "host replication enterprisedb192.168.122.12/32 trust" >> /opt/PostgresPlus/9.0AS/data/pg_hba.conf[root@ppas1 ~]# echo "host all all 192.168.122.11/32 trust" >> /opt/PostgresPlus/9.0AS/data/pg_hba.conf
[root@ppas1 ~]# echo "host all all 192.168.122.12/32 trust" >> /opt/PostgresPlus/9.0AS/data/pg_hba.conf
10
[root@ppas2 ~]# /etc/init.d/ppas-9.0 stop
11
將PPAS1的資料全備到PPAS2
[root@ppas1 ~]# edb-psql -U enterprisedb edb -c "SELECTpg_start_backup('label',true);"
[root@ppas1 ~]# rsync -a /opt/PostgresPlus/9.0AS/data/
root@192.168.122.12:/opt/PostgresPlus/9.0AS/data/ --excludepostmaster.pid
[root@ppas1 ~]# edb-psql -U enterprisedb edb -c "SELECTpg_stop_backup();
12
[root@ppas2 ~]# vim /opt/PostgresPlus/9.0AS/data/recovery.confstandby_mode = 'on'
primary_conninfo = 'host=192.168.122.11 port=5444
user=enterprisedb'trigger_file = '/opt/PostgresPlus/9.0AS/data/recovery_trigger'restore_command = 'scp -Cp root@192.168.122.11:/opt/ppas_arch/%f"%p"'
[root@ppas2 ~]# chown enterprisedb.enterprisedb /opt/PostgresPlus/
9.0AS/data/recovery.conf[root@ppas2 ~]# /etc/init.d/ppas-9.0 start
13

兩台伺服器的Stream Replication 已經完成

############################

下面的留著當備忘

14
[root@ppas1 ~]# mkdir /var/run/pgpool
15
[root@ppas1 ~]# cp /opt/PostgresPlus/9.0AS/etc/pgpool.conf.samplestream /opt/PostgresPlus/9.0AS/etc/pgpool.conf
[root@ppas1 ~]# vim /opt/PostgresPlus/9.0AS/etc/pgpool.conf
修改:
backend_hostname0 = '192.168.122.11'
backend_port0 = 5444
backend_weight0 = 1
backend_data_directory0 = '/opt/PostgresPlus/9.0AS/data'
backend_hostname1 = '192.168.122.12'
backend_port1 = 5444
backend_weight1 = 1
backend_data_directory1 = '/opt/PostgresPlus/9.0AS/data'
16
[root@ppas1 ~]# edb-psql -U enterprisedb edb -c "select md5('1q2w3e4r');"
md5
---------------------------------
5416d7cd6ef195a0f7622a9c56b55e84
(1 row)
[root@ppas1 ~]# echo "enterprisedb:5416d7cd6ef195a0f7622a9c56b55e84" >> /opt/PostgresPlus/9.0AS/etc/pcp.conf
17
啟動PGPool
[root@ppas1 ~]# /opt/PostgresPlus/9.0AS/bin/pgpool -f /opt/PostgresPlus/9.0AS/etc/pgpool.conf -F /opt/PostgresPlus/9.0AS/etc/
pcp.conf
[root@ppas1 ~]# netstat -natulp | grep 9999
tcp 0 0 127.0.0.1:9999 0.0.0.0:* LISTEN 2434/pgpool
[root@ppas1 ~]#

18
[root@ppas1 ~]# edb-psql -p 9999 -U enterprisedb edbedb-psql (9.0.4.10)
Type "help" for help.
edb=# create table a (id int);
CREATE TABLE
edb=# insert into a values (5),(6);
INSERT 0 2
edb=# select * from a;
id
---
5
6
(2 rows)

19
[root@ppas1 ~]# /etc/init.d/ppas-9.0 stopStopping Postgres Plus Advanced Server 9.0:
waiting for server to shut down....... doneserver stopped

20
[root@ppas2 ~]# edb-psql -h 192.168.122.11 -p 9999 -U enterprisedbedb
edb-psql: server closed the connection unexpectedlyThis probably means the server terminated abnormallybefore or while processing the request.
以上串連出錯是由於pgpool 正好此時的路由指向到PPAS1,但此時PPAS1的資料庫已經STOP 。
[root@ppas2 ~]# edb-psql -h 192.168.122.11 -p 9999 -U enterprisedbedb
edb-psql (9.0.4.10)
Type "help" for help.
edb=#
重新再串連一次,此時pgpool 會將串連轉向PPAS2,同時在pgpool 內部會將PPAS1定為故障狀態,直到PPAS1的資料庫重新可用。

21
edb=# insert into a values (7);
ERROR: cannot execute INSERT in a read-only transaction
由於PPAS2還在Stream Replication 的Slave 狀態,因此不可做寫資料操作
edb=# \q
22
[root@ppas2 ~]# touch /opt/PostgresPlus/9.0AS/data/recovery_trigger
[root@ppas2 ~]# edb-psql -h 192.168.122.11 -p 9999 -U enterprisedbedb
edb-psql (9.0.4.10)
Type "help" for help.
edb=# insert into a values (7);
ERROR: cannot execute INSERT in a read-only transaction
此處操作太快了,因此系統還沒有改為Master 狀態
edb=# insert into a values (7);
INSERT 0 1
再過1-2 秒進行操作,寫入成功
edb=#




-----------------

轉載請著明出處:
blog.csdn.net/beiigang



postgreSQL921 安裝後需要配置?

可以調優一下 postgresql.conf 裡的設定,比如共用記憶體大小、checkpoint segment 等等。
 
postgresql資料庫中怎複製表結構與完全複製表,如oracle中create table a as select * from b

Oracle 的例子
SQL> SELECT 2 * 3 FROM 4 test_main; ID VALUE---------- ---------- 1 ONE 2 TWOSQL> CREATE TABLE test_t AS SELECT * FROM test_main;表已建立。SQL> select * FROM test_t; ID VALUE---------- ---------- 1 ONE 2 TWO
postgresql 的例子
Test=# CREATE TABLE test_t AS (SELECT * FROM test_main) ;SELECT 2Test=# select * from test_t; id | value----+------- 1 | ONE 2 | TWO(2 行記錄)我不知道是不是 Postgresql 那裡要加個括弧啊, 哈哈。

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.