中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

postgresql 10 pub/sub使用簡明教程

發布時間:2020-10-19 00:10:13 來源:網絡 閱讀:2628 作者:pgmia 欄目:數據庫

1.初始化配置


1).pubdb

postgres=# create database pubdb;

postgres=# \c pubdb 

You are now connected to database "pubdb" as user "postgres".

pubdb=# create table t1(id bigserial primary key, name varchar(20));

CREATE TABLE

pubdb=# create publication pub_mdb1_t1 for table t1;

CREATE PUBLICATION

pubdb=# 


pubdb=# select * from pg_publication;

   pubname   | pubowner | puballtables | pubinsert | pubupdate | pubdelete 

-------------+----------+--------------+-----------+-----------+-----------

 pub_mdb1_t1 |       10 | f            | t         | t         | t

(1 row)


pubdb=# 

pubdb=# insert into t1(name) values ('Peter'),('Chris'),('Jasmine'),('Jeans'),('Willam');

INSERT 0 5

pubdb=# select * from t1;

 id |  name   

----+---------

  1 | Peter

  2 | Chris

  3 | Jasmine

  4 | Jeans

  5 | Willam

(5 rows)


pubdb=# 

pubdb=# 

pubdb=# \q

[postgres@pgmdb01 ~]$


2).subdb

$ createdb subdb

恢復原發布數據

$ pg_restore -d subdb t1.dump


創建提交,不復制原存在數據,此時sub端啟動一個logical replication worker,

pub端創建一個pg_replication_slot


$ psql subdb

subdb=# CREATE SUBSCRIPTION sub_mdb1_t1

    CONNECTION 'host=172.16.3.228 port=5432 user=postgres password=123456 dbname=pubdb'

    PUBLICATION pub_mdb1_t1

    WITH (copy_data = false);

NOTICE:  created replication slot "sub_mdb1_t1" on publisher

CREATE SUBSCRIPTION

subdb=# 

subdb=# 

subdb=# 

subdb=# select * from t1;

 id |  name   

----+---------

  1 | Peter

  2 | Chris

  3 | Jasmine

  4 | Jeans

  5 | Willam

(5 rows)


查看提交信息


subdb=# \dRs+

List of subscriptions

-[ RECORD 1 ]------+-----------------------------------------------------------------------

Name               | sub_mdb1_t1

Owner              | postgres

Enabled            | t

Publication        | {pub_mdb1_t1}

Synchronous commit | off

Conninfo           | host=172.16.3.228 port=5432 user=postgres password=123456 dbname=pubdb


subdb=# \dRs

List of subscriptions

-[ RECORD 1 ]--------------

Name        | sub_mdb1_t1

Owner       | postgres

Enabled     | t

Publication | {pub_mdb1_t1}

subdb=# 


3).pubdb查看發布復制信息

pubdb=# 

pubdb=# select * from pg_stat_replication;

-[ RECORD 1 ]----+------------------------------

pid              | 16501

usesysid         | 10

usename          | postgres

application_name | sub_mdb1_t1

client_addr      | 172.16.3.230

client_hostname  | 

client_port      | 52682

backend_start    | 2017-10-10 14:59:18.469715+08

backend_xmin     | 

state            | streaming

sent_lsn         | 0/F036E90

write_lsn        | 0/F036E90

flush_lsn        | 0/F036E90

replay_lsn       | 0/F036E90

write_lag        | 

flush_lag        | 

replay_lag       | 

sync_priority    | 0

sync_state       | async


pubdb=# select * from pg_replication_slots ;

-[ RECORD 1 ]-------+------------

slot_name           | sub_mdb1_t1

plugin              | pgoutput

slot_type           | logical

datoid              | 26203

database            | pubdb

temporary           | f

active              | t

active_pid          | 16501

xmin                | 

catalog_xmin        | 604

restart_lsn         | 0/F036E58

confirmed_flush_lsn | 0/F036E90


2.插入增量發布記錄

1).pubdb插入增量

pubdb=# pubdb=# insert into t1(name) values('Zeng'),('Feng'),('Mia');

INSERT 0 3

pubdb=# \x

Expanded display is off.

pubdb=# select * from t1;

 id |  name   

----+---------

  1 | Peter

  2 | Chris

  3 | Jasmine

  4 | Jeans

  5 | Willam

  6 | Zeng

  7 | Feng

  8 | Mia

(8 rows)


pubdb=# 

pubdb=# select * from pg_stat_replication;

-[ RECORD 1 ]----+------------------------------

pid              | 16501

usesysid         | 10

usename          | postgres

application_name | sub_mdb1_t1

client_addr      | 172.16.3.230

client_hostname  | 

client_port      | 52682

backend_start    | 2017-10-10 14:59:18.469715+08

backend_xmin     | 

state            | streaming

sent_lsn         | 0/F0372B8

write_lsn        | 0/F0372B8

flush_lsn        | 0/F0372B8

replay_lsn       | 0/F0372B8

write_lag        | 

flush_lag        | 

replay_lag       | 

sync_priority    | 0

sync_state       | async


pubdb=# select * from pg_replication_slots ;

-[ RECORD 1 ]-------+------------

slot_name           | sub_mdb1_t1

plugin              | pgoutput

slot_type           | logical

datoid              | 26203

database            | pubdb

temporary           | f

active              | t

active_pid          | 16501

xmin                | 

catalog_xmin        | 605

