PolarDB开源数据库进阶课12 集群版转换为单机版

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
简介: 本文介绍了如何将“共享存储实例”转换为“本地存储实例”,实验环境依赖于Docker容器中的loop设备模拟共享存储。具体步骤包括准备本地目录、停库、拷贝数据、修改配置文件并启动实例。通过这些操作,可以实现从共享存储到本地存储的平滑转换。相关系列文章详细记录了PolarDB RAC一写多读集群的搭建与管理,提供了丰富的实战经验。

背景

穷鬼玩PolarDB RAC一写多读集群系列已经写了几篇:

本篇文章介绍一下如何把“共享存储实例”转换为“本地存储实例”? 实验环境依赖 《在Docker容器中用loop设备模拟共享存储》 , 如果没有环境, 请自行参考以上文章搭建环境.

本文还依赖如下文章:

DEMO

b站视频链接

Youtube视频链接

在pb3容器进行演示. 假设在pb3 容器中的standby节点已经被成功激活. 接下来将介绍把这个“共享存储实例”转换为“本地存储实例”.

预览当前目录结构:

# 数据放在PFS内  
$ sudo pfs -C disk ls /nvme2n1/shared_data/  
   Dir  1     256               Tue Dec 24 09:52:52 2024  pg_multixact  
   Dir  1     768               Tue Dec 24 14:29:01 2024  pg_wal  
   Dir  1     0                 Tue Dec 24 09:52:54 2024  pg_commit_ts  
   Dir  1     512               Tue Dec 24 14:46:02 2024  polar_fullpage  
   Dir  1     0                 Tue Dec 24 09:52:57 2024  pg_replslot  
   Dir  1     0                 Tue Dec 24 09:52:57 2024  pg_tblspc  
  File  1     227               Tue Dec 24 09:52:57 2024  polar_non_exclusive_backup_label  
  File  1     257               Tue Dec 24 09:52:57 2024  postgresql.auto.conf  
   Dir  1     0                 Tue Dec 24 09:52:57 2024  pg_twophase  
   Dir  1     128               Tue Dec 24 09:52:57 2024  pg_xact  
   Dir  1     128               Tue Dec 24 14:45:55 2024  pg_logindex  
   Dir  1     7808              Tue Dec 24 09:52:57 2024  global  
   Dir  1     512               Tue Dec 24 09:52:58 2024  base  
total 16384 (unit: 512Bytes)  
  
# 本地实例放在本地目录中  
$ ls ~/standby  
backup_label.old  current_logfiles  pg_dynshmem    pg_log       pg_multixact  pg_serial     pg_stat_tmp  PG_VERSION         polar_fullpage        polar_shmem_stat_file  postmaster.opts  
backup_manifest   global            pg_hba.conf    pg_logical   pg_notify     pg_snapshots  pg_subtrans  pg_xact            polar_rel_size_cache  postgresql.auto.conf   postmaster.pid  
base              pg_commit_ts      pg_ident.conf  pg_logindex  pg_replslot   pg_stat       pg_tblspc    polar_cache_trash  polar_settings.conf   postgresql.conf

设计目标目录结构

# 数据放在本地 /data/standby/shared_data 目录中  
  
# 本地实例还是放在本地 ~/standby 目录中

1、准备存放PFS 共享盘数据库目录的本地目录

mkdir -p /data/standby/shared_data

2、停库

pg_ctl stop -m fast -D ~/standby

3、把PFS的内容拷贝到本地目录, 并修改owner和权限

pfs cp -r /nvme2n1/shared_data /data/standby/  
  
chmod 700 /data/standby/shared_data  
chown -R postgres:postgres /data/standby/shared_data

预览新的本地共享数据目录结构

$ ll /data/standby/shared_data  
total 8  
drwx------ 15 postgres postgres  480 Dec 24 15:55 ./  
drwxr-xr-x  3 postgres postgres   96 Dec 24 15:48 ../  
drwxr-xr-x  6 postgres postgres  192 Dec 24 15:55 base/  
drwxr-xr-x 63 postgres postgres 2016 Dec 24 15:55 global/  
drwxr-xr-x  2 postgres postgres   64 Dec 24 15:55 pg_commit_ts/  
drwxr-xr-x  3 postgres postgres   96 Dec 24 15:55 pg_logindex/  
drwxr-xr-x  4 postgres postgres  128 Dec 24 15:55 pg_multixact/  
drwxr-xr-x  2 postgres postgres   64 Dec 24 15:55 pg_replslot/  
drwxr-xr-x  2 postgres postgres   64 Dec 24 15:55 pg_tblspc/  
drwxr-xr-x  2 postgres postgres   64 Dec 24 15:55 pg_twophase/  
drwxr-xr-x  8 postgres postgres  256 Dec 24 15:55 pg_wal/  
drwxr-xr-x  3 postgres postgres   96 Dec 24 15:55 pg_xact/  
drwxr-xr-x  6 postgres postgres  192 Dec 24 15:55 polar_fullpage/  
-rw-r--r--  1 postgres postgres  227 Dec 24 15:55 polar_non_exclusive_backup_label  
-rw-r--r--  1 postgres postgres  257 Dec 24 15:55 postgresql.auto.conf

共享数据目录中这两个文件没什么用可以删掉

rm /data/standby/shared_data/polar_non_exclusive_backup_label  
rm -f /data/standby/shared_data/postgresql.auto.conf

4、修改 ~/standby 内配置文件

postgresql.conf

