2017-10-17 184 views
1

我安裝PostgreSQL 10使用腳本:10 PostgreSQL的邏輯複製不工作

$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - 

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' 

$ sudo apt-get update 
$ sudo apt-get install postgresql postgresql-contrib 

在主服務器:xx.xxx.xxx.xx-:

而在這之後在postgresql.conf裏:

set wal_level = logical 

在從服務器 - :

postgresql.conf中

set wal_level = logical 

而且畢竟我用下面的查詢主服務器上:在從服務器

create table t1 (id integer primary key, val text); 
create user replicant with replication; 
grant select on t1 to replicant; 
insert into t1 (id, val) values (10, 'ten'), (20, 'twenty'), (30, 'thirty'); 
create publication pub1 for table t1; 

和:

create table t1 (id integer primary key, val text, val2 text); 
create subscription sub1 connection 'dbname=dbsrc user=replicant' publication pub1; 

但是這是我面臨的是表中的問題不同步和根據邏輯複製,當我在主服務器上插入新行時,從服務器沒有獲得該行。

我是新來的postgresql請幫幫我。

感謝您寶貴的時間。

現在,這裏是我的PostgreSQL日誌主服務器:

2017-10-17 11:06:16.644 UTC [10713] [email protected] LOG: starting logical decoding for slot "sub_1" 
2017-10-17 11:06:16.644 UTC [10713] [email protected] DETAIL: streaming transactions committing after 1/F45EB0C8, reading WAL from 1/F45EB0C8 
2017-10-17 11:06:16.645 UTC [10713] [email protected] LOG: logical decoding found consistent point at 1/F45EB0C8 
2017-10-17 11:06:16.645 UTC [10713] [email protected] DETAIL: There are no running transactions. 

這是我從服務器PostgreSQL的日誌:

2017-10-17 19:14:45.622 CST [7820] WARNING: out of logical replication worker slots 
2017-10-17 19:14:45.622 CST [7820] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:45.670 CST [7821] WARNING: out of logical replication worker slots 
2017-10-17 19:14:45.670 CST [7821] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:45.680 CST [7822] WARNING: out of logical replication worker slots 
2017-10-17 19:14:45.680 CST [7822] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:50.865 CST [7820] WARNING: out of logical replication worker slots 
2017-10-17 19:14:50.865 CST [7820] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:50.917 CST [7821] WARNING: out of logical replication worker slots 
2017-10-17 19:14:50.917 CST [7821] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:50.928 CST [7822] WARNING: out of logical replication worker slots 
2017-10-17 19:14:50.928 CST [7822] HINT: You might need to increase max_logical_replication_workers. 
2017-10-17 19:14:55.871 CST [7820] WARNING: out of logical replication worker slots 
2017-10-17 19:14:55.871 CST [7820] HINT: You might need to increase max_logical_replication_workers. 

和增加max_logical_replication_workers後,我得到這個:

2017-10-17 19:44:45.898 CST [7987] LOG: logical replication table synchronization worker for subscription "sub2", table "t1" has started 
2017-10-17 19:44:45.982 CST [7988] LOG: logical replication table synchronization worker for subscription "myadav_test", table "test_replication" h$ 
2017-10-17 19:44:45.994 CST [7989] LOG: logical replication table synchronization worker for subscription "sub3", table "t1" has started 
2017-10-17 19:44:48.621 CST [7987] ERROR: could not start initial contents copy for table "staging.t1": ERROR: permission denied for schema staging 
2017-10-17 19:44:48.623 CST [7962] LOG: worker process: logical replication worker for subscription 20037 sync 20027 (PID 7987) exited with exit co$ 
2017-10-17 19:44:48.705 CST [7988] ERROR: could not start initial contents copy for table "staging.test_replication": ERROR: permission denied for$ 
2017-10-17 19:44:48.707 CST [7962] LOG: worker process: logical replication worker for subscription 20025 sync 20016 (PID 7988) exited with exit co$ 
2017-10-17 19:44:48.717 CST [7989] ERROR: duplicate key value violates unique constraint "t1_pkey" 
2017-10-17 19:44:48.717 CST [7989] DETAIL: Key (id)=(10) already exists. 
2017-10-17 19:44:48.717 CST [7989] CONTEXT: COPY t1, line 1 
2017-10-17 19:44:48.718 CST [7962] LOG: worker process: logical replication worker for subscription 20038 sync 20027 (PID 7989) exited with exit co$ 
2017-10-17 19:44:51.629 CST [8008] LOG: logical replication table synchronization worker for subscription "sub2", table "t1" has started 
2017-10-17 19:44:51.712 CST [8009] LOG: logical replication table synchronization worker for subscription "myadav_test", table "test_replication" h$ 
2017-10-17 19:44:51.722 CST [8010] LOG: logical replication table synchronization worker for subscription "sub3", table "t1" has started 

現在我終於意識到邏輯複製對於postgres數據庫,但不適用於同一服務器上的其他數據庫。我正在獲取日誌模式的權限問題。

+0

檢查你的PostgreSQL日誌,應該有一些更多的信息 – JustMe

+0

@JustMe感謝快速反應我更新日誌中的問題。 –

+0

在PostgreSQL郵件列表中,您可能會有更多的運氣。 –

回答

1

使用擁有訂閱的用戶的權限應用行更改。默認情況下,這是創建訂閱的用戶。

因此,請確保訂閱擁有足夠權限的用戶。格蘭特需要表格的權利,或者如果您不能打擾,請使擁有所有權利的超級用戶擁有的訂閱。

參見:

+0

感謝您的回覆...我會嘗試讓你知道@Craig Ringer –

+0

是的,它的工作正常我只是使用postgres用戶創建邏輯複製和工作正常..... –