CentOS7 PostgreSQL 主从配置( 一)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CentOS7 PostgreSQL 主从配置( 一),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3728字,纯文字阅读大概需要6分钟。
内容图文
![CentOS7 PostgreSQL 主从配置( 一)](/upload/InfoBanner/zyjiaocheng/463/6d98c0f2c6014543bc03e5fe3c44a1ce.jpg)
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
CentOS7 PostgreSQL 主从配置( 一)
标签:
本文系统来源:http://www.cnblogs.com/zhangeamon/p/5465501.html
内容总结
以上是互联网集市为您收集整理的CentOS7 PostgreSQL 主从配置( 一)全部内容,希望文章能够帮你解决CentOS7 PostgreSQL 主从配置( 一)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。