欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PostgreSQL部署邏輯復(fù)制過(guò)程詳解

 更新時(shí)間:2024年04月29日 12:14:18   作者:Floating warm sun  
這篇文章主要介紹了PostgreSQL部署邏輯復(fù)制過(guò)程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

1.環(huán)境準(zhǔn)備

角色主機(jī)名IP端口數(shù)據(jù)庫(kù)名用戶(hù)名版本
發(fā)布端postgresql192.168.80.2395432pubdbreplicpostgresql 15
訂閱端postgresql2192.168.80.2405432subdbreplicpostgresql 15

2.發(fā)布端配置參數(shù)

## vi postgressql.conf(重啟生效)
listen_addresses = '*'
wal_level=logical
max_replication_slots=8
max_wal_senders=10
## alter system set
alter system set wal_level=logical;
## 參數(shù)說(shuō)明
wal_level設(shè)置為logical,才支持邏輯復(fù)制,低于這個(gè)級(jí)別邏輯復(fù)制不能工作。
max_replication_slots設(shè)置值必須大于訂閱的數(shù)量。
max_wal_senders設(shè)置值必須大于max_replication_slots參數(shù)值加上物理備庫(kù)數(shù),因?yàn)槊總€(gè)訂閱在主庫(kù)上都會(huì)占用主庫(kù)一個(gè)wal發(fā)送進(jìn)程。

3.發(fā)布端配置pg_hba.conf

vi pg_hba.conf
host    replication     test       0/0         md5

4.訂閱端配置參數(shù)

## vi postgresql.conf(重啟生效)
listen_addresses = '*'
wal_level=logical
max_replication_slots=8
max_logical_replication_workers=8
## alter system set
alter system set wal_level=logical;
## 參數(shù)說(shuō)明
max_replication_slots設(shè)置數(shù)據(jù)庫(kù)復(fù)制槽數(shù)量。
max_logical_replication_workers設(shè)置邏輯復(fù)制進(jìn)程數(shù),應(yīng)大于訂閱節(jié)點(diǎn)的數(shù)量,并且給表同步預(yù)留一些進(jìn)程數(shù)量。
注意:max_logical_replication_workers會(huì)消耗后臺(tái)進(jìn)程數(shù),并且從max_worker_processes參數(shù)設(shè)置的后臺(tái)進(jìn)程數(shù)中消費(fèi),因此max_worker_processes需要設(shè)置的大一些。

5.發(fā)布端創(chuàng)建邏輯復(fù)制用戶(hù),并具備replication復(fù)制權(quán)限(可選)

如不創(chuàng)建,可以使用默認(rèn)的管理員用戶(hù)postgres。

postgres=# create user replic replication login connection limit 8 password 'replic';
CREATE ROLE
limit 8:為新用戶(hù)設(shè)置最大數(shù)目連接數(shù)。默認(rèn)無(wú)限制。

6.發(fā)布端創(chuàng)建發(fā)布

## 創(chuàng)建復(fù)制數(shù)據(jù)庫(kù)
postgres=# create database pubdb;
CREATE DATABASE
## 授予復(fù)制用戶(hù)權(quán)限
postgres=# \c pubdb postgres
You are now connected to database "pubdb" as user "postgres".
pubdb=# grant all on schema public to replic;
GRANT
## 創(chuàng)建復(fù)制表
pubdb=> create table c1 (id int4 primary key,name text);
CREATE TABLE
pubdb=> insert into c1 values (1,'a');
INSERT 0 1
pubdb=> select * from c1;
 id | name 
----+------
  1 | a
(1 row)
## 創(chuàng)建發(fā)布
pubdb=> \c pubdb postgres
You are now connected to database "pubdb" as user "postgres".
pubdb=# create publication pub1 for table c1;
CREATE PUBLICATION
注意:如果發(fā)布多張表使用逗號(hào)隔開(kāi),如果發(fā)布所有表則將 for table 修改為 for all tables。
##查看創(chuàng)建的發(fā)布
pubdb=# select * from pg_publication;
  oid  | pubname | pubowner | puballtables | pubinsert | pubupdate | pubdelete | pubtruncate | pubviaroot 
-------+---------+----------+--------------+-----------+-----------+-----------+-------------+------------
 33177 | pub1    |       10 | f            | t         | t         | t         | t           | f
