主备查询

主备不会自动切换(即需要实现线上环境主数据库宕掉之后,从数据库能够自动切换为主数据库,需要借用第三方软件,例如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主备切换的更多相关文章

  1. 在Azure云上实现postgres主备切换

    以下是工作上实现postgres主备切换功能所用到的代码和步骤,中间走了不少弯路,在此记录下.所用到的操作系统为centos 7.5,安装了两台服务器,hostname为VM7的为Master,VM8 ...

  2. Spark系列(五)Master主备切换机制

    Spark Master主备切换主要有两种机制,之中是基于文件系统,一种是基于Zookeeper.基于文件系统的主备切换机制需要在Active Master挂掉后手动切换到Standby Master ...

  3. Nginx+Keepalived主备切换(包含nginx服务停止)

    原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...

  4. 在Windows Azure上配置VM主备切换(1)——Linux篇

    对任何一个上线系统来说,高可用设计是不可或缺的一个环节,这样才可以确保应用可以持续.稳定的运行,而不是频繁的掉线.停机.高可用设计的核心思路很简单,就是消除一切单点故障,将单点链路或者节点升级为多点. ...

  5. (摘)DataGuard物理standby管理 - 主备切换

    DataGuard物理standby管理 - 主备切换 Dataguard的切换分为两种,switchover和failover. switchover一般用于数据库或硬件升级,这时只需要较短时间中断 ...

  6. 测试redis+keepalived实现简单的主备切换【转载】

    转自: 测试redis+keepalived实现简单的主备切换 - Try My Best 尽力而为 - ITeye技术网站http://raising.iteye.com/blog/2311757 ...

  7. Redis安装,主从,主备切换

    网络环境: 主:10.187.120.5 从:10.187.69.58 从:10.187.69.59 一.安装 mv redis-2.8.19.tar.gz /export/servers/ cd / ...

  8. MySQL 复制 - 性能与扩展性的基石 4:主备切换

    一旦使用 MySQL 的复制功能,就很大可能会碰到主备切换的情况.也许是为了迭代升级服务器,或者是主库出现问题时,将一台备库转换成主库,或者只是希望重新分配容量.不过出于什么原因,都需要将新主库的信息 ...

  9. Oracle 11.2.0.4.0 Dataguard部署和日常维护(5)-Datauard 主备切换和故障转移篇

    1. dataguard主备切换   1.1. 查看当前主备库是否具备切换条件 on slave select sequence#,first_time,next_time,archived,appl ...

随机推荐

  1. 2602 最短路径问题Dihstra算法

    题目描述 Description 平面上有n个点(n<=100),每个点的坐标均在-10000~10000之间.其中的一些点之间有连线.若有连线,则表示可从一个点到达另一个点,即两点间有通路,通 ...

  2. table表格td内内容自动换行

    项目开发时,遇到问题:td内传入数据,全是字母,不会自动换行 一般字母数字/特殊符号的话,会被浏览器默认是一个字符串或者说一个单词,不会自动换行 所以需要设置一下,让表格内容自动换行. 1.给td标签 ...

  3. 工作中遇到的vscode配合eslint完成保存为eslint格式

    vscode个人设置 // vscode的个人设置配置 { "workbench.iconTheme": "vscode-icons", "workb ...

  4. c++ 处理utf-8字符串

    c++的字符串中的每一个元素都是一个字节.所以在装入utf8字符串的时候,其实是按照一定的规则编码的. 字符的8位中 如果0开头 则自己就是一个单位. 1字节 0xxxxxxx  2字节 110xxx ...

  5. Thymeleaf基础知识

    Thymeleaf是一个Java类库,它是一个xml/xhtml/html5的模板引擎,可以作为MVC的Web引用的View层. Thymeleaf还提供了额外的模块与SpringMVC集成,因此推荐 ...

  6. strdup和strndup函数

    首先说明一下:这两个函数不建议使用,原因是返回内存地址把释放权交给别的变量,容易忘记释放. 一.strdup函数 函数原型 头文件:#include <string.h> char *st ...

  7. centos6.5_64bit-Tomcat7安装部署

    此次安装系统版本及软件版本 centos6.5-64bit java -1.7.0_45 jdk1.8.0_111 apache-tomcat-7.0.73   一.检查java版本信息        ...

  8. MySQL入门很简单: 7 触发器

    触发器是由事件来触发某个操作,这些事件包括INSERT语句,UPDATE语句和DELETE语句 1.创建触发器 1)创建只有一个执行语句的触发器 例子:再向department表中执行INSERT操作 ...

  9. 初学React:定义一个组件

    接着聊React,今天说说如何创建一个组件类. <!DOCTYPE html> <html lang="en"> <head> <meta ...

  10. 如何处理Eclipse错误消息 The declared package does not match the expected package

    我从github下载了一个开源项目后,导入到自己Eclipse之后,遇到了这个烦人的错误消息: The declared package "com.sap.smartService" ...