IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> sql-server 迁移数据库到postresql 方案Babelfish for PostgreSQL14.2 Ubuntu 20.4 -> 正文阅读

[大数据]sql-server 迁移数据库到postresql 方案Babelfish for PostgreSQL14.2 Ubuntu 20.4

sql-server 迁移数据库到postresql 方案 数据库 Postgresql 14.2

参考:
https://github.com/babelfish-for-postgresql/babelfish_extensions/blob/BABEL_1_X_DEV/contrib/README.md

https://mp.weixin.qq.com/s/-Rwf9R5utg_wYi91ZcUsFA
https://www.modb.pro/db/181528

https://www.modb.pro/db/237005
https://www.modb.pro/db/402380

This package includes 4 extensions:

    babelfishpg_tsql
        Supports the tsql language.
    babelfishpg_tds
        Supports the tds connection.
    babelfishpg_common
        Supports the various datatypes in MSSQL.
    babelfishpg_money
        supports the money type in MSSQL. This is a variation of the opensource fixeddecimal extension.

before setup config env

postgres@iZbp179u0bgzhoi4l5mu3lZ:~$ more /etc/issue
Ubuntu 20.04.4 LTS

postgres@iZbp179u0bgzhoi4l5mu3lZ:~$ cmake -version
cmake version 3.20.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).

vi  .bashrc
export PATH="$PATH:/opt/mssql-tools/bin"

export EXTENSIONS_SOURCE_CODE_PATH="/opt/babelfish_extensions"

export INSTALLATION_PATH=/opt/postgres

export PG_CONFIG=$INSTALLATION_PATH/bin/pg_config
export PG_SRC=/opt/postgresql_modified_for_babelfish
export cmake=/usr/local/bin/cmake
~                                     

How do I build the extensions?

The following build instructions comply with Ubuntu 20.04 and Amazon Linux 2 environment.
Build the Postgres engine

1 First install dependent tools and libraries

Install postgresql-devel, libicu, libxml2, openssl and uuid-devel packages in order to build Babelfish.

You'll also need to install gcc, gcc-c++, java and bison.
    sudo apt-get install uuid-dev openjdk-8-jre \
                        libicu-dev libxml2-dev openssl libssl-dev python-dev \
                        libossp-uuid-dev libpq-dev pkg-config g++ build-essential bison 
For RHEL-flavoured distributions, this is the command for dealing with the required dependencies:
    sudo yum install libicu-devel libxml2-devel \
                     openssl-devel uuid-devel postgresql-devel gcc gcc-c++ java