(1 row)
參數(shù)說(shuō)明:
pubname:發(fā)布名稱(chēng)。
pubowner:發(fā)布的屬主,可以和pg_user視圖的usesysid字段關(guān)聯(lián)查詢(xún)屬主的具體信息。
puballtables:是否發(fā)布數(shù)據(jù)庫(kù)中的所有表,t 表示發(fā)布數(shù)據(jù)庫(kù)中所有已存在的表和以后新建的表。
pubinsert:t 表示僅發(fā)布表上的insert操作。
pubupdate:t 表示僅發(fā)布表上的update操作。
pubdelete:t 表示僅發(fā)布表上的delete操作。
pubtruncate:t 表示僅發(fā)布表上的truncate操作。

7.發(fā)布端給復(fù)制用戶(hù)授權(quán)

pubdb=# grant connect on database pubdb to replic;
GRANT
pubdb=# grant usage on schema public to replic;
GRANT
pubdb=# grant select on c1 to replic;
GRANT

8.訂閱端創(chuàng)建表

postgres=# create database subdb;
CREATE DATABASE
postgres=# create user replic replication login connection limit 8 password 'replic';
CREATE ROLE
subdb=> \c subdb postgres
You are now connected to database "subdb" as user "postgres".
subdb=# grant all on schema public to replic;
GRANT
subdb=> create table c1 (id int4 primary key,name text);
CREATE TABLE

9.訂閱端創(chuàng)建訂閱

subdb=> \c subdb postgres
You are now connected to database "subdb" as user "postgres".
subdb=# create subscription sub1 connection 'host=192.168.80.239 port=5432 dbname=pubdb user=replic password=replic' publication pub1;
NOTICE:  created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
## 查看創(chuàng)建的訂閱
subdb=# \x
Expanded display is on.
subdb=# select * from pg_subscription;
-[ RECORD 1 ]----+-----------------------------------------------------------------------
oid              | 41374
subdbid          | 41361
subskiplsn       | 0/0
subname          | sub1
subowner         | 10
subenabled       | t
subbinary        | f
substream        | f
subtwophasestate | d
subdisableonerr  | f
subconninfo      | host=192.168.80.239 port=5432 dbname=pubdb user=replic password=replic
subslotname      | sub1
subsynccommit    | off
subpublications  | {pub1}

10.訂閱端給復(fù)制用戶(hù)授權(quán)

subdb=# grant connect on database subdb to replic;
GRANT
subdb=# grant usage on schema public to replic;
GRANT
subdb=# grant select on c1 to replic;
GRANT

11.配置完成,發(fā)布端查看信息

postgres=# select slot_name,plugin,slot_type,database,active,restart_lsn from pg_replication_slots where slot_name='sub1';
 slot_name |  plugin  | slot_type | database | active | restart_lsn 
-----------+----------+-----------+----------+--------+-------------
 sub1      | pgoutput | logical   | pubdb    | t      | 0/3F45C840
(1 row)

12.測(cè)試邏輯復(fù)制

## 發(fā)布端向表中插入數(shù)據(jù)
pubdb=> insert into c1 values (2,'tt');
INSERT 0 1
pubdb=> select * from c1;
 id | name 
----+------
  1 | a
  2 | tt
(2 rows)
pubdb=> delete from c1 where id=1;
DELETE 1
pubdb=> select * from c1;
 id | name 
----+------
  2 | tt
(1 row)
## 訂閱端查看結(jié)果
subdb=# select * from c1;
 id | name 
----+------
  2 | tt
(1 row)
## 添加新表測(cè)試,發(fā)布端創(chuàng)建表結(jié)構(gòu)
pubdb=> create table c2 (id int primary key,addr varchar(100));
CREATE TABLE
## 訂閱端創(chuàng)建表結(jié)構(gòu)
subdb=> create table c2 (id int primary key,addr varchar(100));
CREATE TABLE
## 發(fā)布端授權(quán)
pubdb=> grant select on c2 to replic;
GRANT
## 將新表c2,添加到發(fā)布列表中
pubdb=> \c pubdb postgres 
You are now connected to database "pubdb" as user "postgres".
pubdb=# alter publication pub1 add table c2;
ALTER PUBLICATION
## 發(fā)布端查看發(fā)布列表
pubdb=# select * from pg_publication_tables;
 pubname | schemaname | tablename | attnames  | rowfilter 
---------+------------+-----------+-----------+-----------
 pub1    | public     | c1        | {id,name} | 
 pub1    | public     | c2        | {id,addr} | 
