首页 > 数据库 >MICROSOFT SQL SERVER TO POSTGRESQL MIGRATION USING PGLOADER

MICROSOFT SQL SERVER TO POSTGRESQL MIGRATION USING PGLOADER

时间:2023-06-30 10:31:45浏览次数:41  
标签:POSTGRESQL string -- btpg10 PGLOADER SERVER pgloader --------- public

To continue our migration series, today’s post will focus on pgloader. Pgloader is another Open Source data migration utility for PostgreSQL from MySQL and SQL Server. Today’s demo will migrate a sample database (StackOverflow) from MS SQL Server 2019 to Postgresql v10.

MICROSOFT SQL SERVER TO POSTGRESQL MIGRATION USING PGLOADER_SQL

 

 

To continue our migration series, today’s post will focus on pgloader. Pgloader is another Open Source data migration utility for PostgreSQL from MySQL and SQL Server. Today’s demo will migrate a sample database (StackOverflow) from MS SQL Server 2019 to Postgresql v10.

StackOverflow contains the following tables

1> use [StackOverflow]
2> go
Changed database context to 'StackOverflow'.
1> select name from sys.tables order by name
2> go
---------------------------------------------------------------------------
Badges
Comments
LinkTypes
PostLinks
Posts
PostTypes
Users
Votes VoteTypes

(9 rows affected)
  1. Install pgloader – on ubuntu this is a simple apt-get install pgloader but you can also build from source
  2. Pglolader uses the FreeTDS driver (on RedHat I needed to install the following freetds freetds-libs freetds-common)
  3. Pgloader has multiple options
# pgloader

