线下PG迁移到阿里云RDS PG - 兼容性、性能评估、迁移

本文涉及的产品
云原生多模数据库 Lindorm,多引擎 多规格 0-4节点
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 MongoDB,通用型 2核4GB
简介:

标签

PostgreSQL , 迁移 , 阿里云RDS PG


背景

用户如果需要将线下的PG数据库迁移到阿里云RDS PG,应该评估哪些东西,如何迁移?

1 规格、性能评估

主要评估线下PG实例所在主机的性能指标

1、CPU主频

2、CPU核数

3、磁盘使用容量

4、网络带宽

5、磁盘读写IOPS

6、磁盘读写带宽

这些指标应该尽量与阿里云RDS PG对齐。

如果线下PG开启了异步提交时,对应的阿里云RDS PG IOPS可能需要更多(与每秒提交的写事务相关)。

2 兼容性评估

1、数据库版本

如果版本不一致,请参考PostgreSQL 版本的 release notes,看看有哪些不兼容的地方,一般不兼容的地方,PG会在release notes里面给出migration 方法。

2、插件

用户需要的插件,在RDS PG中是否存在,如果在RDS PG中没有,那么两种选择1. 提工单看是否可以加上插件,2. 看看业务上是否可以修正,去掉这个插件的依赖。

3、插件版本

线下PG与RDS PG的插件版本不一样时,建议根据插件的RELEASE NOTES,判断是否需要修改业务?

4、业务需要的数据库用户权限

(超级用户、OR 普通用户,。。。)

RDS PG给的最大权限是rds_superuser,权限介于数据库的superuser 与 普通用户之间。

5、本土化参数

这个主要与数据库有关,建库时,使用的是C还是其他本地化collation。collation决定了排序、货币格式等。

创建数据库时可以指定,如果模板库不是你要的,那么你需要用template0来创建。

postgres=# create database db1 with template=template0 encoding='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C' ;  
CREATE DATABASE  

https://www.postgresql.org/docs/10/static/charset.html

postgres=# \l+  
                                                                   List of databases  
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   |  Size   | Tablespace |                Description                   
-----------+----------+----------+------------+------------+-----------------------+---------+------------+--------------------------------------------  
 postgres  | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 |                       | 127 GB  | pg_default | default administrative connection database  
 template0 | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 | =c/postgres          +| 7561 kB | pg_default | unmodifiable empty database  
           |          |          |            |            | postgres=CTc/postgres |         |            |   
 template1 | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 | =c/postgres          +| 7561 kB | pg_default | default template for new databases  
           |          |          |            |            | postgres=CTc/postgres |         |            |   
(3 rows)  

同时对于wchar的模糊查询,也需要用collate 非 C设置。

《PostgreSQL 模糊查询最佳实践 - (含单字、双字、多字模糊查询方法)》

6、数据库字符集

如果线上线下字符集不一致,需要字符集转换。建议使用一致的字符集。创建数据库时可以指定。

postgres=# \l+  
                                                                   List of databases  
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   |  Size   | Tablespace |                Description                   
-----------+----------+----------+------------+------------+-----------------------+---------+------------+--------------------------------------------  
 postgres  | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 |                       | 127 GB  | pg_default | default administrative connection database  
 template0 | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 | =c/postgres          +| 7561 kB | pg_default | unmodifiable empty database  
           |          |          |            |            | postgres=CTc/postgres |         |            |   
 template1 | postgres | UTF8     | en_US.UTF8 | en_US.UTF8 | =c/postgres          +| 7561 kB | pg_default | default template for new databases  
           |          |          |            |            | postgres=CTc/postgres |         |            |   
(3 rows)  
postgres=# create database db1 with template=template0 encoding='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C' ;  
CREATE DATABASE  

7、CLIENT相关的参数

这些参数决定了一些使用上的风格,建议迁移前后做一下对比,保证兼容。

比如bytea_output,可以选择为十六进制输出,也可以选择为转义输出格式。

#------------------------------------------------------------------------------  
# CLIENT CONNECTION DEFAULTS  
#------------------------------------------------------------------------------  
  
# - Statement Behavior -  
  
#search_path = '"$user", public'        # schema names  
#row_security = on  
#default_tablespace = ''                # a tablespace name, '' uses the default  
#temp_tablespaces = ''                  # a list of tablespace names, '' uses  
                                        # only default tablespace  
#check_function_bodies = on  
#default_transaction_isolation = 'read committed'  
#default_transaction_read_only = off  
#default_transaction_deferrable = off  
#session_replication_role = 'origin'  
#statement_timeout = 0                  # in milliseconds, 0 is disabled  
#lock_timeout = 0                       # in milliseconds, 0 is disabled  
#idle_in_transaction_session_timeout = 0        # in milliseconds, 0 is disabled  
#vacuum_freeze_min_age = 50000000  
#vacuum_freeze_table_age = 150000000  
#vacuum_multixact_freeze_min_age = 5000000  
#vacuum_multixact_freeze_table_age = 150000000  
#bytea_output = 'hex'                   # hex, escape  
#xmlbinary = 'base64'  
#xmloption = 'content'  
#gin_fuzzy_search_limit = 0  
#gin_pending_list_limit = 4MB  
  
# - Locale and Formatting -  
  
datestyle = 'iso, mdy'  
#intervalstyle = 'postgres'  
timezone = 'PRC'  
#timezone_abbreviations = 'Default'     # Select the set of available time zone  
                                        # abbreviations.  Currently, there are  
                                        #   Default  
                                        #   Australia (historical usage)  
                                        #   India  
                                        # You can create your own file in  
                                        # share/timezonesets/.  
#extra_float_digits = 0                 # min -15, max 3  
#client_encoding = sql_ascii            # actually, defaults to database  
                                        # encoding  
  
# These settings are initialized by initdb, but they can be changed.  
lc_messages = 'en_US.UTF8'                      # locale for system error message  
                                        # strings  
lc_monetary = 'en_US.UTF8'                      # locale for monetary formatting  
lc_numeric = 'en_US.UTF8'                       # locale for number formatting  
lc_time = 'en_US.UTF8'                          # locale for time formatting  
  
# default configuration for text search  
default_text_search_config = 'pg_catalog.english'  
# - Shared Library Preloading -  
  
#shared_preload_libraries = ''  # (change requires restart)  
#local_preload_libraries = ''  
#session_preload_libraries = ''  
  
# - Other Defaults -  
  
#dynamic_library_path = '$libdir'  
  
#jit = on                               # allow JIT compilation  
#jit_provider = 'llvmjit'               # JIT implementation to use  
#------------------------------------------------------------------------------  
# VERSION AND PLATFORM COMPATIBILITY  
#------------------------------------------------------------------------------  
  
# - Previous PostgreSQL Versions -  
  
#array_nulls = on  
#backslash_quote = safe_encoding        # on, off, or safe_encoding  
#default_with_oids = off  
#escape_string_warning = on  
#lo_compat_privileges = off  
#operator_precedence_warning = off  
#quote_all_identifiers = off  
#standard_conforming_strings = on  
#synchronize_seqscans = on  
  
# - Other Platforms and Clients -  
  
#transform_null_equals = off  
#------------------------------------------------------------------------------  
# CUSTOMIZED OPTIONS  
#------------------------------------------------------------------------------  
  
# Add settings for extensions here  

3 迁移

大致步骤如下

1、测试迁移,全量数据迁移

2、全链路测试

3、清除数据,正式迁移数据

4、比对数据一致性

增量迁移可以考虑阿里云的工具,如rds_dbsync, DTS服务,或者采用pglogical。

https://help.aliyun.com/document_detail/26624.html

参考

https://www.postgresql.org/docs/10/static/charset.html

《PostgreSQL 模糊查询最佳实践 - (含单字、双字、多字模糊查询方法)》

《[未完待续] PostgreSQL pglogical 逻辑复制实现跨版本升级》

《MySQL准实时同步到PostgreSQL, Greenplum的方案之一 - rds_dbsync》

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
28天前
|
SQL 关系型数据库 MySQL
阿里云MySQL数据库价格、购买、创建账号密码和连接数据库教程
阿里云数据库使用指南:购买MySQL、SQL Server等RDS实例,选择配置和地区,完成支付。创建数据库和账号,设置权限。通过DMS登录数据库,使用账号密码访问。同地域VPC内的ECS需将IP加入白名单以实现内网连接。参考链接提供详细步骤。
367 3
|
16天前
|
存储 关系型数据库 MySQL
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
|
16天前
|
缓存 关系型数据库 MySQL
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
|
22天前
|
存储 关系型数据库 数据库
超1/3中国500强企业都在用的「汇联易」,为什么选用阿里云RDS?
迎峰而上:汇联易依托阿里云RDS通用云盘,加速业务智能化升级
超1/3中国500强企业都在用的「汇联易」,为什么选用阿里云RDS?
|
28天前
|
弹性计算 关系型数据库 MySQL
阿里云MySQL云数据库优惠价格、购买和使用教程分享!
阿里云数据库使用流程包括购买和管理。首先,选购支持MySQL、SQL Server、PostgreSQL等的RDS实例,如选择2核2GB的MySQL,设定地域和可用区。购买后,等待实例创建。接着,创建数据库和账号,设置DB名称、字符集及账号权限。最后,通过DMS登录数据库,填写账号和密码。若ECS在同一地域和VPC内,可内网连接,记得将ECS IP加入白名单。
429 2
|
28天前
|
SQL 关系型数据库 MySQL
阿里云mysql数据库价格购买和使用教程
阿里云数据库使用指南:购买MySQL、SQL Server等RDS实例,通过选择配置、地域和可用区完成购买。创建数据库和账号,分配权限。使用DMS登录数据库,进行管理操作。确保ECS与RDS在同一地域的VPC内,配置白名单实现内网连接。详细步骤见官方文档。
629 1
|
28天前
|
SQL 数据可视化 Apache
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
阿里云数据库 SelectDB 内核 Doris 的 SQL 方言转换工具, Doris SQL Convertor 致力于提供高效、稳定的 SQL 迁移解决方案,满足用户多样化的业务需求。兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移。
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
|
1月前
|
关系型数据库 MySQL 数据库
使用阿里云的数据传输服务DTS(Data Transmission Service)进行MySQL 5.6到MySQL 8.0的迁移
【2月更文挑战第29天】使用阿里云的数据传输服务DTS(Data Transmission Service)进行MySQL 5.6到MySQL 8.0的迁移
219 2
|
1月前
|
弹性计算 小程序 开发者
阿里云服务器性能测评:25M带宽阿里云云服务器支持多少人访问?
在深入探讨25M带宽云服务器的性能时,我们首先要明确一个核心概念:带宽与服务器能够支持的同时访问量之间存在着直接的关联。那么,大家可能会好奇,带宽为25M的云服务器究竟能够支持多少用户同时访问呢?
122 0
|
1月前
|
SQL 关系型数据库 MySQL
购买阿里云RDS实例
购买阿里云RDS实例
165 2

推荐镜像

更多