su - postgres
-bash-4.2$ cat .bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/data/postgresql/pgdata/pg-5432
export PGDATA
export PATH=/usr/pgsql-14/bin:$PATH# If you want to customize your settings,# Use the file below. This is not overridden# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
主节点数据库 (pg-151) 配置
初始化数据库
initdb -D/data/postgresql/pgdata/pg-5432/
修改配置文件和 hba postgresql.conf
pg_hba.conf (用于设置主机访问)
localallall trust
host allall192.168.28.0/24 md5
# IPv4 local connections:
host allall127.0.0.1/32 trust
# IPv6 local connections:
host allall ::1/128 trust
# Allow replication connections from localhost, by a userwith the
# replication privilege.
local replication all trust
host replication repluser 192.168.28.0/24 md5
host replication all127.0.0.1/32 trust
host replication all ::1/128 trust
创建复制用户 (master 节点)
先运行 matser 数据库 pg_ctl start 再创建复制用户
psql (14.10)
Type"help"forhelp.
postgres=# create user repluser with replication password 'repluser';
-bash-4.2$ pg_ctl stop
waiting for server to shut down.... done
[root@k8s-master01 pgsql_cluster]# pcs status
Cluster name: pgcluster
Stack: corosync
Current DC: pg-153 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum
Last updated: Tue Nov 21 16:59:30 2023
Last change: Tue Nov 21 16:59:29 2023 by root via crm_attribute on pg-152
3 nodes configured
7 resource instances configured
Online: [ pg-151 pg-152 pg-153 ]
Full list of resources:
Master/Slave Set: msPostgresql [pgsql]
Masters: [ pg-152 ]
Slaves: [ pg-153 ]
Stopped: [ pg-151 ]
Resource Group: master-group
vip-master (ocf::heartbeat:IPaddr2): Started pg-152
Resource Group: slave-group
vip-slave (ocf::heartbeat:IPaddr2): Started pg-153
Failed Resource Actions:
* pgsql_monitor_3000 on pg-151 'not running' (7): call=92, status=complete, exitreason='',
last-rc-change='Tue Nov 21 16:58:59 2023', queued=0ms, exec=0ms
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
注意 master 节点挂掉之后,使用 crm_mon -Arf -1 命令看到末尾有 "You have to remove /var/lib/pgsql/tmp/PGSQL.lock file to force start." 字样,master 宕机启动时,需要删除临时锁文件方可进行集群角色转换。即执行 rm -rf /var/lib/pgsql/tmp/PGSQL.lock 拉起数据库不需要执行 pg_ctl start, 只需要 pcs resource cleanup
[root@k8s-master01 pgsql_cluster]# pcs resource cleanup
Cleaned up all resources on all nodes
Waiting for 1 reply from the CRMd. OK
[root@k8s-master01 pgsql_cluster]# pcs status
Cluster name: pgcluster
Stack: corosync
Current DC: pg-153 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum
Last updated: Tue Nov 21 17:01:57 2023
Last change: Tue Nov 21 17:01:26 2023 by hacluster via crmd on pg-151
3 nodes configured
7 resource instances configured
Online: [ pg-151 pg-152 pg-153 ]
Full list of resources:
Master/Slave Set: msPostgresql [pgsql]
Masters: [ pg-152 ]
Slaves: [ pg-153 ]
Stopped: [ pg-151 ]
Resource Group: master-group
vip-master (ocf::heartbeat:IPaddr2): Started pg-152
Resource Group: slave-group
vip-slave (ocf::heartbeat:IPaddr2): Started pg-153
Failed Resource Actions:
* pgsql_start_0 on pg-151 'unknown error' (1): call=127, status=complete, exitreason='My data may be inconsistent. You have to remove /var/lib/pgsql/tmp/PGSQL.lock file to force start.',
last-rc-change='Tue Nov 21 17:01:28 2023', queued=1ms, exec=615ms
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
Host (ClaudeCode)
│
├── Client ←──JSON-RPC──→ context7 Server
├── Client ←──JSON-RPC──→ sequential-thinking Server
└── Client ←──JSON-RPC──→ your Server
# ✅ 好的 description(包含触发场景)description:>
Comprehensive document creation and editing with tracked changes.
Use when Claude needs to work with .docx files for:
(1) Creating new documents, (2) Modifying content,
(3) Working with tracked changes, (4) Adding comments# ❌ 差的 description(太模糊)description:Ausefuldocumenttool
## Editing documents
For simple edits, modify XML directly.
**For tracked changes**: See [REDLINING.md](references/REDLINING.md)
**For OOXML details**: See [OOXML.md](references/OOXML.md)
vim postgres.conf
wal_level = logical
max_wal_senders = 100 #max_wal_senders大于max_replication_slots
vim pg_hba.conf
host all repl 订阅者IP/32 md5
重启 pgsql ,配置生效
su postgres
pg_ctl restart -D/data/postgresql/pgdata/pg-5433/
发布者节点创建用户,赋权
su postgres
psql -P 5433
psql (16.9 (Ubuntu 16.9-0ubuntu0.24.10.1))
Type "help" for help.
#创建用户
postgres=# create user repuser password 'repuser' replication;
CREATE ROLE
#在postgres库中创建表,并插入一条数据
postgres=# create table test1(id int primary key,name varchar(10) );
postgres=# insert into test1 values(1,'a');# 赋予复制用户select表权限
postgres=# grant select on table test1 to repuser;
创建表 test1 的发布
create publication pub_test01 fortable test1;
订阅端
修改 posetgres.conf
vim postgres.conf
max_replication_slots=8
max_logical_replication_workers=10
max_worker_processes=8
select*from pg_replication_slots; --查看所有复制槽select*from pg_stat_replication; --查看复制槽的同步状态select*from pg_publication; --查看所有发布select*from pg_publication_tables; --查看所有发布对应的表select usename,a.pubname,c.*,pubinsert,pubupdate,pubdelete,pubtruncate from pg_publication a,pg_user b,pg_publication_tables c where a.pubowner=b.usesysid and c.pubname=a.pubname;
订阅端
select*from pg_subscription; --查看所有订阅select srrelid::regclass from pg_subscription_rel; --查看订阅的所有表select usename,datname,subname,srrelid::regclass,srsublsn,subconninfo from pg_subscription a,pg_user b,pg_subscription_rel c ,pg_database d where a.oid=c.srsubid and a.subowner=b.usesysid and a.subdbid=d.oid;
删除发布订阅
删除订阅
订阅在运行的情况下,需要一下操作:
ALTER SUBSCRIPTION pub_test01;
##首先需要停止当前的订阅ALTER SUBSCRIPTION subs_test01 (slot_name =NONE);
##然后将订阅的复制槽设置成空
drop subscription subs_test01;
##最后就可以删除订阅了。##另外一个问题,复制订阅中,如果订阅的服务停止,或无法再次连接的情况下,需要关注 发布端的数据wal log 无法清理以及膨胀的问题。##所以在复制订阅中的订阅停止后,如果确认订阅无法再次恢复,或者不确认多长时间恢复,则需要删除复制槽select * from pg_replication_slots;
selectpg_drop_replication_slot(slot_name) from pg_replication_slots where slot_name = 'pub_test01';
vim /home/postgres/.bashrc
[ -f /etc/profile ] && source /etc/profile
export PATH=/usr/lib/postgresql/16/bin:$PATH# If you want to customize your settings,# Use the file below. This is not overridden# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
设置 sudo 免密
vim /etc/sudoers
#行末新增
postgres ALL=(ALL) NOPASSWD: ALL
su postgres
cd ~
#备库从主库同步WAL日志使用,主备倒换后,主库降备库,新备库使用,所以备库也配置
touch .pgpass
vim .pgpass
192.168.28.11:5433:*:replica:replica192.168.28.12:5433:*:replica:replica192.168.28.13:5433:*:replica:replica
su postgres
cd ~
cat ./.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDnvcOPSQgi2zKWqNHsFjKC0zp4X5+yG1eNf5fEr25r2+NlBGMRrBFh2pONh2pWSLiglbhOZA5Pr1ILpllwP34eiGNjxTp0ys0U1YjnOuvgY7iwwR+xkXJmywDb0g0ALSEi3TS0lu5z3u4mBcW03q4m/oS++Fi+7ieDinyQAZOXXOyvj8k7g7/NiUXzONN83do/+KC5htVm9Q77A2DrDmZWQGbypMKQYPY66RjcWvApPOVYbrUxHlndq3fU4IhHPOVwiAdpHm5bh8dyb9k1FWcIS9sxLVm4KsUbt99VeDC8ri7iglMKen+gcktIyo80rGRoIdzJrD6JPP8cTlhpTwV/uW42kWgS9lZ8I/Ahk7lWoDdiF/pVNkMiiTOgZ2/YGV88CE0khpOtRl3nPHFlUZHi1QLdfH9omI0FZWeLYAuQbKWBGZ8GgfAweKjEtMy/J43NO5qGK6JZ0KB2ve03JowCGbW65cmTuPQgz3Hwo5I0fv3YEy88LK9nVnLub44zunGqJ4JBAc2H/WrmSqLYtLtljo/5EuKmc34SS75WimY9wh1nTmhVPODuLzurXjz28zx245tkcLeImbn4C8Gge4I7TgtPj8VkWTXC6WlrTTLjebLuMjYR3qFfuGqfD2vuLEHU4CBGHAnpDCG51v96gBpw+m9Cman6f9KvA3iZRBOXHw== postgres@k8s-node01
在主从服务器上添加备份服务器的公钥
root@k8s-master01:~# su postgres
postgres@k8s-master01:/root$cd ~
postgres@k8s-master01:~$vim ./.ssh/authorized_keys
然后是 cc 添加 mcp 的指令 用别的工具的自行配置下吧 (以下地址已不可用 请用更新 3 中的网站)
claude mcp add-json augment-context-engine-mcp --scope user ‘{“type”:“stdio”,“command”:“auggie”,“args”:[“–mcp”],“env”:{“AUGMENT_API_TOKEN”:“05e8092b03bb0c314bb9f762b2edf4c4”,“AUGMENT_API_URL”:“https://ace-test.heroman.wtf/”}}’