亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

角色主機(jī)名IP端口數(shù)據(jù)庫名用戶名版本
發(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ù)說明
wal_level設(shè)置為logical,才支持邏輯復(fù)制,低于這個級別邏輯復(fù)制不能工作。
max_replication_slots設(shè)置值必須大于訂閱的數(shù)量。
max_wal_senders設(shè)置值必須大于max_replication_slots參數(shù)值加上物理備庫數(shù),因?yàn)槊總€訂閱在主庫上都會占用主庫一個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ù)說明
max_replication_slots設(shè)置數(shù)據(jù)庫復(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會消耗后臺進(jìn)程數(shù),并且從max_worker_processes參數(shù)設(shè)置的后臺進(jìn)程數(shù)中消費(fèi),因此max_worker_processes需要設(shè)置的大一些。

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

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

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

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

## 創(chuàng)建復(fù)制數(shù)據(jù)庫
postgres=# create database pubdb;
CREATE DATABASE
## 授予復(fù)制用戶權(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ā)布多張表使用逗號隔開,如果發(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ù)說明:
pubname:發(fā)布名稱。
pubowner:發(fā)布的屬主,可以和pg_user視圖的usesysid字段關(guān)聯(lián)查詢屬主的具體信息。
puballtables:是否發(fā)布數(shù)據(jù)庫中的所有表,t 表示發(fā)布數(shù)據(jù)庫中所有已存在的表和以后新建的表。
pubinsert:t 表示僅發(fā)布表上的insert操作。
pubupdate:t 表示僅發(fā)布表上的update操作。
pubdelete:t 表示僅發(fā)布表上的delete操作。
pubtruncate:t 表示僅發(fā)布表上的truncate操作。

7.發(fā)布端給復(fù)制用戶授權(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ù)制用戶授權(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.測試邏輯復(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)
## 添加新表測試,發(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)
## 如果沒有看到新表,可在訂閱端刷新訂閱
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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解析PostgreSQL中Oid和Relfilenode的映射問題

    解析PostgreSQL中Oid和Relfilenode的映射問題

    這篇文章主要介紹了PostgreSQL中Oid和Relfilenode的映射問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • PostgreSQL拆分字符串的三種方式

    PostgreSQL拆分字符串的三種方式

    這篇文章給大家介紹了PostgreSQL拆分字符串的三種方式,字符串轉(zhuǎn)為數(shù)組,字符串轉(zhuǎn)為列表和字符串轉(zhuǎn)為數(shù)據(jù)項(xiàng),并通過代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • postgresql設(shè)置id自增的基本方法舉例

    postgresql設(shè)置id自增的基本方法舉例

    這篇文章主要給大家介紹了關(guān)于postgresql設(shè)置id自增的基本方法,自增字段主要用于實(shí)現(xiàn)自增主鍵或生成唯一版本號,文中通過代碼以及圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • PostgreSQL表操作之表的創(chuàng)建及表基礎(chǔ)語法總結(jié)

    PostgreSQL表操作之表的創(chuàng)建及表基礎(chǔ)語法總結(jié)

    在PostgreSQL中創(chuàng)建表命令用于在任何給定的數(shù)據(jù)庫中創(chuàng)建新表,下面這篇文章主要給大家介紹了關(guān)于PostgreSQL表操作之表的創(chuàng)建及表基礎(chǔ)語法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • Postgresql 截取字符串的案例

    Postgresql 截取字符串的案例

    這篇文章主要介紹了Postgresql 截取字符串的案例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • PostgreSQL HOT與PHOT有哪些區(qū)別

    PostgreSQL HOT與PHOT有哪些區(qū)別

    這篇文章主要介紹了PostgreSQL8.3版本開始就引入的HOT機(jī)制與PHOT使用區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-09-09
  • PostgreSQL 如何獲取當(dāng)前日期時間及注意事項(xiàng)

    PostgreSQL 如何獲取當(dāng)前日期時間及注意事項(xiàng)

    這篇文章主要介紹了PostgreSQL 如何獲取當(dāng)前日期時間及注意事項(xiàng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • PostgreSQL 日志文件的所在位置

    PostgreSQL 日志文件的所在位置

    這篇文章主要介紹了PostgreSQL 日志文件的所在位置,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL部署邏輯復(fù)制過程詳解

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

    這篇文章主要介紹了PostgreSQL部署邏輯復(fù)制過程詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-04-04
  • postgreSQL中的case用法說明

    postgreSQL中的case用法說明

    這篇文章主要介紹了postgreSQL中的case用法說明,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01

最新評論