postgresql 9.4 流複製簡單配置
#環境
postgresql:9.4.5
host:ct6606 192.108.56.122 master
ct6607 192.108.56.123 slave
#安裝postgresql
#在ct6606,ct6607分別執行以下
[root@ct6606 ~]# ll postgresql-9.4.5-1-linux-x64.run
-rwxr--r--. 1 root root 37802126 Nov 5 2015 postgresql-9.4.5-1-linux-x64.run
[root@ct6606 ~]# ./postgresql-9.4.5-1-linux-x64.run
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.
----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.
Installation Directory [/opt/PostgreSQL/9.4]:
----------------------------------------------------------------------------
Please select a directory under which to store your data.
Data Directory [/opt/PostgreSQL/9.4/data]:
----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.
Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.
Port [5432]:
----------------------------------------------------------------------------
Advanced Options
Select the locale to be used by the new database cluster.
Locale
[1] [Default locale]
...
[707] zh_CN
[708] zh_CN.gb2312
[709] zh_CN.utf8
...
Please choose an option [1] : 709
----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.
Do you want to continue? [Y/n]: y
----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.
[root@ct6606 ~]# id postgres
uid=500(postgres) gid=500(postgres) groups=500(postgres)
[root@ct6606 ~]# ps -ef|grep postgre|grep -v grep
postgres 25195 1 0 09:02 ? 00:00:00 /opt/PostgreSQL/9.4/bin/postgres -D /opt/PostgreSQL/9.4/data
postgres 25197 25195 0 09:02 ? 00:00:00 postgres: logger process
postgres 25199 25195 0 09:02 ? 00:00:00 postgres: checkpointer process
postgres 25200 25195 0 09:02 ? 00:00:00 postgres: writer process
postgres 25201 25195 0 09:02 ? 00:00:00 postgres: wal writer process
postgres 25202 25195 0 09:02 ? 00:00:00 postgres: autovacuum launcher process
postgres 25203 25195 0 09:02 ? 00:00:00 postgres: stats collector process
[root@ct6606 ~]# echo "export PATH=\$PATH:/opt/PostgreSQL/9.4/bin" >>/root/.bash_profile
[root@ct6606 ~]# . /root/.bash_profile
[root@ct6606 ~]# mv /etc/init.d/postgresql-9.4 /etc/init.d/postgresql
#配置postgresql
#在ct6606執行以下
#修改引數
[root@ct6606 ~]# cd /opt/PostgreSQL/9.4/data/
[root@ct6606 data]# vi postgresql.conf
加入:
wal_level=hot_standby
max_wal_senders=1
hot_standby=on
[root@ct6606 data]# vi pg_hba.conf
修改:
host all all 127.0.0.1/32 md5為:
host all all 0.0.0.0/0 md5
加入:
host replication repuser 0.0.0.0/0 md5
[root@ct6606 data]# service postgresql restart
#建replication使用者,備份,傳輸
[root@ct6606 data]# psql -U postgres
postgres=# create user repuser replication login connection limit 5 encrypted password 'system';
postgres=# select pg_start_backup('replication');
postgres=# \q
[root@ct6606 data]# cd /opt/PostgreSQL/9.4/
[root@ct6606 9.4]# tar -czvf data.tar.gz data --exclude=data/pg_xlog/*
[root@ct6606 data]# psql -U postgres
postgres=# select pg_stop_backup(), current_timestamp;
postgres=# select pg_switch_xlog();
postgres=# \q
[root@ct6606 9.4]# scp data.tar.gz 192.108.56.123:/opt/PostgreSQL/9.4/
#在ct6607執行以下
#解壓,修改引數,啟動
[root@ct6607 ~]# service postgresql stop
[root@ct6607 ~]# cd /opt/PostgreSQL/9.4/
[root@ct6607 9.4]# rm -rf data
[root@ct6607 9.4]# tar -xzvf data.tar.gz
[root@ct6607 9.4]# cd data
[root@ct6607 data]# cp ../share/postgresql/recovery.conf.sample recovery.conf
[root@ct6607 data]# vi recovery.conf
加入:
standby_mode=on
trigger_file='/opt/PostgreSQL/9.4/data/pg.trigger'
primary_conninfo='host=192.108.56.122 port=5432 user=repuser password=system keepalives_idle=60'
[root@ct6607 data]# vi .pgpass
加入:
192.108.56.122:5432:postgres:repuser:system
[root@ct6607 data]# service postgresql start
#測試
在master端會多出postgres: wal sender process 程式
在slave端會多出postgres: wal receiver process 程式
[root@ct6606 9.4]# psql -U postgres -h 192.108.56.122
postgres=# create table tb01 as select 1 a;
SELECT 1
postgres-# \q
[root@ct6606 9.4]# psql -U postgres -h 192.108.56.123
postgres=# select * from tb01;
a
---
1
(1 row)
postgresql:9.4.5
host:ct6606 192.108.56.122 master
ct6607 192.108.56.123 slave
#安裝postgresql
#在ct6606,ct6607分別執行以下
[root@ct6606 ~]# ll postgresql-9.4.5-1-linux-x64.run
-rwxr--r--. 1 root root 37802126 Nov 5 2015 postgresql-9.4.5-1-linux-x64.run
[root@ct6606 ~]# ./postgresql-9.4.5-1-linux-x64.run
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.
----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.
Installation Directory [/opt/PostgreSQL/9.4]:
----------------------------------------------------------------------------
Please select a directory under which to store your data.
Data Directory [/opt/PostgreSQL/9.4/data]:
----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.
Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.
Port [5432]:
----------------------------------------------------------------------------
Advanced Options
Select the locale to be used by the new database cluster.
Locale
[1] [Default locale]
...
[707] zh_CN
[708] zh_CN.gb2312
[709] zh_CN.utf8
...
Please choose an option [1] : 709
----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.
Do you want to continue? [Y/n]: y
----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.
[root@ct6606 ~]# id postgres
uid=500(postgres) gid=500(postgres) groups=500(postgres)
[root@ct6606 ~]# ps -ef|grep postgre|grep -v grep
postgres 25195 1 0 09:02 ? 00:00:00 /opt/PostgreSQL/9.4/bin/postgres -D /opt/PostgreSQL/9.4/data
postgres 25197 25195 0 09:02 ? 00:00:00 postgres: logger process
postgres 25199 25195 0 09:02 ? 00:00:00 postgres: checkpointer process
postgres 25200 25195 0 09:02 ? 00:00:00 postgres: writer process
postgres 25201 25195 0 09:02 ? 00:00:00 postgres: wal writer process
postgres 25202 25195 0 09:02 ? 00:00:00 postgres: autovacuum launcher process
postgres 25203 25195 0 09:02 ? 00:00:00 postgres: stats collector process
[root@ct6606 ~]# echo "export PATH=\$PATH:/opt/PostgreSQL/9.4/bin" >>/root/.bash_profile
[root@ct6606 ~]# . /root/.bash_profile
[root@ct6606 ~]# mv /etc/init.d/postgresql-9.4 /etc/init.d/postgresql
#配置postgresql
#在ct6606執行以下
#修改引數
[root@ct6606 ~]# cd /opt/PostgreSQL/9.4/data/
[root@ct6606 data]# vi postgresql.conf
加入:
wal_level=hot_standby
max_wal_senders=1
hot_standby=on
[root@ct6606 data]# vi pg_hba.conf
修改:
host all all 127.0.0.1/32 md5為:
host all all 0.0.0.0/0 md5
加入:
host replication repuser 0.0.0.0/0 md5
[root@ct6606 data]# service postgresql restart
#建replication使用者,備份,傳輸
[root@ct6606 data]# psql -U postgres
postgres=# create user repuser replication login connection limit 5 encrypted password 'system';
postgres=# select pg_start_backup('replication');
postgres=# \q
[root@ct6606 data]# cd /opt/PostgreSQL/9.4/
[root@ct6606 9.4]# tar -czvf data.tar.gz data --exclude=data/pg_xlog/*
[root@ct6606 data]# psql -U postgres
postgres=# select pg_stop_backup(), current_timestamp;
postgres=# select pg_switch_xlog();
postgres=# \q
[root@ct6606 9.4]# scp data.tar.gz 192.108.56.123:/opt/PostgreSQL/9.4/
#在ct6607執行以下
#解壓,修改引數,啟動
[root@ct6607 ~]# service postgresql stop
[root@ct6607 ~]# cd /opt/PostgreSQL/9.4/
[root@ct6607 9.4]# rm -rf data
[root@ct6607 9.4]# tar -xzvf data.tar.gz
[root@ct6607 9.4]# cd data
[root@ct6607 data]# cp ../share/postgresql/recovery.conf.sample recovery.conf
[root@ct6607 data]# vi recovery.conf
加入:
standby_mode=on
trigger_file='/opt/PostgreSQL/9.4/data/pg.trigger'
primary_conninfo='host=192.108.56.122 port=5432 user=repuser password=system keepalives_idle=60'
[root@ct6607 data]# vi .pgpass
加入:
192.108.56.122:5432:postgres:repuser:system
[root@ct6607 data]# service postgresql start
#測試
在master端會多出postgres: wal sender process 程式
在slave端會多出postgres: wal receiver process 程式
[root@ct6606 9.4]# psql -U postgres -h 192.108.56.122
postgres=# create table tb01 as select 1 a;
SELECT 1
postgres-# \q
[root@ct6606 9.4]# psql -U postgres -h 192.108.56.123
postgres=# select * from tb01;
a
---
1
(1 row)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1874775/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何配置 pglogical | PostgreSQL 的流複製SQL
- 【PG流複製】Postgresql流複製主備切換SQL
- 2. PostgreSQL 流複製SQL
- PostGreSql 12.6 的流複製(CentOS)SQLCentOS
- Postgres 流複製配置
- 【PG流複製】Postgresql流複製部署過程及效能測試SQL
- PostgreSQL 13 同步流複製(#2.4)-202104SQL
- 240815-PostgreSQL自帶邏輯複製簡單使用SQL
- PostgreSQL DBA(126) - PG 12(搭建流複製)SQL
- PostgreSQL 13 非同步流複製(#2.1)-202103SQL非同步
- PostgreSQL 13 同步流複製+failover(#2.6)-202104SQLAI
- Mysql Master-slave複製簡單配置記錄MySqlAST
- PostgreSQL 13 級聯流複製部署(#2.7)-202105SQL
- PostgreSQL DBA(31) - Backup&Recovery#4(搭建流複製)SQL
- 再不瞭解PostgreSQL,你就晚了之PostgreSQL主從流複製部署SQL
- 美創科技運維日記|postgresql-pg簡易非同步流複製搭建運維SQL非同步
- PostgreSQL 13 同步流複製+延遲備庫(#2.5)-202104SQL
- PostgreSQL 13 非同步流複製+failover切換(#2.3)-202104SQL非同步AI
- 使用 Bitnami PostgreSQL Docker 映象快速設定流複製叢集SQLDocker
- PostgreSQL 13 非同步流複製+延遲備庫(#2.2)-202103SQL非同步
- PostgreSQL基於PG內建流複製的,靠譜的PostgreSQL高可用方案SQL
- 簡單搭建MySQL主從複製MySql
- PostgreSQL 主從複製方案SQL
- PostgreSQL雙向複製教程SQL
- PostgreSQL 邏輯複製解密SQL解密
- PostgreSQL邏輯複製解密SQL解密
- PostgreSQL構建流複製拉取日誌的起始位置在哪裡SQL
- mysql複製--主從複製配置MySql
- Postgresql實戰:使用pg_basebackup或pg_start_backup方式搭建Postgresql主從流複製SQL
- MySQL 8 複製(五)——配置GTID複製MySql
- PostgreSQL中的複製延遲SQL
- pg流複製備份
- MySQL高可用之組複製技術(2):配置單主模型的組複製MySql模型
- poi操作excel,複製sheet,複製行,複製單元格,複製styleExcel
- 簡單實踐實現 MySQL 主從複製MySql
- 簡單的多執行緒複製檔案執行緒
- postgresql 簡單入門SQL
- MySQL 8 複製(九)——組複製聯機配置MySql
- 16.1.3 使用GTID 配置複製