CentOS7 PostgreSQL 主从配置( 一)
主库配置
pg_hba.conf
host replication all 10.2.0.0/0 trust
postgresql.conf
listen_addresses = '*'
max_wal_senders =
wal_level = hot_standby
wal_keep_segments =
重启主库
从库配置
安装
使用yum安装 (找源 http://yum.postgresql.org/)
yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
yum install postgresql95-server postgresql95-contrib
生成基础备份(主数据库IP 10.2.0.14)
pg_basebackup -h 10.2.0.14 -U postgres -F p -P -x -R -D /var/lib/pgsql/9.5/data/ -l postgresbackup20160506
postgres 不在有参数 -x
说明 pg_log, pg_xlog, pg_clog目录分别重命名为log, pg_wal, pg_xact。
pg_basebackup支持两种全量备份的方式,
1.以fetch的方式,先备份数据在备份日志
2.以stream的方式,并行的备份数据和日志
pg_basebackup对于全量备份的数据和日志,提供了串行备份和并行备份的方式。fetch模式也就是串行备份需要保证在备份数据的过程中,备份开始时刻的日志需要一直保存下来, 也就说pg的wal_keep_segments需要足够大去保存日志文件,如果备份数据期间,日志开始时刻的日志已经被移除,那么备份就会失败。而stream模式,也就是并行备份过程中wal_max_sender必须保证不小于2。 而stream模式不支持,将数据和日志以流的方式输出到标准输出。
查看生成文件(注意文件的权限,用户组)
chown postgres:postgres /var/lib/pgsql/9.5/data/ -R
chmod 700 /var/lib/pgsql/9.5/data/
ls -l /var/lib/pgsql/9.5/data -rw-------. 1 postgres postgres 197 5月 6 13:11 backup_label.old
drwx------. 6 postgres postgres 50 5月 6 13:11 base
drwx------. 2 postgres postgres 4096 5月 6 13:38 global
drwx------. 2 postgres postgres 17 5月 6 13:11 pg_clog
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_commit_ts
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_dynshmem
-rw-------. 1 postgres postgres 4214 5月 6 13:11 pg_hba.conf
-rw-------. 1 postgres postgres 1636 5月 6 13:11 pg_ident.conf
drwx------. 2 postgres postgres 56 5月 6 13:11 pg_log
drwx------. 4 postgres postgres 37 5月 6 13:11 pg_logical
drwx------. 4 postgres postgres 34 5月 6 13:11 pg_multixact
drwx------. 2 postgres postgres 17 5月 6 13:38 pg_notify
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_replslot
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_serial
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_snapshots
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_stat
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_stat_tmp
drwx------. 2 postgres postgres 17 5月 6 13:11 pg_subtrans
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_tblspc
drwx------. 2 postgres postgres 6 5月 6 13:11 pg_twophase
-rw-------. 1 postgres postgres 4 5月 6 13:11 PG_VERSION
drwx------. 3 postgres postgres 89 5月 6 13:29 pg_xlog
-rw-------. 1 postgres postgres 88 5月 6 13:11 postgresql.auto.conf
-rw-------. 1 postgres postgres 21756 5月 6 13:38 postgresql.conf
-rw-------. 1 postgres postgres 59 5月 6 13:38 postmaster.opts
-rw-------. 1 postgres postgres 87 5月 6 13:38 postmaster.pid
-rw-r--r--. 1 postgres postgres 140 5月 6 13:35 recovery.conf
cat recovery.conf
standby_mode = 'on'
primary_conninfo = 'user=postgres host=10.2.0.14 port=5432 sslmode=disable sslcompression=1'
修改 postgresql.conf(否则启动失败 错误:postgresql-9.5.service start operation timed out. Terminating.)
hot_standby=on
启动从库
systemctl start postgresql-9.5.service
systemctl enable postgresql-9.5.service
测试
主库操作从库查看同步结果
psql -U postgres
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF- | en_US.UTF- |
template0 | postgres | UTF8 | en_US.UTF- | en_US.UTF- | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF- | en_US.UTF- | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF- | en_US.UTF- |
( rows) postgres=# \c test
est=# create table test01(id int primary key,note text);
CREATE TABLE
test=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | test01 | table | postgres
( row) test=# insert into test01 values(,'');
INSERT
test=# insert into test01 values(,'');
INSERT
test=# insert into test01 values(,'');
INSERT
test=# insert into test01 values(,'');
INSERT
test=# \q select * from test01;
id | note
----+------
|
|
|
|
主从同步状况查看
主库
select * from pg_stat_replication ;
-[ RECORD ]----+------------------------------
pid |
usesysid |
usename | postgres
application_name | walreceiver
client_addr | 10.2.0.15
client_hostname |
client_port |
backend_start | -- ::49.191165+
backend_xmin |
state | streaming
sent_lsn | /BA000140
write_lsn | /BA000140
flush_lsn | /BA000140
replay_lsn | /BA000140
write_lag |
flush_lag |
replay_lag |
sync_priority |
sync_state | async
从库 select * from pg_stat_wal_receiver ;
-[ RECORD ]---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pid |
status | streaming
receive_start_lsn | /BA000000
receive_start_tli |
received_lsn | /BA000140
received_tli |
last_msg_send_time | -- ::19.692318+
last_msg_receipt_time | -- ::19.724085+
latest_end_lsn | /BA000140
latest_end_time | -- ::49.194596+
slot_name |
conninfo | user=postgres passfile=/root/.pgpass dbname=replication host=10.2.0.14 port= fallback_application_name=walreceiver sslmode=prefer sslcompression= krbsrvname=postgres target_session_attrs=any
CentOS7 PostgreSQL 主从配置( 一)的更多相关文章
- CentOS7 PostgreSQL 主从配置( 二)
同步流复制配置PostgreSql的流复制是异步的,缺点是Standby上的数据落后于主库上的数据,如果使用Hot Standby做读写分离,就会存在数据一致性的问题.PostgreSql9.1版本后 ...
- CentOS7 PostgreSQL 主从配置( 三)
postgres 主备切换 主备查看 方法 ps -ef | grep wal (主库 sender)postgres 27873 27864 0 5月06 ? 00:00:10 postgres: ...
- Centos7 Openldap主从配置
转载 https://blog.csdn.net/htvxjl02/article/details/80336788 Centos7 Openldap主从配置 2018年05月16日 15:09:57 ...
- postgresql 主从配置
安装postgresql 主从是否一定需要分两台机器,主从必须要同一个版本,不然启动会报错. 3. 配置Master数据库 su – postgres /usr/local/pgsql/bin/pg_ ...
- postgresql主从配置
master:10.0.1.114 slaver:10.0.1.116 一.yum安装https://blog.csdn.net/weixin_41048363/article/details/803 ...
- centos7 postgresql安装配置
2021-07-15 1.添加用户 # 添加用户 postgres useradd postgres # 给用户 postgres 设置密码 passwd postgres 2.切换到该用户,下载 p ...
- postgresql pgsql最新版安装指南及数据存储路径更改及主从配置
postgresql pgsql最新版安装指南及数据存储路径更改及主从配置 安装指南 首先在apt的list添加你当前系统版本对应的apt列表 目前官网有16.04,14.04,12.04 分别对应下 ...
- postgresql主从同步配置
前言 不久前,公司的一台物理机器硬件坏了,导致运行在其上的虚拟机都挂了.很不凑巧的是,我负责的那台虚拟机的系统盘坏了(ps:感觉老天在玩我),导致里面的数据永远的离我而去(ps:当时我的内心是崩溃的) ...
- CentOS7系统DNS主从配置
CentOS7系统DNS主从配置:一.DNS服务器正向解析:1.1 基础环境:主机IP 主机名 操作系统 用途192.168.0.110 master ...
随机推荐
- oracle 行专列
首先,做准备工作. 建表 -- Create table create table DEMO ( n_iden NUMBER, c_order_code NVARCHAR2(), c_order_na ...
- Scala并发编程
Scala的actor提供了一种基于事件的轻量级线程.只要使用scala.actors.Actor伴生对象的actor方法,就可以创建一个actor.它接受一个函数值/闭包做参数,一创建好就开始运行. ...
- Git操作基本命令
分支开发原则: 如果本地dev分支有修改,则需要先切换到master分支,把本地分支的修改merge回master(git merge dev),然后在master上把合并后的内容push到maste ...
- Python编码问题整理【转】
认识常见编码 GB2312是中国规定的汉字编码,也可以说是简体中文的字符集编码 GBK 是 GB2312的扩展 ,除了兼容GB2312外,它还能显示繁体中文,还有日文的假名 cp936:中文本地系统是 ...
- 第七十一,CSS颜色与度量单位
CSS颜色与度量单位 学习要点: 1.颜色表方案 2.度量单位 本章主要探讨HTML5中CSS颜色和度量单位等问题,包括颜色的选取方式.相对长度和绝对长度等. 一.颜色表方案 1 颜色的表现形式主 ...
- 【🉐】 彻底理解webservice SOAP WSDL
原文: http://wenku.baidu.com/view/f87b55f19e31433239689314.html WebServices简介 先给出一个概念 SOA ,即Service Or ...
- 2016弱校联盟十一专场10.2——Around the World
题目链接:Around the World 题意: 给你n个点,有n-1条边,现在这n-1条边又多增加了ci*2-1条边,问你有多少条欧拉回路 题解: 套用best定理 Best Theorem:有向 ...
- strings
3.1.1.1 计算列表中的字符串数目 使用Count属性可计算列表中的字符串数目.Count是只读属性,用以指示列表中字符串列表数目.因为字符串列表是以零开始索引,因而Count比列表的最大索引数大 ...
- 驱动力—— 通信引擎(上)—— ESFramework 4.0 进阶(03)
在ESFramework 4.0 进阶(02)-- 核心:消息处理的骨架流程一文中我们详细介绍了ESFramework中消息处理的骨架流程,并且我们已经知道,ESFramework中的所有通信引擎使用 ...
- 重登陆模式 --ESFramework 4.0 快速上手(07)
在ESFramework框架中基于TCP的服务端引擎(当然也包括Rapid引擎)都采用了这样一条规则:默认情况下,客户端与服务器成功建立TCP连接以后,服务端会从客户端发过来的第一条消息中取出消息头的 ...