postgresql在windows7环境下的热备hot standby
环境: Step1:安装PG数据库 Step2:创建流复制用户 master端执行: CREATE USER repuserreplication LOGIN CONNECTION LIMIT3ENCRYPTED PASSWORD 'repuser'; Step3:配置Master端的访问文件pg_hba.conf 增加一行: Step4:配置MASTER端配置文件 max_wal_senders = 1 archive_mode = on 注:max_wal_senders是Slave库的节点数,有多少个slave库就设多少, 5.2:拷贝C:Program FilesPostgreSQL9.5data文件夹,并复制到Slave服务器上 备机端如果已经安装了postgres数据库,数据文件夹名称一样的话,可以先停掉备机数据库,将data文件夹中内容清空。将master中data文件夹中内容拷贝到slave中相同文件夹下。 select pg_stop_backup(),current_timestamp;
6.1:postgresql.conf文件 6.2:recovery.conf文件 将C:ProgramFilesPostgreSQL9.5sharerecovery.conf.sample文件拷贝到data文件夹下,重命名为recovery.conf 新增以下内容: standby_mode = 'on' primary_conninfo ='host=192.16.41.114 port=5432 user=repuser password=repuserkeepalives_idle=60' 6.3:配置.pgpass文件(slave端) 6.4:删除slave端(从master端拷过来的)的postmaster.pid文件和pg_xlog文件夹中内容。 Step8:测试 On Master: ( id integer NOTNULL, name charactervarying(20), CONSTRAINTt_pkey PRIMARY KEY (id) ) INSERT INTO t(id,name)VALUES (1,'xxxxxxxxx'); INSERT INTO t(id,name)VALUES (2,'xxxxxxxxx'); select * from t; update t set name = 'YYYYY' where id=1; delete from t where id = 2; ERROR: cannot execute UPDATE in a read-onlytransaction ERROR: cannot execute DELETE in a read-onlytransaction
遇到的问题: 备份完成后,slave库的服务无法启动: 操作:将备份库的data文件夹改为data.old,将master中的data文件夹拷贝到slave中,启动服务。 报错:服务无法启动,报服务启动后终止。 日志:pg中的log文件内容为空 查看事件管理器中日志:2016-04-25 16:47:38 HKT 致命错误: 无法创建锁文件"postmaster.pid": Permission denied 解决方法: 1.修改新拷贝过来的data文件夹权限,修改后并不起作用。
2.保留slave的data文件夹,将其中内容清空,把master中的data文件夹中内容拷贝到slave中。启动服务,成功。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |