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

简介:

标签

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》

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
4月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
424 158
|
4月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
4月前
|
缓存 监控 关系型数据库
使用MYSQL Report分析数据库性能(中)
使用MYSQL Report分析数据库性能
395 156
|
4月前
|
缓存 监控 关系型数据库
使用MYSQL Report分析数据库性能(上)
最终建议:当前系统是完美的读密集型负载模型,优化重点应放在减少行读取量和提高数据定位效率。通过索引优化、分区策略和内存缓存,预期可降低30%的CPU负载,同时保持100%的缓冲池命中率。建议每百万次查询后刷新统计信息以持续优化
498 161
|
5月前
|
存储 运维 关系型数据库
从MySQL到云数据库,数据库迁移真的有必要吗?
本文探讨了企业在业务增长背景下,是否应从 MySQL 迁移至云数据库的决策问题。分析了 MySQL 的优势与瓶颈,对比了云数据库在存储计算分离、自动化运维、多负载支持等方面的优势,并提出判断迁移必要性的五个关键问题及实施路径,帮助企业理性决策并落地迁移方案。
|
7月前
|
关系型数据库 MySQL 数据库
MySQL数据库上云迁移
本文介绍了将数据库迁移到RDS for Mysql的两种主要方法:停服迁移和不停服迁移。停服迁移适合可短暂中断服务的场景,通过mysqldump或DTS完成;不停服迁移适用于需保持业务连续性的场景,推荐使用DTS实现结构、全量及增量数据迁移。文中详细列出了每种方法的具体操作步骤,帮助企业根据需求选择合适的迁移方案。
267 1
MySQL数据库上云迁移
|
5月前
|
缓存 关系型数据库 MySQL
MySQL数据库性能调优:实用技术与策略
通过秉持以上的策略实施具体的优化措施,可以确保MySQL数据库的高效稳定运行。务必结合具体情况,动态调整优化策略,才能充分发挥数据库的性能潜力。
262 0
|
3月前
|
SQL 关系型数据库 MySQL
阿里云RDS云数据库全解析:产品功能、收费标准与活动参考
与云服务器ECS一样,关系型数据库RDS也是很多用户上云必买的热门云产品之一,阿里云的云数据库RDS主要包含RDS MySQL、RDS SQL Server、RDS PostgreSQL、RDS MariaDB等几个关系型数据库,并且提供了容灾、备份、恢复、监控、迁移等方面的全套解决方案,帮助您解决数据库运维的烦恼。本文为大家介绍阿里云的云数据库 RDS主要产品及计费方式、收费标准以及活动等相关情况,以供参考。
|
4月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
954 152
|
4月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
791 156

推荐镜像

更多