CentOS7 PostgreSQL 主从配置( 一)

主库配置

pg_hba.conf

host replication all 10.2.0.0/0 trust

postgresql.conf

listen_addresses = ‘*‘
max_wal_senders = 5
wal_level = hot_standby

重启主库

从库配置

安装
使用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

查看生成文件(注意文件的权限,用户组)

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_standdby=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-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 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
(1 row)

test=# insert into test01 values(1,‘1111‘);
INSERT 0 1
test=# insert into test01 values(2,‘2222‘);
INSERT 0 1
test=# insert into test01 values(4,‘4444‘);
INSERT 0 1
test=# insert into test01 values(5,‘5555‘);
INSERT 0 1
test=# \q

select * from test01;
id | note
----+------
1 | 1111
2 | 2222
4 | 4444
5 | 5555
时间: 2024-08-08 21:07:21

CentOS7 PostgreSQL 主从配置( 一)的相关文章

CentOS7 PostgreSQL 主从配置

PostgreSQL安装 安装使用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.rpmyum install postgresql95-server postgresql95-contrib 设置开机启动 (centos 服务安装位置 cd /usr

CentOS7 PostgreSQL 主从配置( 三)

postgres 主备切换 主备查看 方法 ps -ef | grep wal (主库 sender)postgres 27873 27864 0 5月06 ? 00:00:10 postgres: wal sender process postgres 10.2.0.13(47582) streaming 0/906FF78postgres 27874 27864 0 5月06 ? 00:00:11 postgres: wal sender process postgres 10.2.0.15

postgresql 主从配置

安装postgresql 主从是否一定需要分两台机器,主从必须要同一个版本,不然启动会报错. 3. 配置Master数据库 su – postgres /usr/local/pgsql/bin/pg_ctl –D /data/pgsql9.1 start #启动数据库 #进入数据库创建repl用户 Psql –p 5432 –U postgres –h 127.0.0.1 Create user repl superuser password ‘密码’ \q #修改postgresql.conf

postgresql主从配置

master:10.0.1.114 slaver:10.0.1.116 一.yum安装https://blog.csdn.net/weixin_41048363/article/details/80310285 二.主从配置 1.主数据配置(10.0.1.114) 1.1  初始化 /usr/pgsql-9.6/bin/postgresql96-setup initdb 1.2 启动postgresql systemctl start postgresql-9.6 1.3 切换到postgres

Linux7/Centos7 Mariadb主从配置过程

环境:RedHat7 同样适用于Centos7(本文是在无网络环境部署mariadb主从) 卸载Mysql (防止mysql和mariadb冲突 ) 停止服务:systemctl stop mysqld 查询安装包:rpm -qa | grep mysql 卸载: rpm -e mysql-server rpm -e --nodeps mysql-libs 准备环境查看磁盘挂载情况:df –h < 如果没有则挂载系统盘:mount/dev/cdrom /media > PS: 在虚拟机设置里对

Centos7+Mariadb集群-主从配置介绍

近期一直在恶补Linux相关的知识,主要是就是学Linux下的基本日常应用服务器的配置及优化,今天我们主要介绍一下在Centos7下安装及配置Mysql 集群,说到集群,其实就是为了提高服务的高可用性.对于高可用的相关服务今天不是主要介绍内容,今天主要介绍MYSQL的主从配置.对在Linux下的其他服务的介绍及服务高可用负载均衡我们将会在后期的文章中介绍.开始今天的介绍:Centos7+Mysql主从配置. 环境介绍: Hostname:A-S IP:192.168.5.21 Role:Mysq

redis介绍及主从配置

redis介绍及主从配置 本文主要包含两个部分:简单介绍下什么是redis.redis主从配置及基于sentinel实现redis集群故障自动切换. redis基于内存亦可持久化的日志型.Key-Value数据库,目前接触到redis主要应用在session缓存方面. 一.系统环境 平台:Centos7.0_x86_64 主机:192.168.115.11.192.168.115.12.192.168.115.12 规划:11为master节点,12.13为slave节点 二.安装redis 1

mycat基础实验之主从配置读写分离和分表

mycat实验之主从配置读写分离和分表 架构图: 1.实验环境: vmware虚机3个   (虚机太少了,电脑有点吃力,3个虚机只能达到基本的测试) 系统centos7     (实验是关闭防火墙和selinux做的) mysql版本5.7 mycat版本1.6 虚机名字和ip: mysql1 192.168.211.138 mysql2 192.168.211.139 mysql3 192.168.211.142 mycat安装在mysql1(192.168.211.138) 这台主机须能够解

mysql主从配置实现一主一从读写分离

主从介绍 定义 Mysql主从又叫Replication.AB复制.简单讲就是A与B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,实现数据实时同步 mysql主从是基于binlog,主上需开启binlog才能进行主从 主从过程大概有3个步骤 主将更改操作记录到binlog里 从将主的binlog事件(sql语句) 同步本机上并记录在relaylog里 从根据relaylog里面的sql语句按顺序执行 主上有一个log dump线程,用来和从的I/O 线程传递binlog 从上有两个线