(2 rows)
## 如果沒(méi)有看到新表,可在訂閱端刷新訂閱
subdb=> \c subdb postgres
You are now connected to database "subdb" as user "postgres".
subdb=# alter subscription sub1 refresh publication;
ALTER SUBSCRIPTION
## 刪除復(fù)制設(shè)置
drop subscription sub1;

到此這篇關(guān)于PostgreSQL部署邏輯復(fù)制的文章就介紹到這了,更多相關(guān)PostgreSQL部署內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Postgresql中LIKE和ILIKE操作符的用法詳解

    Postgresql中LIKE和ILIKE操作符的用法詳解

    這篇文章主要介紹了Postgresql中LIKE和ILIKE操作符的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • Postgre數(shù)據(jù)庫(kù)Insert 、Query性能優(yōu)化詳解

    Postgre數(shù)據(jù)庫(kù)Insert 、Query性能優(yōu)化詳解

    這篇文章主要介紹了Postgre數(shù)據(jù)庫(kù)Insert和Query性能優(yōu)化的步驟,大家可以參考使用
    2013-11-11
  • PostgreSQL實(shí)現(xiàn)一個(gè)通用標(biāo)簽系統(tǒng)

    PostgreSQL實(shí)現(xiàn)一個(gè)通用標(biāo)簽系統(tǒng)

    這篇文章主要給大家介紹了關(guān)于利用PostgreSQL實(shí)現(xiàn)一個(gè)通用標(biāo)簽系統(tǒng)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • postgresql SQL語(yǔ)句變量的使用說(shuō)明

    postgresql SQL語(yǔ)句變量的使用說(shuō)明

    這篇文章主要介紹了postgresql SQL語(yǔ)句變量的使用說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • 解決PostgreSQL Array使用中的一些小問(wèn)題

    解決PostgreSQL Array使用中的一些小問(wèn)題

    這篇文章主要介紹了解決PostgreSQL Array使用中的一些小問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • PostgreSQL數(shù)據(jù)庫(kù)的基本查詢(xún)操作

    PostgreSQL數(shù)據(jù)庫(kù)的基本查詢(xún)操作

    這篇文章采用詳細(xì)的代碼示例為大家介紹了PostgreSQL數(shù)據(jù)庫(kù)的基本查詢(xún)操作使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-04-04
  • PostgreSQL中實(shí)現(xiàn)數(shù)據(jù)實(shí)時(shí)監(jiān)控和預(yù)警的步驟詳解

    PostgreSQL中實(shí)現(xiàn)數(shù)據(jù)實(shí)時(shí)監(jiān)控和預(yù)警的步驟詳解

    在 PostgreSQL 中實(shí)現(xiàn)數(shù)據(jù)的實(shí)時(shí)監(jiān)控和預(yù)警是確保數(shù)據(jù)庫(kù)性能和數(shù)據(jù)完整性的關(guān)鍵任務(wù),以下將詳細(xì)討論如何實(shí)現(xiàn)此目標(biāo),并提供相應(yīng)的解決方案和具體示例,需要的朋友可以參考下
    2024-07-07
  • PostgreSQL慢SQL的定位排查方法

    PostgreSQL慢SQL的定位排查方法

    所謂慢SQL 是指在數(shù)據(jù)庫(kù)中執(zhí)行時(shí)間超過(guò)指定閾值的語(yǔ)句,慢查詢(xún)太多,對(duì)于業(yè)務(wù)而言,是有很大風(fēng)險(xiǎn)的,可能隨時(shí)都會(huì)因?yàn)槟撤N原因而被觸發(fā),本篇文章將介紹 PostgreSQL 慢 SQL 如何定位排查,需要的朋友可以參考下
    2024-07-07
  • PostgreSQL 復(fù)制表的 5 種方式詳解

    PostgreSQL 復(fù)制表的 5 種方式詳解

    PostgreSQL 提供了多種不同的復(fù)制表的方法,它們的差異在于是否需要復(fù)制表結(jié)構(gòu)或者數(shù)據(jù),這篇文章主要介紹了PostgreSQL 復(fù)制表的 5 種方式,需要的朋友可以參考下
    2023-01-01
  • PostgreSQL實(shí)現(xiàn)按年、月、日、周、時(shí)、分、秒的分組統(tǒng)計(jì)

    PostgreSQL實(shí)現(xiàn)按年、月、日、周、時(shí)、分、秒的分組統(tǒng)計(jì)

    這篇文章介紹了PostgreSQL實(shí)現(xiàn)按年、月、日、周、時(shí)、分、秒分組統(tǒng)計(jì)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06

最新評(píng)論