pgloader [ option ... ] command-file ...
pgloader [ option ... ] SOURCE TARGET
  --help -h                       boolean  Show usage and exit.
  --version -V                    boolean  Displays pgloader version and exit.
  --quiet -q                      boolean  Be quiet
  --verbose -v                    boolean  Be verbose
  --debug -                      boolean  Display debug level information.
  --client-min-messages           string   Filter logs seen at the console (default: "warning")
  --log-min-messages              string   Filter logs seen in the logfile (default: "notice")
  --summary -S                    string   Filename where to copy the summary
  --root-dir -D                   string   Output root directory. (default: #P"/tmp/pgloader/")
  --upgrade-config -U             boolean  Output the command(s) corresponding to .conf file for v2.x
  --list-encodings -E             boolean  List pgloader known encodings and exit.
  --logfile -L                    string   Filename where to send the logs.
  --load-lisp-file -l             string   Read user code from files
  --dry-run                       boolean  Only check database connections, don't load anything.
  --on-error-stop                 boolean  Refrain from handling errors properly.
  --no-ssl-cert-verification      boolean  Instruct OpenSSL to bypass verifying certificates.
  --context -C                    string   Command Context Variables
  --with                          string   Load options
  --set                           string   PostgreSQL options
  --field                         string   Source file fields specification
  --cast                          string   Specific cast rules
  --type                          string   Force input source type
  --encoding                      string   Source expected encoding
  --before                        string   SQL script to run before loading the data
  --after                         string   SQL script to run after loading the data
  --self-upgrade                  string   Path to pgloader newer sources
  --regress                       boolean  Drive regression testing
  1. Create the database in postgres – add the uuid-ossp extension
postgres=# create database stackoverflow owner btpg10;
CREATE DATABASE

postgres=# \c stackoverflow btpg10;
You are now connected to database "stackoverflow" as user "btpg10".

stackoverflow=# create extension "uuid-ossp";
CREATE EXTENSION
  1. I define a parfile for specific flags – we can alter table names, exclude tables, define data type conversions - for this demo we will only define our source/target connections and rename the default MS SQL schema(dbo) to the default postgres (public)
load database
     from mssql://SA:@host1:1433/StackOverflow
     into postgresql://btpg10:@host2:5432/stackoverflow

        alter schema
before load do $$ drop schema if exists dbo cascade; $$;
  1. Define freetds config file in same directory
# view .freetds.conf
[global]
    tds version = 7.4
    client charset = UTF-8
  1. Test connectivity
# pgloader --dry-run ss_so.cmd
2020-06-25T18:33:26.014000Z LOG pgloader version "3.6.1"
2020-06-25T18:33:26.058000Z LOG Loading the FreeTDS shared librairy (sybdb)
2020-06-25T18:33:26.061000Z LOG DRY RUN, only checking connections.
2020-06-25T18:33:26.062000Z LOG Attempting to connect to #<MSSQL-CONNECTION mssql://[email protected]:1433/StackOverflow {100696F6F3}>
2020-06-25T18:33:26.190000Z LOG Success, opened #<MSSQL-CONNECTION mssql://[email protected]:1433/StackOverflow {100696F6F3}>.
2020-06-25T18:33:26.190000Z LOG Running a simple query: SELECT 1;
2020-06-25T18:33:26.210000Z LOG Attempting to connect to #<PGSQL-CONNECTION pgsql://[email protected]:5432/stackoverflow {1006970C13}>
2020-06-25T18:33:26.244000Z LOG Success, opened #<PGSQL-CONNECTION pgsql://[email protected]:5432/stackoverflow {1006970C13}>.
2020-06-25T18:33:26.245000Z LOG Running a simple query: SELECT 1;
2020-06-25T18:33:26.245000Z LOG report summary reset

   table name      errors      rows      bytes      total time
 --------------  ----------  --------  ---------  --------------
 --------------  ----------  --------  ---------  --------------
  1. Run data migration
# pgloader --verbose ss_so.cmd

2020-06-25T18:42:07.745000Z LOG report summary reset
             table name     errors       read   imported      bytes      total time       read      write
-----------------------  ---------  ---------  ---------  ---------  --------------  ---------  ---------
            before load          0          1          1                     0.017s
        fetch meta data          0         18         18                     0.457s
         Create Schemas          0          0          0                     0.001s
       Create SQL Types          0          0          0                     0.009s
          Create tables          0         18         18                     0.102s
         Set Table OIDs          0          9          9                     0.006s
-----------------------  ---------  ---------  ---------  ---------  --------------  ---------  ---------
          public.badges          0    1102019    1102019    50.5 MB         10.400s    10.396s     6.802s
        public.comments          0    3875183    3875183   743.1 MB       1m32.008s  1m32.002s    58.180s
       public.postlinks          0     161519     161519     7.5 MB          1.709s     1.700s     1.111s
       public.posttypes          0          8          8     0.1 kB          0.143s     0.137s
           public.votes          0   10143364   10143364   424.5 MB       1m38.394s  1m37.466s   1m6.057s
       public.linktypes          0          2          2     0.0 kB          0.132s     0.130s
           public.posts          0    3729195    3729195     2.8 GB        5m8.075s   5m8.051s  2m37.241s
           public.users          0     299398     299398    42.7 MB         12.007s     5.144s     4.256s
       public.votetypes          0         15         15     0.2 kB          0.134s     0.131s
-----------------------  ---------  ---------  ---------  ---------  --------------  ---------  ---------
COPY Threads Completion          0          4          4                  6m52.193s
         Create Indexes          0          9          9                    41.768s
 Index Build Completion          0          9          9                     4.211s
        Reset Sequences          0          9          9                     0.443s
           Primary Keys          0          9          9                     0.067s
    Create Foreign Keys          0          0          0                     0.000s
        Create Triggers          0          0          0                     0.002s
       Install Comments          0          0          0                     0.000s
-----------------------  ---------  ---------  ---------  ---------  --------------  ---------  ---------
      Total import time          ✓   19310703   19310703     4.1 GB       7m38.684s
  1. Verify tables / data in Postgresql
postgres=# \c stackoverflow
You are now connected to database "stackoverflow" as user "postgres".

stackoverflow=# \dt
          List of relations
 Schema |   Name    | Type  | Owner
--------+-----------+-------+--------
 public | badges    | table | btpg10
 public | comments  | table | btpg10
 public | linktypes | table | btpg10
 public | postlinks | table | btpg10
 public | posts     | table | btpg10
 public | posttypes | table | btpg10
 public | users     | table | btpg10
 public | votes     | table | btpg10
 public | votetypes | table | btpg10
(9 rows)

Author

Thomas Flatley

Reference

microsoft-sql-server-postgresql-migration-using-pgloader

作者:古道轻风


标签:POSTGRESQL,string,--,btpg10,PGLOADER,SERVER,pgloader,---------,public
From: https://blog.51cto.com/u_15949547/6588769

相关文章

  • C# ModbusRtu或者TCP协议上位机源码,包括存储,数据到SQL SERVER数据库,趋势曲线图,数据报
    C#ModbusRtu或者TCP协议上位机源码,包括存储,数据到SQLSERVER数据库,趋势曲线图,数据报表,实时和历史报警界面,有详细注释,需要哪个协议版本原创文章,转载请说明出处,资料来源:http://imgcs.cn/5c/655313350668.html......
  • 华为云Serverless核心技术与最佳实践
    一、Serverless简介软件架构的发展从原先的单体架构到近十几年的微服务架构,再到现在新兴的Serverless架构。单体架构通常把应用的逻辑和功能耦合在一起,部署在BMS裸金属机或VM上,耦合模式使得一些通用功能或通用逻辑无法灵活复用,经常出现重复造轮子的现象,架构整体上是相对封闭的。微......
  • 谷歌云:全面推出 AlloyDB for PostgreSQL 与数据库迁移服务
    【本文由CloudAce整理发布。CloudAce是谷歌云全球战略合作伙伴,拥有300多名工程师,也是谷歌最高级别合作伙伴,多次获得GoogleCloud合作伙伴奖。作为谷歌托管服务商,我们提供谷歌云、谷歌地图、谷歌办公套件、谷歌云认证培训服务。】2022年12月,谷歌云宣布全面推出AlloyDB......
  • 谷歌云:全面推出 AlloyDB for PostgreSQL 与数据库迁移服务
    【本文由CloudAce 整理发布。CloudAce 是谷歌云全球战略合作伙伴,拥有300多名工程师,也是谷歌最高级别合作伙伴,多次获得GoogleCloud合作伙伴奖。作为谷歌托管服务商,我们提供谷歌云、谷歌地图、谷歌办公套件、谷歌云认证培训服务。】2022年12月,谷歌云宣布全面推出 Allo......
  • 广州丨阿里云 Serverless 技术实战营邀你来玩!
    活动简介“Serverless技术实战与创新沙龙”是一场以Serverless为主题的开发者活动,活动受众以关注Serverless技术的开发者、企业决策人、云原生领域创业者为主,活动形式为演讲、动手实操,让开发者通过一个下午的时间增进对Serverless技术的理解,快速上手Serverless,拥抱云......
  • PostgreSQL技术大讲堂 - 第20讲:事务概述与隔离级别
     PostgreSQL从小白到专家,是从入门逐渐能力提升的一个系列教程,内容包括对PG基础的认知、包括安装使用、包括角色权限、包括维护管理、、等内容,希望对热爱PG、学习PG的同学们有帮助,欢迎持续关注CUUGPG技术大讲堂。第20讲:事务概述与隔离级别内容1:ACID四大特性内容2:PostgreSQL......
  • SQL Server 表中自增长ID列,因删除而不连续。可以使用临时表
    1.使用局部临时表来调整自增长列select*from#newtempfromgrade--相当于备份truncatetablegrade--删除数据insertintogradeselectclassnamefrom#newtemp2.使用全局临时表来调整自增长列select*from##tempfromgrade--相当于备份truncatetableg......
  • SQL Server查询重复数据
    1.查询单列重复select*fromtablewherenamein(selectnamefromtablegroupbynamehavingcount(name)>1)2.查询多列重复SELECTa.*FROMtablea,(SELECTname,codeFROMtableGROUPBYname,codeHAVINGCOUNT(1)>1)ASbWHEREa.name=b.nameANDa.......
  • Linux安装jumpserver实践
    1、结合之前Linux安装mysql登录问题-适用root强制登录这一步比较重要,否则在线自动安装不了。不能忽略。进行,要先安装该mysql,并对数据库初始化、设置密码之后,登录数据库,并创建一个数据库:https://docs.jumpserver.org/zh/v3/installation/setup_linux_standalone/requirements/#......
  • sqlserver 表权限设置
    表“增删改查”权限表上右键选择【属性】,选择【权限】选项卡:#点击【搜索】,在弹出的框中点击【浏览】,选择需要设置的用户;#在上面点击【确定】后,就可以在【权限】选项卡中看到权限列表,选择需要的权限点击确定即可;#当选中【选择】和【引用】权限时,还可以设置【列权限】;并且用户【zy......