Postgres主备切换
主备查询
主备不会自动切换(即需要实现线上环境主数据库宕掉之后,从数据库能够自动切换为主数据库,需要借用第三方软件,例如heartbeat等)
(1)如何查看是primary还是standby
- 方法1:查看进程
主机 sender
[wln@localhost data]$ ps -ef | grep wal
wln 10421 10416 0 07:52 ? 00:00:00 postgres: wal writer process
wln 10691 10416 0 08:04 ? 00:00:00 postgres: wal sender process repluser 127.0.0.1(59226) streaming 0/6011BAC
wln 10702 8927 0 08:05 pts/2 00:00:00 grep wal
备机 receiver
[wln@localhost data]$ ps -ef | grep wal
wln 10421 10416 0 07:52 ? 00:00:00 postgres: wal writer process
wln 10690 10685 3 08:04 ? 00:00:03 postgres: wal receiver process streaming 0/6011BAC
wln 10702 8927 0 08:05 pts/2 00:00:00 grep wal
- 方法2:
主机:
[wln@localhost data]$ pg_controldata | grep Database
Database system identifier: 6032728846531166188
Database cluster state: in production
Database block size: 8192
备机:
[wln@localhost standby]$ pg_controldata | grep Database
Database system identifier: 6032728846531166188
Database cluster state: in archive recovery
Database block size: 8192
主备切换(方式1)
(1)备机切换为主机
- 将主机停掉
[wln@localhost data]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
- 在备机PGDATA对应目录下生成recovery.conf文件中指定的文件trigger_file = '/pgdata/9.1/data2/trigger_activestb' (此时备机正常运行状态)
touch /pgdata/9.1/data2/trigger_activestb
会看到 recovery.conf 文件变为 recovery.done
- 查看原来备机日志:
LOG: trigger file found: /home/wln/standby/trigger_activestb
LOG: redo done at 0/6011C40
LOG: last completed transaction was at log time 2014-07-06 08:05:40.152147+08
LOG: selected new timeline ID: 2
LOG: archive recovery complete
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
- 登录原来的备机
[postgres@postgres ~]$ psql
psql (9.1.0)
Type "help" for help.
You are now connected to database "postgres" as user "postgres".
postgres=# SHOW transaction_read_only
postgres-# ;
transaction_read_only
-----------------------
off
(1 row)
可以看出现在原备机具有读写功能。即主备切换成功
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+-------
public | t1 | table | wln
(1 row)
postgres=# create table t2(id int);
CREATE TABLE
4、主备切换(方式2:实践过程中采用的方式)
备机中recovery.conf中设置为:
standby_mode = on
recovery_target_timeline = 'latest'
primary_conninfo = 'host=localhost port=5433 user=repluser password=password'
#trigger_file = '/home/wln/standby/trigger_activestb' #这个注释掉
备机升为主机方式为:pg_ctl promote -D standbyPath
会看到recovery.conf过几秒后变为recovery.done 表示升级为主机成功。
Postgres主备切换的更多相关文章
- 在Azure云上实现postgres主备切换
以下是工作上实现postgres主备切换功能所用到的代码和步骤,中间走了不少弯路,在此记录下.所用到的操作系统为centos 7.5,安装了两台服务器,hostname为VM7的为Master,VM8 ...
- Spark系列(五)Master主备切换机制
Spark Master主备切换主要有两种机制,之中是基于文件系统,一种是基于Zookeeper.基于文件系统的主备切换机制需要在Active Master挂掉后手动切换到Standby Master ...
- Nginx+Keepalived主备切换(包含nginx服务停止)
原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...
- 在Windows Azure上配置VM主备切换(1)——Linux篇
对任何一个上线系统来说,高可用设计是不可或缺的一个环节,这样才可以确保应用可以持续.稳定的运行,而不是频繁的掉线.停机.高可用设计的核心思路很简单,就是消除一切单点故障,将单点链路或者节点升级为多点. ...
- (摘)DataGuard物理standby管理 - 主备切换
DataGuard物理standby管理 - 主备切换 Dataguard的切换分为两种,switchover和failover. switchover一般用于数据库或硬件升级,这时只需要较短时间中断 ...
- 测试redis+keepalived实现简单的主备切换【转载】
转自: 测试redis+keepalived实现简单的主备切换 - Try My Best 尽力而为 - ITeye技术网站http://raising.iteye.com/blog/2311757 ...
- Redis安装,主从,主备切换
网络环境: 主:10.187.120.5 从:10.187.69.58 从:10.187.69.59 一.安装 mv redis-2.8.19.tar.gz /export/servers/ cd / ...
- MySQL 复制 - 性能与扩展性的基石 4:主备切换
一旦使用 MySQL 的复制功能,就很大可能会碰到主备切换的情况.也许是为了迭代升级服务器,或者是主库出现问题时,将一台备库转换成主库,或者只是希望重新分配容量.不过出于什么原因,都需要将新主库的信息 ...
- Oracle 11.2.0.4.0 Dataguard部署和日常维护(5)-Datauard 主备切换和故障转移篇
1. dataguard主备切换 1.1. 查看当前主备库是否具备切换条件 on slave select sequence#,first_time,next_time,archived,appl ...
随机推荐
- Python常用模块(二)
一.json与pickle json与pickle模块是为了完成数据的序列化. 序列化是指把对象(变量)从内存中变成可存储或传输的过程,在Python中叫picking,在其他语言中也由其他的叫法,但 ...
- 洛谷 P1195 口袋的天空(最小生成树)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P1195 思路: 首先可以判断这道题是用最小生成树来做的,然后在将其合并时用ans记录一下它的总消耗, ...
- js获取url的参数和值的N种有效方法
js获取url的参数和值的N种有效方法 function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[" ...
- Brackets - 前端神器
做了几年的 .Net 项目开发,后来公司转 Java 语言开发,Java 做了还没一年,公司准备前后端分离开发,而我被分到前端! Brackets是一款基于web(html+css+js)开发的web ...
- Java Knowledge series 7
Pepole who make a greate contribution on common libaraies deserve our respect. Component(Widget) / S ...
- 快速排序c语言实现
#include <stdio.h> void quick_sort(int* a, int n) { ) return; int i,j,tmp,k; k = a[n/]; ,j = n ...
- SqlServer存储过程中常用函数及操作
1.case语句 用于选择语句 SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN ...
- BizMDM企业主数据管理平台
类型: 定制服务 软件包: business intelligence integrated industry solution collateral 联系服务商 产品详情 解决方案 概要 在全新的数 ...
- MySQL报错:Packets larger than max_allowed_packet are not all
MySQL根据配置文件会限制Server接受的数据包大小.有时候大的插入和更新会受 max_allowed_packet 参数限制,导致写入或者更新失败. 修改方法: 1.修改配置文件my.ini m ...
- MySQL入门很简单: 7 触发器
触发器是由事件来触发某个操作,这些事件包括INSERT语句,UPDATE语句和DELETE语句 1.创建触发器 1)创建只有一个执行语句的触发器 例子:再向department表中执行INSERT操作 ...