gitlab下的postgresql使用pg_basebackup备份

 

1.尝试备份

su - gitlab-psql
/opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql

-sh-4.2$ /opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql
pg_basebackup: error: connection to server on socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432" 
failed: FATAL:  number of requested standby connections exceeds max_wal_senders (currently 0)


su - gitlab-psql
psql -h /var/opt/gitlab/postgresql -d gitlabhq_production
gitlabhq_production=# show max_wal_senders;
 max_wal_senders 
-----------------
 0
(1 row)

修改配置文件

[root@node1 gitlab]# vi /var/opt/gitlab/postgresql/data/postgresql.conf
我这里修改为2
max_wal_senders = 2
wal_level = replica

重启
[root@node1 data]# gitlab-ctl restart postgresql
ok: run: postgresql: (pid 30564) 0s

登录重新查看参数
gitlabhq_production=# show max_wal_senders;
max_wal_senders
-----------------
2
(1 row)

 

2.再次备份

su - gitlab-psql
/opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql


-sh-4.2$ /opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql
pg_basebackup: error: connection to server on socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432" failed: FATAL:  
no pg_hba.conf entry for replication connection from host "[local]", user "gitlab-psql", no encryption

修改配置文件 pg_hba.conf 在最后添加如下项目 

# replication privilege.
local   replication     all                                     trust

重启pg
gitlab-ctl stop postgresql
gitlab-ctl start postgresql

 

3.继续报错误

-sh-4.2$ /opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/7000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: error: could not send replication command "CREATE_REPLICATION_SLOT "pg_basebackup_3021" TEMPORARY PHYSICAL RESERVE_WAL": ERROR:  all replication slots are in use
HINT:  Free one or increase max_replication_slots.
pg_basebackup: removing data directory "/tmp/20250320"

 

修改配置文件
vi /var/opt/gitlab/postgresql/data/postgresql.conf

max_replication_slots = 10

重启pg
gitlab-ctl stop postgresql
gitlab-ctl start postgresql

 

最后备份成功:

-sh-4.2$ /opt/gitlab/embedded/bin/pg_basebackup -D "/tmp/20250320" -Ft -Pv -h /var/opt/gitlab/postgresql
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/8000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_6809"
110091/110091 kB (100%), 1/1 tablespace                                         
pg_basebackup: write-ahead log end point: 0/8000138
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed

 

总结:
若要使用pg_basebackup进行备份需要如下配置:
配置文件:postgresql.conf

max_replication_slots = 10
max_wal_senders = 2
wal_level = replica

具体数字根据实际情况进行调整

 

配置文件pg_hba.conf 在最后添加如下项目 

# replication privilege.
local   replication     all                                     trust

 

posted @ 2025-03-20 14:43  slnngk  阅读(76)  评论(0)    收藏  举报