开发者社区> 德哥> 正文

线下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》

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
《阿里云PostgreSQL、PPAS、HDB for PG生态、产品、案例、实践》电子版地址
阿里云PostgreSQL、PPAS、HDB for PG生态、产品、案例、实践
26 0
阿里云数据库RDS PG联合电商SaaS领导者班牛,助力1500+品牌数智化
班牛选用阿里云数据库RDS PostgreSQL作为基建,支撑起了一万多商户的数据隔离,助力班牛PaaS化诸多场景落地。
1324 0
只需五步!将数据仓库从 Redshift迁移到阿里云AnalyticDB for PG
作者:陆封,阿里云数据库资深技术专家
334 0
2020 PG亚洲大会集结阿里云PG最强直播天团
2020PG亚洲大会阿里云数据库专场正在直播!
15050 0
阿里云数据库应用案例3 - PG大客户专属数据库集群
行业:  通用行业.    应用场景:  全托管数据库无法满足某些场景的需求: 1、客户自定义需求, PG 数据库引擎具备插件扩展能力, 但是RDS内置的插件为常用插件, 无法覆盖某些客户的需求,例如: CITUS 分布式数据库插件(许可问题), timescaledb 时序数据库插件(许可问题), trodb mongo兼
565 0
数据价值挖掘利器!阿里云实时数仓AnalyticDB PG版新一代计算引擎Odyssey技术解析
随着数字经济时代的到来,越来越多的应用依赖数据分析来挖掘数据的价值。作为大数据存储、在线分析的重要基础系统,分析型数据库(OLAP)为数据价值的在线化提供重要的技术平台。
1176 0
阿里云RDS PG 10 HA版 - 使用postgres_fdw外部表插件 - 实例内跨库访问其他库的表
标签 PostgreSQL , postgres_fdw , 阿里云 , 内核安全限制 背景 阿里云rds pg内核安全上做了限制,只能访问当前实例的其他库,所以使用dblink, postgres_fdw时,虽然PG功能上是可以访问其他远程实例的,但是阿里云RDS PG限制了只能访问当前实例。 另一方面,当前实例是HA版本,并且是云化版本,所以IP,PORT都可能在发生迁移、切换后发
468 0
阿里云rds PG, PPAS PostgreSQL 同实例,跨库数据传输、访问(postgres_fdw 外部表)
标签 PostgreSQL , 阿里云rds , pg , ppas , 跨库查询 , 外部表 , postgres_fdw 背景 如果你使用pg或ppas作为实时数仓,并且有跨库数据传输(ods, dw, dm 分层结构)的需求,可以使用postgres_fdw外部表实现,不需要使用ETL工具对数据进行抽取和导入这种无用功操作。 postgres_fdw是PG的一个外部表插件,可读,
1054 0
+关注
德哥
公益是一辈子的事, I am digoal, just do it.
文章
问答
来源圈子
更多
让用户数据永远在线,让数据无缝的自由流动
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
Elastic与阿里云合作宣传信息白皮书
立即下载
阿里云&信通院《Serverless数据库技术研究报告》
立即下载
降本增效,阿里云数据治理Workshop上海站
立即下载