PostgreSQL Hot Standby的搭建
一、 简介:
二、系统环境
- master库操作
- 创建流复制用户repuser
CREATE USER repuser replication LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD 'li0924';# replication 做流复制的时候用到的一个用户属性,一般单独设定。# LOGIN 用户登录的属性;CREATE USER默认自带;所以LOGIN关键字可以略去。
wal_level = hot_standbymax_wal_senders = 1wal_keep_segments = 32# max_wal_senders 是slave库的节点数,有多少个slave库就设多少,# wal_keep_segments 默认值是16,是PG_XLOG下的日志文件数相关参数
host replication repuser 192.168.1.201/16 md5# 第二项必须填 replication;
4.重新启动主数据库,让配置生效:
pg_stop;pg_start
这个步骤就是一个数据库克隆的工作。
- slave库操作
1.在slave数据库的/data/pgdata/postgresql.conf文件中设置如下配置项:
hot_standby = on
2.在PGDATA目录下;也就这里的/data/pgdata;新建文件recovery.conf
standby_mode = 'on'primary_conninfo = 'host=192.168.1.202 port=5432 user=repuser password=li0924'trigger_file = '/data/pgdata/trigger_standby'
3.删除原先从master库上过来的/data/pgdata/postmaster.pid文件,
rm /data/pgdata/postmaster.pid
4.根据master库中的环境变量文件;修改slave库的postgres用户的环境变量 然后启动备库:
pg_start
四、验证工作
- 查看进程
master库
[postgres@sdserver40_210 ~]$ ps -ef | grep postgreroot 2021 556 0 15:18 pts/1 00:00:00 su - postgrespostgres 2022 2021 0 15:18 pts/1 00:00:00 -bashpostgres 2239 1 0 15:24 pts/1 00:00:00 /opt/pgsql95/bin/postgrespostgres 2249 2239 0 15:24 ? 00:00:00 postgres: checkpointer processpostgres 2250 2239 0 15:24 ? 00:00:00 postgres: writer processpostgres 2251 2239 0 15:24 ? 00:00:00 postgres: wal writer processpostgres 2252 2239 0 15:24 ? 00:00:00 postgres: autovacuum launcher processpostgres 2253 2239 0 15:24 ? 00:00:00 postgres: archiver process last was 00000006000000000000001E.00000028.backuppostgres 2254 2239 0 15:24 ? 00:00:00 postgres: stats collector processpostgres 3235 2239 0 15:54 ? 00:00:00 postgres: wal sender process repuser 183.60.192.229(40399) streaming 0/1F000D80
slave库
[postgres@sdserver40_222 pgdata]$ ps -ef | grep postgrespostgres 6856 1 0 15:54 pts/0 00:00:00 /opt/pgsql/bin/postgrespostgres 6863 6856 0 15:54 ? 00:00:00 postgres: startup process recovering 00000006000000000000001Fpostgres 6864 6856 0 15:54 ? 00:00:00 postgres: checkpointer processpostgres 6865 6856 0 15:54 ? 00:00:00 postgres: writer processpostgres 6866 6856 0 15:54 ? 00:00:00 postgres: wal receiver process streaming 0/1F000CA0postgres 6867 6856 0 15:54 ? 00:00:00 postgres: stats collector processroot 6922 30527 0 16:08 pts/0 00:00:00 su - postgrespostgres 6923 6922 0 16:08 pts/0 00:00:00 -bashpostgres 6974 6923 0 16:49 pts/0 00:00:00 ps -efpostgres 6975 6923 0 16:49 pts/0 00:00:00 grep postgres
- 数据验证
在master库操作
[postgres@sdserver40_210 ~]$ psql mydb repuserpsql (9.5.0)Type "help" for help.mydb=> \dList of relationsSchema | Name | Type | Owner--------+-------+---------------+----------public | dept | table | lottupublic | emp | foreign table | postgrespublic | test | table | lottupublic | trade | table | lottu(4 rows)mydb=> create table t_lottu (id int primary key,name varchar(20));CREATE TABLEmydb=> \dList of relationsSchema | Name | Type | Owner--------+---------+---------------+----------public | dept | table | lottupublic | emp | foreign table | postgrespublic | t_lottu | table | repuserpublic | test | table | lottupublic | trade | table | lottu(5 rows)mydb=> insert into t_lottu values (1001,'lottu');INSERT 0 1mydb=> insert into t_lottu values (1002,'vincent');INSERT 0 1mydb=> insert into t_lottu values (1003,'rax');INSERT 0 1mydb=> select * from t_lottu;id | name------+---------1001 | lottu1002 | vincent1003 | rax(3 rows)
登录slave库查看数据
[postgres@sdserver40_222 pgdata]$ psql mydb repuserpsql (9.5.0)Type "help" for help.mydb=> select * from t_lottu;id | name------+---------1001 | lottu1002 | vincent1003 | rax(3 rows)mydb=> delete from t_lottu where id = 1003;
ERROR: cannot execute DELETE in a read-only transaction
参考博客 --http://my.oschina.net/Kenyon/blog/54967
PostgreSQL Hot Standby的搭建的更多相关文章
- postgresql数据库异步流复制hot standby环境搭建
生命不息,test不止. 最近组里面修改了几个postgresql的bug,要进行回归测试,除了前面提到的WAL的RT测试和Mirroring Controller的RT测试,还要测试下postgre ...
- PostgreSQL Hot Standby的主备切换
一. 简介: PG在9.*版本后热备提供了新的一个功能,那就是Stream Replication的读写分离,是PG高可用性的一个典型应用.其中备库是只读库:若主库出现故障:备库这个 ...
- Postgresql监控pgwatch的搭建
一,需要环境: You will need a handful of components to make this work: - Apache (webserver) #apache搭建web页面 ...
- Logical standby database 搭建(配置)
说明 Logical standby 数据库是通过Physical standby数据库转换的.本Logical standby是通过之前创建的Physical standby转换的. Physica ...
- postgresql 10.5 主从复制--搭建测试
env: role master slave host pg1 pg2 ip 11 12 pg-version 10.5 10.5 1 初始化查看 [ceiec@localhost ~]$ df -h ...
- postgresql集群的搭建
目录 架构图 部署详情 postgresql的安装与配置 pgpool的安装与配置 写在安装前 postgresql是一款很强大的数据库,具体有多强大呢,请谷歌... 网上的相关资料不是很多,参考了大 ...
- ORACLE Physical Standby DG搭建
主库: 一:强制force logging: alter database force logging; 二:开启主库的归档模式 三:主库添加standby redo log,比redo日志组多一组: ...
- Nginx+PostgreSQL+Django+UWSGI搭建
最近因为项目上的需要开始大量使用nginx,因此也想趁机将以前常用的django+apache的架构换成django+nginx.常见的 django webapp 部署方式采用FCGI 或 WSGI ...
- postgreSQL 时间线
“时间线”(Timeline)是PG一个很有特色的概念,在备份恢复方面的文档里面时有出现.但针对这个概念的详细解释却很少,也让人不太好理解,我们在此仔细解析一下. 时间线的引入 为了理解引入时间线的背 ...
随机推荐
- First learning operation system
1,操作系统负责管理硬件资源,为应用程序的开发执行提供基础 2,用户空间包括应用程序,只能通过调用系统调用访问硬件,无法访问更小粒度功能 3,设备驱动程序函数和内核子系统的函数对用户不可见 4,操作系 ...
- Java基础之创建窗口——使用BoxLayout管理器(TryBoxLayout4)
控制台程序. javax.swing.BoxLayout类定义的布局管理器在单行或单列中布局组件.创建BoxLayout对象时,需要指定是在行还是列中布局组件. 对于行,组件是从左到右地添加:对于列, ...
- mongodb的连接和开启安全验证
首先是启动mongodb a.打开cmd,cd进入mongodb的安装目录下的bin目录下面,执行 mongod --dbpath D:\MongoDBdata(数据存放的目录) 或者将mongodb ...
- GTA项目 三, 使用 bootstrap table展示界面,使得data和UI分离
/** bootstrap-table - v1.5.0 - 2014-12-12* https://github.com/wenzhixin/bootstrap-table* Copyright ( ...
- leetcode-5 最长回文子串(动态规划)
题目要求: * 给定字符串,求解最长回文子串 * 字符串最长为1000 * 存在独一无二的最长回文字符串 求解思路: * 回文字符串的子串也是回文,比如P[i,j](表示以i开始以j结束的子串)是回文 ...
- Error : L6218E: Undefined symbol downloadAddress (referred from nand.o).
MKD 报错: linking...LCD.axf: Error: L6218E: Undefined symbol EnZK (referred from ht128x64.o).LCD.axf: ...
- JavaScript----marquee滚动标签 图片无缝滚动 插入百度地图
页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...
- android测试(转)
1.冒烟测试 跟web端的测试流程一样,你拿到一个你们开发做出来的apk首先得去冒烟,也就是保证他的稳定性,指定时间内不会崩溃.这款原生sdk自带的monkey可以当做我们的测试工具.就跟我之前博客所 ...
- 解决Android抽屉被击穿问题
1,创建一个抽屉DrawerLayout,在V4包下android.support.v4.widget.DrawerLayout,在要设置抽屉的布局中设置android:layout_gravity= ...
- java多线程实现卖票小程序
package shb.java.demo; /** * 多线程测试卖票小程序. * @Package:shb.java.demo * @Description: * @author shaobn * ...