echo "  
huge_pages=off  
port=5432  
polar_hostid=3  
polar_enable_shared_storage_mode=on  
polar_disk_name='home'  # 修改
# polar_storage_cluster_name='disk'   # 修改  
polar_datadir='file-dio:///data/standby/shared_data/'    # 修改  
polar_vfs.localfs_mode=true    # 修改   
shared_preload_libraries='\$libdir/polar_vfs,\$libdir/polar_worker'  
logging_collector=on  
log_line_prefix='%p\t%r\t%u\t%m\t'  
log_directory='pg_log'  
listen_addresses='0.0.0.0'  
max_connections=200  
# 下面几个参数解决replica不能promote的问题, 因为RO依赖logindex.  
polar_logindex_mem_size=64MB  
polar_xlog_queue_buffers=64MB  
polar_xlog_page_buffers=64MB  
# 使用pfs管理块设备时可以关掉 full page write 和 polar_has_partial_write  . 或者使用zfs这类cow的文件系统时也可以关掉以下2个配置.  
full_page_writes = off  
polar_has_partial_write = on  # 修改
polar_resource_manager.enable_resource_manager=off
" >> ~/standby/postgresql.conf

5、启动实例

pg_ctl start -D ~/standby

将“共享存储实例”转换为“本地存储实例”完成

$ psql  
psql (PostgreSQL 15.10 (PolarDB 15.10.2.0 build d4f5477d debug) on aarch64-linux-gnu)  
Type "help" for help.  
  
postgres=# \dt  
         List of relations  
 Schema | Name  | Type  |  Owner     
--------+-------+-------+----------  
 public | t     | table | postgres  
 public | t1    | table | postgres  
 public | t2    | table | postgres  
 public | t_new | table | postgres  
 public | tbl   | table | postgres  
(5 rows)  
  
postgres=# show polar_datadir;  
             polar_datadir               
---------------------------------------  
 file-dio:///data/standby/shared_data/  
(1 row)  
  
postgres=# create table t3(id int);  
CREATE TABLE  
postgres=# insert into t3 select generate_series(1,10);  
INSERT 0 10

验证完转换成功后, 可以把本地的pfsd进行退出.

PS: 如果你想比较平滑的完成转换, 可用考虑采用先建立本地盘的standby然后激活的方式. 参考 《如何搭建PolarDB容灾(Standby)节点》

这还不是完全的单机版, 完全的单机版参考: 《穷鬼玩PolarDB RAC一写多读集群系列 | 原来PolarDB还有单机版?》

参考

《穷鬼玩PolarDB RAC一写多读集群系列 | 在Docker容器中用loop设备模拟共享存储》

《穷鬼玩PolarDB RAC一写多读集群系列 | 如何搭建PolarDB容灾(Standby)节点》

《穷鬼玩PolarDB RAC一写多读集群系列 | 共享存储在线扩容》

《穷鬼玩PolarDB RAC一写多读集群系列 | 计算节点 Switchover》

《穷鬼玩PolarDB RAC一写多读集群系列 | 在线备份》

《穷鬼玩PolarDB RAC一写多读集群系列 | 在线归档》

《穷鬼玩PolarDB RAC一写多读集群系列 | 实时归档》

《穷鬼玩PolarDB RAC一写多读集群系列 | 时间点恢复(PITR)》

《穷鬼玩PolarDB RAC一写多读集群系列 | 读写分离》

《穷鬼玩PolarDB RAC一写多读集群系列 | 主机全毁, 只剩共享存储的PolarDB还有救吗?》

《穷鬼玩PolarDB RAC一写多读集群系列 | 激活容灾(Standby)节点》

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
4月前
|
存储 关系型数据库 分布式数据库
喜报|阿里云PolarDB数据库(分布式版)荣获国内首台(套)产品奖项
阿里云PolarDB数据库管理软件(分布式版)荣获「2024年度国内首版次软件」称号,并跻身《2024年度浙江省首台(套)推广应用典型案例》。
|
2月前
|
Cloud Native 关系型数据库 MySQL
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
PolarDB-X 是阿里云推出的云原生分布式数据库,支持PB级存储扩展、高并发访问与数据强一致,助力企业实现MySQL平滑迁移。现已开放免费体验,点击即享高效、稳定的数据库升级方案。
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
|
5月前
|
关系型数据库 分布式数据库 数据库
再获殊荣,阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
内存池化技术新突破,阿里云PolarDB蝉联SIGMOD最佳论文奖
|
2月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
4月前
|
关系型数据库 分布式数据库 数据库
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
阿里云PolarDB凭借全球首创基于CXL Switch的分布式内存池技术,在SIGMOD 2025上荣获工业赛道“最佳论文奖”,连续两年蝉联该顶会最高奖项。其创新架构PolarCXLMem打破传统RDMA技术瓶颈,性能提升2.1倍,并已落地应用于内存池化场景,推动大模型推理与多模态存储发展,展现CXL Switch在高速互联中的巨大潜力。
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
|
2月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
125 3
|
2月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
3月前
|
存储 运维 关系型数据库
从MySQL到云数据库,数据库迁移真的有必要吗?
本文探讨了企业在业务增长背景下,是否应从 MySQL 迁移至云数据库的决策问题。分析了 MySQL 的优势与瓶颈,对比了云数据库在存储计算分离、自动化运维、多负载支持等方面的优势,并提出判断迁移必要性的五个关键问题及实施路径,帮助企业理性决策并落地迁移方案。
|
2月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
|
2月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。

相关产品

  • 云原生数据库 PolarDB