2 Now it’s time to build the Postgres engine.

 In the Postgres engine directory, run these sequence of commands to build the PG engine modified for Babelfish (Github repo: https://github.com/babelfish-for-postgresql/postgresql_modified_for_babelfish):
    ./configure --prefix=$HOME/postgres/ --without-readline --without-zlib --enable-debug CFLAGS="-ggdb" --with-libxml --with-uuid=ossp --with-icu
    make -j 4 2>error.txt
    make install
    make check

3 Also build and install the extensions because uuid-ossp.so is a runtime dependency for babelfish:

    cd contrib && make && sudo make install

4 Install & build dependencies

4.1 Get the latest version of cmake (version 3+ is required)
To get and use the latest version of cmake:
    wget https://github.com/Kitware/CMake/releases/download/v3.20.6/cmake-3.20.6-linux-x86_64.sh
    sh cmake-3.20.6-linux-x86_64.sh
4.2 Install ANTLR
The babelfishpg_tsql contrib has a plug-in parser generated by ANTLR, which depends on cmake and antlr4-cpp-runtime-4.9.3. Unfortunately, there aren't binaries for C++ targets available. You'll also need have uuid-devel installed in order to install antlr4-cpp-runtime-4.9.3.

First copy the jar file in contrib/babelfishpg_tsql/antlr/thirdparty/antlr/ to another location:

cd babelfish_extensions/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/
sudo cp antlr-4.9.3-complete.jar /usr/local/lib

Compile antlr4:
    wget http://www.antlr.org/download/antlr4-cpp-runtime-4.9.3-source.zip
    unzip -d antlr4 antlr4-cpp-runtime-4.9.3-source.zip 
    cd antlr4
    mkdir build && cd build 
    cmake .. -DANTLR_JAR_LOCATION=/usr/local/lib/antlr-4.9.3-complete.jar -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_DEMO=True
    make
    sudo make install
  Copy libantlr4-runtime to postgres/lib
    cp /usr/local/lib/libantlr4-runtime.so.4.9.3 ~/postgres/lib/

If you come across the error

-- Checking for module 'uuid'
--   No package 'uuid' found
CMake Error at /usr/local/share/cmake-3.21/Modules/FindPkgConfig.cmake:554 (message):
    A required package was not found
Call Stack (most recent call first):
    /usr/local/share/cmake-3.21/Modules/FindPkgConfig.cmake:776 (_pkg_check_modules_internal)
    CMakeLists.txt:44 (pkg_check_modules)
4.3 Check that you have uuid-devel installed. If so, go to antlr4/CMakeLists.txt and comment out the line pkg_check_modules(UUID REQUIRED uuid) by adding a # to the beginning of the line.
More information about installing ANTLR4 can be found at this link.

Set environment variables and paths
    Set the PG_CONFIG environment variable to where you installed the DB engine postgresql_modified_for_babelfish. For example, I installed it under ~/postgres (the default location), so I set PG_CONFIG as follows:

export PG_CONFIG=~/postgres/bin/pg_config

    Set PG_SRC to where the DB engine source package is as we need access to a few engine source files in order to build the Babelfish extensions. For example:

export PG_SRC=~/postgresql_modified_for_babelfish

    Set the cmake environment variable to where you installed cmake (as defined above in step 2). For example:

export cmake=/usr/local/bin/cmake

    Update the file contrib/babelfishpg_tsql/antlr/CMakeLists.txt with the correct antlr4-runtime path (if not there already). For example:

SET (MYDIR /usr/local/include/antlr4-runtime/)

Build the extensions

make and make install each extension within the extension project’s contrib directory:

cd contrib/babelfishpg_money
make && make install
cd ../babelfishpg_common
make && make install
cd ../babelfishpg_tds
make && make install
cd ../babelfishpg_tsql
make && make install

How to install the extensions and how to connect via SQLCMD?

Install the SQL server command line tools by following steps 1 - 3 under Install the SQL Server command-line tools. Use the RHEL7 URL in step 1.
    For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable. This enables you to run the tools without specifying the full path. For Z shell (the default shell for Cloud Desktop), add the following line to your ~/.zshrc file:

export PATH=/opt/mssql-tools/bin:$PATH

From where you installed postgres in the ./configure step adjust the paths of these commands and run them to start the Postgres server:

    ~/postgres/bin/initdb -D ~/postgres/data/
    ~/postgres/bin/pg_ctl -D ~/postgres/data/ -l logfile start
Modify ~/postgres/data/postgresql.conf by uncommenting and adjusting the following 2 properties:
    listen_addresses = '*'
    shared_preload_libraries = 'babelfishpg_tds'
Modify ~/postgres/data/pg_hba.conf to allow connections from allowed IP addresses, replacing 10.x.y.z with your IP address. E.g.
      host    all             all     0.0.0.0/0            md5
Now run this to apply the changes:
    ~/postgres/bin/pg_ctl -D ~/postgres/data/ -l logfile restart

Connect via psql using the command ~/postgres/bin/psql -U your_user_name. Create the extension and set up essential parameters. Please be aware you need to choose either ‘single-db’ or ‘multi-db’ mode during this provisioning step and you CAN NOT change it later. Refer to our documentation page for more information on ‘single-db’ vs ‘multi-db’ mode.

select * from pg_available_extensions WHERE name like 'postgis%'
          babelfishpg_money
 
     babelfishpg_common
 
    babelfishpg_tds
 
      babelfishpg_tsql

    CREATE USER babelfish_user WITH CREATEDB CREATEROLE PASSWORD '12345678' INHERIT;
    DROP DATABASE IF EXISTS babelfish_db;
    CREATE DATABASE babelfish_db OWNER babelfish_user;
    \c babelfish_db
    CREATE EXTENSION IF NOT EXISTS "babelfishpg_tds" CASCADE;
    GRANT ALL ON SCHEMA sys to babelfish_user;
    ALTER SYSTEM SET babelfishpg_tsql.database_name = 'babelfish_db';
    ALTER SYSTEM SET babelfishpg_tds.set_db_session_property = true;
    ALTER DATABASE babelfish_db SET babelfishpg_tsql.migration_mode = 'single-db'|'multi-db';
    SELECT pg_reload_conf();
    CALL SYS.INITIALIZE_BABELFISH('babelfish_user');
    If you run into errors connecting to psql such as psql: error: could not connect to server: No such file or directory try giving permissions by using this command instead:

    sudo ~/postgres/bin/psql -d postgres -U your_user_name

Try connecting to Babelfish via SQLCMD

    sqlcmd -S localhost -U babelfish_user -P 12345678


验证数据库引擎

https://www.modb.pro/db/237005

SELECT @@version,@@servername ;

SELECT * from sysdatabases s;

SELECT * from pg_user;

SELECT * from pg_database;

create database abc

重新连接到 abc库
在 abc库 做如下操作:

create table xxx (id int);
insert into xxx values(1),(2),(3);

SELECT * from xxx;

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-05-21 19:02:54  更:2022-05-21 19:03:37 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 19:46:43-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码