restart_lsn         | 0/F037280

confirmed_flush_lsn | 0/F0372B8


pubdb=# 

[postgres@pgmdb01 ~]$ ps -fU postgres

UID        PID  PPID  C STIME TTY          TIME CMD

postgres 15874 15873  0 12:44 pts/2    00:00:00 -bash

postgres 15950     1  0 12:50 ?        00:00:00 /opt/pgsql/10.0/bin/postmaster -D /pgdata10

postgres 15951 15950  0 12:50 ?        00:00:00 postgres: logger process   

postgres 15953 15950  0 12:50 ?        00:00:00 postgres: checkpointer process   

postgres 15954 15950  0 12:50 ?        00:00:00 postgres: writer process   

postgres 15955 15950  0 12:50 ?        00:00:00 postgres: wal writer process   

postgres 15956 15950  0 12:50 ?        00:00:00 postgres: autovacuum launcher process   

postgres 15957 15950  0 12:50 ?        00:00:00 postgres: archiver process   

postgres 15958 15950  0 12:50 ?        00:00:00 postgres: stats collector process   

postgres 15959 15950  0 12:50 ?        00:00:00 postgres: bgworker: logical replication launcher  

postgres 15961 15960  0 12:50 pts/1    00:00:00 -bash

postgres 16077 15874  0 13:08 pts/2    00:00:00 tail -f postgresql-Tue.log

postgres 16082 15950  0 13:10 ?        00:00:00 postgres: postgres pubdb 172.16.3.223(56608) idle

postgres 16083 15950  0 13:10 ?        00:00:00 postgres: postgres pubdb 172.16.3.223(56610) idle

postgres 16501 15950  0 14:59 ?        00:00:00 postgres: wal sender process postgres 172.16.3.230(52682) idle

postgres 16543 15961  0 15:09 pts/1    00:00:00 ps -fU postgres

[postgres@pgmdb01 ~]$ 


sequence增長為最新值8


CREATE SEQUENCE public.t1_id_seq

    INCREMENT 1

    START 8

    MINVALUE 1

    MAXVALUE 9223372036854775807

    CACHE 1;


2).查看增量提交記錄


subdb


subdb=# select * from t1;

 id |  name   

----+---------

  1 | Peter

  2 | Chris

  3 | Jasmine

  4 | Jeans

  5 | Willam

  6 | Zeng

  7 | Feng

  8 | Mia

(8 rows)


subdb=# 



[postgres@pgsubdb1 log]$ ps -fU postgres

UID        PID  PPID  C STIME TTY          TIME CMD

postgres   935     1  0 10:28 ?        00:00:01 /opt/pgsql/10.0/bin/postmaster -D /pgdata10

postgres  1001   935  0 10:28 ?        00:00:00 postgres: logger process   

postgres  1005   935  0 10:28 ?        00:00:00 postgres: checkpointer process   

postgres  1006   935  0 10:28 ?        00:00:00 postgres: writer process   

postgres  1007   935  0 10:28 ?        00:00:01 postgres: wal writer process   

postgres  1008   935  0 10:28 ?        00:00:00 postgres: autovacuum launcher process   

postgres  1009   935  0 10:28 ?        00:00:00 postgres: archiver process   

postgres  1010   935  0 10:28 ?        00:00:00 postgres: stats collector process   

postgres  1011   935  0 10:28 ?        00:00:00 postgres: bgworker: logical replication launcher  

postgres  1084  1083  0 10:28 pts/0    00:00:00 -bash

postgres 15551 15550  0 11:48 pts/1    00:00:00 -bash

postgres 16206 16205  0 14:40 pts/2    00:00:00 -bash

postgres 16276  1084  0 14:46 pts/0    00:00:00 psql subdb

postgres 16277   935  0 14:46 ?        00:00:00 postgres: postgres subdb [local] idle

postgres 16324 16206  0 14:56 pts/2    00:00:00 psql subdb

postgres 16325   935  0 14:56 ?        00:00:00 postgres: postgres subdb [local] idle

postgres 16332   935  0 14:59 ?        00:00:00 postgres: bgworker: logical replication worker for subscription 24626  

postgres 16374 15551  0 15:11 pts/1    00:00:00 ps -fU postgres

[postgres@pgsubdb1 log]$


sequence為原始值5,不增長


CREATE SEQUENCE public.t1_id_seq

    INCREMENT 1

    START 5

    MINVALUE 1

    MAXVALUE 9223372036854775807

    CACHE 1;


3.常見問題(特殊情景使用請參見官方文檔)


當遠程數據庫無法連接時,drop SUBSCRIPTION


# ALTER SUBSCRIPTION name DISABLE

# alter subscription sub_measurement set (slot_name=none);

# drop subscription sub_measurement;


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

台湾省| 调兵山市| 琼海市| 辽宁省| 漳浦县| 昌图县| 台江县| 若尔盖县| 高清| 南部县| 无为县| 根河市| 江城| 保靖县| 龙泉市| 永年县| 胶州市| 吴堡县| 南靖县| 石阡县| 昔阳县| 长垣县| 佳木斯市| 遵义县| 年辖:市辖区| 桐庐县| 封开县| 海原县| 论坛| 昌都县| 甘孜| 文水县| 宽城| 乌鲁木齐市| 武强县| 明光市| 辽宁省| 斗六市| 云南省| 台安县| 灌阳县|