2023年4月24日月曜日

Rocky Linux9 に postgres インストール

$ cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)
【ロケーション設定】
timedatectl set-timezone Asia/Tokyo
localectl set-locale LANG=ja_JP.utf8

timedatectl
localectl

【ネットワーク設定】
nmcli d
nmcli c

#nmcli c delete vlan100

nmcli general hostname postgres

nmcli c delete internet
nmcli c add type ethernet ifname enp1s0 con-name "internet" ethernet.mtu 1500
nmcli c mod internet ipv4.method auto
nmcli c mod internet connection.autoconnect yes
nmcli c up internet

VLAN=vlan_monitor
VLAN_IP=192.168.254.211/24
nmcli c delete $VLAN
nmcli c add type ethernet ifname enp7s0 con-name "$VLAN"
nmcli c mod $VLAN ipv4.addresses $VLAN_IP
nmcli c mod $VLAN ipv4.method manual
nmcli c mod $VLAN connection.autoconnect yes
nmcli c mod $VLAN ipv4.dns 8.8.8.8
nmcli c mod $VLAN ipv4.gateway 192.168.254.254
nmcli c up $VLAN

VLAN=vlan_database
VLAN_IP=192.168.200.111/24
nmcli c delete $VLAN
nmcli c add type ethernet ifname enp8s0 con-name "$VLAN"
nmcli c mod $VLAN ipv4.addresses $VLAN_IP
nmcli c mod $VLAN ipv4.method manual
nmcli c mod $VLAN connection.autoconnect yes
nmcli c mod $VLAN +ipv4.routes "192.168.210.0/24 192.168.200.2"
nmcli c mod $VLAN +ipv4.routes "192.168.12.0/24  192.168.200.2"
nmcli c mod $VLAN +ipv4.routes "192.168.22.0/24  192.168.200.2"
nmcli c mod $VLAN +ipv4.routes "192.168.32.0/24  192.168.200.2"
nmcli c up $VLAN

# systemctl restart NetworkManager

【postgres15】
# dnf update --refresh
# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf  -y install postgresql15-server
# /usr/pgsql-15/bin/postgresql-15-setup initdb
# systemctl start postgresql-15
# systemctl enable postgresql-15
# systemctl status postgresql-15
# passwd postgres
# su - postgres
$ psql -V
psql (PostgreSQL) 15.5
$ psql
alter user postgres with password 'password';
exit
$  vi /var/lib/pgsql/15/data/pg_hba.conf 
#local   all             all                                     peer
#host    all             all             127.0.0.1/32            scram-sha-256
local     all             all                                     trust
host      all             all             10.0.0.0/16             password
$ vi /var/lib/pgsql/15/data/postgresql.conf 
listen_addresses = '*'          
port = 5432 
max_connections = 100 
log_timezone = 'Asia/Tokyo'
timezone = 'Asia/Tokyo'
lc_messages = 'ja_JP.utf8'                    # locale for system error message
lc_monetary = 'ja_JP.utf8'                    # locale for monetary formatting
lc_numeric = 'ja_JP.utf8'                       # locale for number formatting
lc_time = 'ja_JP.utf8'
# systemctl restart postgresql-15
# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# firewall-cmd --reload

【データディレクトリの変更】
$ psql
show config_file ;
show data_directory;
# systemctl stop postgresql-15.service
# mkdir -p /pg_data/data
# chown postgres:postgres /pg_data
# chown postgres:postgres /pg_data/data
# chmod -R 700  /pg_data/data
# rsync -av /var/lib/pgsql/15/data/  /pg_data/data

# vi /var/lib/pgsql/15/data/postgresql.conf
data_directory = '/pg_data/data'
# vi /lib/systemd/system/postgresql-15.service
#Environment=PGDATA=/var/lib/pgsql/15/data/
Environment=PGDATA=/pg_data/data/
# systemctl daemon-reload
# systemctl start postgresql-15

【Postgres14】
# dnf update --refresh
# dnf install http://apt.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf  -y install postgresql14-server postgresql14-docs 
# dnf -y install postgresql14-libs postgresql14-plperl postgresql14-plpython3 postgresql14-pltcl postgresql14-tcl postgresql14-contrib postgresql14-llvmjit
/usr/pgsql-14/bin/postgresql-14-setup initdb
# vi /var/lib/pgsql/14/data/pg_hba.conf  << __EOF__
#local   all             all                                        peer
local     all             all                                          trust
#host    all           all       127.0.0.1/32         scram-sha-256      
host      all           all        192.168.0.0/16   password
__EOF__

# vi /var/lib/pgsql/14/data/postgresql.conf  <<__EOF__
listen_addresses = '*'          
port = 5432 
max_connections = 100 
log_timezone = 'Asia/Tokyo'
timezone = 'Asia/Tokyo'
lc_messages = 'ja_JP.utf8'                    # locale for system error message
lc_monetary = 'ja_JP.utf8'                    # locale for monetary formatting
lc_numeric = 'ja_JP.utf8'                       # locale for number formatting
lc_time = 'ja_JP.utf8'
__EOF__

※ 青字確認。AWS EC2では、en_USxxxxになっていた。

# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# firewall-cmd --reload
# systemctl enable postgresql-14
# systemctl start postgresql-14 
# psql --version
psql (PostgreSQL) 14.7

# ls -lZ /var/lib/pgsql
合計 0
drwx------. 4 postgres postgres system_u:object_r:postgresql_db_t:s0 51  4月 24 11:50 14

# passwd postgres
# su - postgres
$ psql -U postgres
alter user postgres with password  'newpassword';
create user admin with password 'xxxxxxxx' superuser;
select * from pg_user;
select * from pg_shadow;
\g
ALTER USER admin WITH PASSWORD 'xxxxxxxx'

create database ARCSDBMS owner admin;

【psql パスワード自動入力】
$ vi ~/.pgpass <<__EOF__
192.168.254.211:5432:workbase:admin:PASSWORD
__EOF__
又は、
$ export PGPASSWORD=password  (非推奨)

【postgres 文字コード】
(1) vi /var/lib/pgsql/14/data/postgresql.conf
       timezone = 'Asia/Tokyo'
       log_timezone = 'Asia/Tokyo'
       lc_messages = 'ja_JP.utf8'                      # locale for system error message
       lc_monetary = 'ja_JP.utf8'                      # locale for monetary formatting
       lc_numeric    = 'ja_JP.utf8'                      # locale for number formatting
       lc_time           = 'ja_JP.utf8'                      # locale for time formatting

(2) pg_settingsを更新。
    select name,setting,context from pg_settings where name like 'lc%';
    update pg_settings set setting ='ja_JP.UTF-8' where name = 'lc_messages'; set_config

(3) role を変更
 alter role office_role set lc_monetary = 'ja_JP.UTF-8';
 alter role office_role set lc_numeric = 'ja_JP.UTF-8';
 alter role office_role set lc_time = 'ja_JP.UTF-8';

(4) データベース作成時に設定 
     create database japan with encoding  'utf8'  lc_collate='ja_JP.utf8' lc_ctype='ja_JP.utf8' template=template0;

(5) テーブルのカラムにロケールを個別に指定。
ALTER TABLE items ALTER COLUMN title TYPE VARCHAR COLLATE "ja_JP.utf8";

(6) templateデータベースを更新。
1) template1データベースをテンプレートから外す
   UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
2) template1データベースを削除
   DROP DATABASE template1;
3) template1データベースを作成
    CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 文字コード 
    LC_COLLATE = 'ja_JP.utf-8' LC_CTYPE = 'ja_JP.utf8'
4) template1データベースをテンプレートへ戻す
   UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';




2023年4月7日金曜日

amazon Linux 2023 設定

【タイムゾーンと日本語】

$ sudo timedatectl set-timezone Asia/Tokyo

$ sudo timedatectl

$ sudo localectl set-locale LANG=ja_JP.utf8

$ sudo localectl


【プロキシ設定】

$ sudo vi /etc/dnf/dnf.conf

proxy=http://192.168.13.101:3128

$ sudo vi /etc/profile.d/proxy.sh

export http_proxy=http://192.168.13.101:3128

export https_proxy=http://192.168.13.101:3128


【epelリポジトリの登録】
$ sudo amazon-linux-extras install epel ----> 廃止

【fedra36 リポジトリの登録】
epelの代わりに登録
# vi /etc/yum.repos.d/fedora.repo
[fedora]
name=Fedora 36 – $basearch
baseurl=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/36/Everything/$basearch/os/
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-36&arch=$basearch
enabled=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=https://getfedora.org/static/fedora.gpg
skip_if_unavailable=False

【未インストールパッケージ】
$ sudo dnf install rsyslog
$ sudo dnf install cronie

# systemctl start rsyslog
# systemctl start crond

【s3 Storage マウント】

$ sudo mkdir /aws

$ sudo vi /etc/fstab

192.168.210.101:/test-cxdnext-filegateway /aws nfs rw,hard,nolock 0 0

$ sudo mount -a


【httpd】
$ sudo dnf install httpd
$  httpd -V
Server version: Apache/2.4.56 (Amazon Linux)
$ sudo systemctl start httpd
$ sudo systemctl enable httpd

【zabbix agent2 】  → 保留(openssl1.1が必要な為
$ sudo dnf install https://repo.zabbix.com/zabbix/6.4/rhel/8/x86_64/zabbix-agent2-6.4.1-release1.el8.x86_64.rpm
Last metadata expiration check: 0:28:37 ago on Fri Apr 7 16:31:07 2023.
zabbix-agent2-6.4.1-release1.el8.x86_64.rpm 3.8 MB/s | 5.5 MB 00:01
Error:
Problem: conflicting requests
- nothing provides libcrypto.so.1.1()(64bit) needed by zabbix-agent2-6.4.1-release1.el8.x86_64
- nothing provides libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) needed by zabbix-agent2-6.4.1-release1.el8.x86_64
- nothing provides libssl.so.1.1()(64bit) needed by zabbix-agent2-6.4.1-release1.el8.x86_64
- nothing provides libssl.so.1.1(OPENSSL_1_1_0)(64bit) needed by zabbix-agent2-6.4.1-release1.el8.x86_64
- nothing provides libssl.so.1.1(OPENSSL_1_1_1)(64bit) needed by zabbix-agent2-6.4.1-release1.el8.x86_64
(try to add '--skip-broken' to skip uninstallable packages)

→openssl3がインストールされている。
# dnf list installed |grep openssl
openssl.x86_64                        1:3.0.8-1.amzn2023.0.1             @System
openssl-libs.x86_64               1:3.0.8-1.amzn2023.0.1             @System
openssl-pkcs11.x86_64        0.4.12-3.amzn2023.0.1              @System

【PYTHON】
$ python3
Python 3.9.16 (main, Feb 23 2023, 00:00:00) 
[GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

【JAVA】
$ sudo dnf install java-17-amazon-corretto java-17-amazon-corretto-devel
$ sudo update-alternatives --config java
# cat > /etc/profile.d/java.sh <<__EOF__
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin
__EOF__
$ source /etc/profile
$ java --version
openjdk 17.0.6 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)


【TOMCAT】
# cd /opt
# wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.7/bin/apache-tomcat-10.1.7.tar.gz
#  tar xvzf apache-tomcat-10.1.7.tar.gz
# vi /usr/lib/systemd/system/tomcat10.service<<__EOF__
[Unit]
Description=Apache Tomcat 10
After=network.target
[Service]
Type=oneshot
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
RemainAfterExit=yes
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
__EOF__

# cd /opt
# ln -s /opt/apache-tomcat-10.1.7 tomcat
# useradd -M -d /opt/tomcat tomcat
# chown -R tomcat:tomcat  /opt/tomcat /opt/tomcat/*

# firewall-cmd --add-port=8080/tcp --permanent
# firewall-cmd --reload

# mkdir ~/Selinux
# cd ~/Selinux
# vi catalinash.te <<__EOF__
module catalinash 1.0;

require {
        type init_t;
        type admin_home_t;
        class file { append execute execute_no_trans ioctl open read };
}

#============= init_t ==============
allow init_t admin_home_t:file { append execute execute_no_trans ioctl open read };
__EOF__

# checkmodule -m -M -o catalinash.mod catalinash.te
# semodule_package --outfile catalinash.pp --module catalinash.mod
# semodule -i catalinash.pp

# systemctl restart tomcat10
# systemctl enable tomcat10
URL localhost:8080で確認

# /opt/tomcat/bin/version.sh
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Server version: Apache Tomcat/10.1.7
Server built:   Feb 27 2023 20:25:27 UTC
Server number:  10.1.7.0
OS Name:        Linux
OS Version:     6.1.21-1.45.amzn2023.x86_64
Architecture:   amd64
JVM Version:    17.0.6+10-LTS
JVM Vendor:     Amazon.com Inc.

■apache連携( apache 2.4.56  /  tomcat 10.1.7 )
# cd /etc/httpd/conf.modules.d
# grep -e mod_proxy_ajp -e  mod_proxy.so *
00-proxy.conf:LoadModule proxy_module modules/mod_proxy.so
00-proxy.conf:LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

# vi /etc/httpd/conf.d/tomcat .conf  <<__EOF__
<Location /test2023/guacamole >
ProxyPass                  ajp://localhost:8009/guacamole
ProxyPassReverse  ajp://localhost:8009/guacamole
</Location>
<Location  /test2023/tomcat >
ProxyPass                   ajp://localhost:8009
ProxyPassReverse  ajp://localhost:8009
</Location>
<Location  /test2023/docs >
ProxyPass                  ajp://localhost:8009/docs
ProxyPassReverse  ajp://localhost:8009/docs
</Location>
<Location  /test2023/examples >
ProxyPass                   ajp://localhost:8009/examples
ProxyPassReverse  ajp://localhost:8009/examples
</Location>
<Location /test2023 /host-manager >
ProxyPass                  ajp://localhost:8009/host-manager
ProxyPassReverse  ajp://localhost:8009/host-manager
</Location>
<Location  /test2023/manager >
ProxyPass                   ajp://localhost:8009/manager
ProxyPassReverse  ajp://localhost:8009/manager
</Location>
__EOF__


$ sudo vi /opt/tomcat/conf/server.xml << __EOF__
<!-- del by takahab
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
  <!-- add by takahab from -->
   <Connector port="8009" protocol="AJP/1.3"
        address="127.0.0.1"
        proxyName="portal.cxdnext.co.jp"
        proxyPort="443"
        scheme="https"
        secure="true"
        redirectPort="8443"
        rejectIllegalHeader="true"
        secretRequired="false" />
    <!-- to add by takahab -->
__EOF__


【Django環境設定】
(1) Django 仮想環境作成
# mkdir /var/www/wsgi
# cd /var/www/wsgi
# vi get << __EOF__
switch のディレクトリ変更
# ./get deploy
      (./env create)

#  vi  /etc/httpd/conf.d/wsgi.conf <<__EOF__
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 600
WSGIApplicationGroup %{GLOBAL}
WSGISocketPrefix /var/run/wsgi

WSGIDaemonProcess test2023 user=apache group=apache processes=1 threads=100 maximum-requests=10000 \
   home=/var/www/wsgi/test2023 \
   python-home=/var/www/wsgi/test2023/.venv \
   python-path=/var/www/wsgi/test2023:/var/www/wsgi/test2023/.venv/lib/python3.9/site-packages \
   lang=ja_JP.utf8

WSGIScriptAlias /test2023 /var/www/wsgi/test2023/Config/wsgi.py process-group=test2023

Alias /assets/ /aws/efs/assets/
Alias /media/  /aws/efs/media/

<Directory /aws/efs/assets>
   Require all granted
</Directory>

<Directory /aws/efs/media>
   Require all granted
</Directory>

WSGIPassAuthorization on

<Location /test2023>
  WSGIProcessGroup test2023
</Location>


__EOF__

# vi /etc/httpd/conf.modules.d/20-wsgi.conf << __EOF__
LoadModule wsgi_module /var/www/wsgi/test2023/.venv/lib64/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so
__EOF__


#------------------------------------------参考-------------------------------------------------
Collecting mod-wsgi
  Using cached mod_wsgi-4.9.4.tar.gz (497 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-t1qa20dz/mod-wsgi_1a6f23a5f3fb4d4eba390f4e7d024c38/setup.py", line 88, in <module>
          raise RuntimeError('The %r command appears not to be installed or '
      RuntimeError: The 'apxs' command appears not to be installed or is not executable. Please check the list of prerequisites in the documentation for this package and install any missing Apache httpd server packages.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.
 →
# dnf install  python3-devel  rpm-build-libs  httpd-devel

Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
      /bin/sh: 行 1: mysql_config: コマンドが見つかりません
      /bin/sh: 行 1: mariadb_config: コマンドが見つかりません
      /bin/sh: 行 1: mysql_config: コマンドが見つかりません

→
# dnf install mariadb-connector-c-devel

【Django】
pip3 install -r requirements.txt でエラー
→ requirements.txt 内のバージョン番号を全て削除して最新版をインストールする。


ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation'
→from django.utils.translation import ugettext_lazy as _
    ugettext_lazy  --> getttext_lazy

ImportError: Unable to find zbar shared library
dnf install zbar zbar-libs
epelからインストールできない。 --> 保留

DEPRECATION: starkbank-ecdsa is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
同様に、mod-wsgi-httpd/ mod-wsgi/jaconv/mysqlclient
→requirement.txtの内容をインストールする前にwhellをインストールしておく。
pip3 install wheel 


ImportError: Module "debug_toolbar.panels.profiling" does not define a "ProfilingPanel" attribute/class





【課題】
(1) rsyslogが入っていない。
(2) cronieがはいっていない。
(3) guacamoleでsshログインできない。
            exe="/usr/sbin/sshd" hostname=? addr=? terminal=? res=success'   認証?
(4)      zabbix clientがインストールできない。(openssl のバージョン)
(5)    epelリポジトリが使えない。
(7)    AWS ロードバランサは、pathでバランスされる為、URL ROOTがサーバのROOTと異る。


  



2023年3月23日木曜日

EC2 linux 2にora2pg インストール


【オラクルクライアントインストール】

# rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-jdbc-11.2.0.4.0-1.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

# vi  /etc/profile.d/oracle.sh <<__EOF__
export        ORACLE_HOME=/usr/lib/oracle/11.2/client64/lib
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
export  C_INCLUDE_PATH=/usr/include/oracle/11.2/client64
__EOF__
# source /etc/profile

【参考】20241025 追記 amazon linux2023

sudo timedatectl set-timezone Asia/Tokyo
sudo localectl set-locale LANG=ja_JP.utf8
sudo dnf -y install libnsl

cd /tmp
wget https://download.oracle.com/otn_software/linux/instantclient/1920000/oracle-instantclient19.20-basic-19.20.0.0.0-1.x86_64.rpm

wget https://download.oracle.com/otn_software/linux/instantclient/1920000/oracle-instantclient19.20-devel-19.20.0.0.0-1.x86_64.rpm

wget https://download.oracle.com/otn_software/linux/instantclient/1920000/oracle-instantclient19.20-sqlplus-19.20.0.0.0-1.x86_64.rpm

wget https://download.oracle.com/otn_software/linux/instantclient/1920000/oracle-instantclient19.20-jdbc-19.20.0.0.0-1.x86_64.rpm

sudo rpm -Uvh  oracle-instantclient19.20-basic-19.20.0.0.0-1.x86_64.rpm
sudo rpm -Uvh oracle-instantclient19.20-devel-19.20.0.0.0-1.x86_64.rpm
sudo rpm -Uvh oracle-instantclient19.20-sqlplus-19.20.0.0.0-1.x86_64.rpm
sudo rpm -Uvh oracle-instantclient19.20-jdbc-19.20.0.0.0-1.x86_64.rpm
 

sudo sh -c 'cat > /etc/profile.d/oracle.sh <<__EOF__
export        ORACLE_HOME=/usr/lib/oracle/19.20/client64/lib
export LD_LIBRARY_PATH=/usr/lib/oracle/19.20/client64/lib
export  C_INCLUDE_PATH=/usr/include/oracle/19.20/client64
__EOF__'
source /etc/profile
sudo sh -c 'cat >  /etc/ld.so.conf.d/oracle.conf <<__EOF__
/usr/lib/oracle/19.20/client64/lib
__EOF__'
sudo ldconfig

sqlplus user/password@host:1521/service_name(sid)       # SIDではつながらなかった。

#sudo dnf provides */pg_config
sudo dnf -y install postgresql15-private-devel        # シンボリックリンクのみで実体なし。
          :                      # /usr/bin/pg_config -> pg_server_config
sudo dnf -y install postgresql15-server-devel         # これで実体がインストールされた。

sudo dnf install -y perl-CPAN
echo "export PERL_MM_USE_DEFAULT=1" >> ~/.bashrc
echo "export PERL_INSTALL_ROOT=/usr/lib64/perl5" >> ~/.bashrc
source ~/.bashrc

sudo dnf  -y install perl-DBI perl-YAML
source ~/.bashrc

#-------------------対面-----------------------------------
cpan
cpan[1]> look Test::More
perl Makefile.PL
sudo make
sudo make install
exit
exit

cpan
cpan[1]> look DBD::Oracle
perl Makefile.PL
sudo make
sudo make install
exit
exit
#-------------------対面-----------------------------------

#-------------------非対面-----------------------------------
export PERL_MM_USE_DEFAULT=1
cpan Test::More <<__EOF__
look Test::More
__EOF__
cd $(find ~/.cpan/build -type d -name "Test-More*" | tail -n 1)
perl Makefile.PL
sudo make
sudo make install
exit

export PERL_MM_USE_DEFAULT=1
cpan -T -i DBD::Oracle <<__EOF__
look DBD::Oracle
__EOF__
cd $(find ~/.cpan/build -type d -name "DBD-Oracle*" | tail -n 1)
perl Makefile.PL
sudo make
sudo make install
exit
#-------------------非対面-----------------------------------

 cd ~
mkdir ora2pg
 curl -OL https://github.com/darold/ora2pg/archive/refs/tags/v24.3.tar.gz
tar xvzf v24.3.tar.gz
cd ora2pg-24.3
sudo perl Makefile.PL
sudo sudo make
sudo make install
source ~/.bashrc

ora2pg help

#--------------------------------Ora2PG install  終了-------------------------------------



sudo dnf   -y install perl-CPAN
sudo dnf   -y install libyaml-devel 
sudo dnf  -y  install gcc                                             # allready installed
sudo dnf  -y install perl-ExtUtils-MakeMaker  # allready installed
sudo dnf  -y install perl-Test-Simple                   # allready installed
sudo dnf  -y install perl-Env                                    # allready installed
sudo dnf  -y install postgresql15
sudo dnf -y install perl-DBI perl-DBD-Pg
$ cd /home/ec2-user
※先にポストグレスとオラクルドライバをインストール
sudo cpan App::cpanminus
sudo cpan 
cpan 1> o conf init
Would you like to configure as much as possible automatically? [yes] yes
upgrade
What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
Would you like me to append that to /home/ec2-user/.bashrc now? [yes]
network traffice external site?( Y/n)  return
Path to pg_config?  return
Check for a new version of the Public Suffix List? [N ]
Import PAUSE and author keys to GnuPG? [y] 
Do you want to run external tests?
These tests *will* *fail* if you do not have network connectivity. [n] 
network traffic to external sites.  [Y/n] 

sudo cpanm  --quiet YAML
sudo cpanm --quiet DBI
sudo cpanm --quiet Test
sudo cpanm --quiet Test::NoWarnings  
sudo cpanm --quiet DBD::Oracle
sudo cpanm --quiet DBD::Pg
cpanm --quiet DBD::Pg is up to date (3.18.0).

【ora2pg インストール】
$ sudo dnf install git
$ mkdir  Make
$ cd Make
$ git clone https://github.com/darold/ora2pg.git
$ cd ./ora2pg 
$ perl Makefile.PL
$ gmake
$ sudo gmake install

#---------------------------------------------------------------------------




【参考】 20240123 追記 Rocky linux9.3
# dnf   install perl-CPAN
# dnf   install libyaml-devel
# dnf   install gcc
# dnf  install perl-ExtUtils-MakeMaker
# dnf  install perl-Test-Simple
# dnf  install perl-Env
# dnf install  postgresql15-devel   
# dnf  install perl-DBI perl-DBD-Pg
POSTGRES_HOME=/usr/pgsql-15                       # for DBD::Pg
$ cpan
o conf init
upgrade
takahab
noxxxxx
install   YAML
install Test
install Test::NoWarnings                        # 下記エラー発生の為追加。
install DBI
install DBD::Oracle
install DBD::Pg
DBD::Pg is up to date (3.18.0).






【DBD::Oracle ドライバインストール】
$ sudo yum -y install perl-CPAN
$ sudo yum -y install libyaml-devel
$ sudo yum -y install gcc
$ sudo yum install perl-ExtUtils-MakeMaker
$ sudo yum install perl-Test-Simple
$ sudo yum install perl-Env
$ sudo yum install  postgresql-devel                                # for DBD::Pg
$ cpan
o conf init
upgrade
install   YAML
install Test
install Test::NoWarnings                        # 下記エラー発生の為追加。
install DBI
install DBD::Oracle
install DBD::Pg                                          # for type=COPY




$ export ORACLE_SID=ARCSDBMS2
$ export ORACLE_USERID="arcsdbcb/password"
$ export ORACLE_DSN="dbi:Oracle:SID=arcsdbms2;host=192.168.10.201;port=1521"
$ export NLS_LANG=Japanese_Japan.JA16SJIS
or
export NLS_LANG=Japanese_Japan.AL32UTF8

$ sqlplus64 arcsdbcb/passwd@10.0.19.2:1521/arcsdbms.world

# vi /etc/ld.so.conf.d/oracle.conf <<__EOF__
/usr/lib/oracle/11.2/client64/lib
__EOF__

$ cpan
install DBI
install DBD::Oracle
install DBD::Pg                                          # for type=COPY

 ERROR   Test::NoWarnings is not installed (any version required)
install Test::NoWarnings

# vi /etc/profile.d/proxy.sh <<__EOF__
PROXY="http://10.0.19.2:3128"
export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export https_proxy=$PROXY
export HTTPS_PROXY=$PROXY
__EOF__

# cpan DBI
# cpan DBD::Oracle

又は、

$ perl -MCPAN -e shell                 #全てEnter
$ perl -MCPAN -e 'install DBI'
$ perl -MCPAN -e 'install DBD::Oracle'

【ora2pg インストール】

$ git clone https://github.com/darold/ora2pg.git
$ cd ./ora2pg 
$ perl Makefile.PL
$ gmake
$ sudo gmake install

【初期設定】
$ mkdir migration
$ ora2pg --project_base ./migration --init_project test_project

$ vi  ./migration/test_project/config/ora2pg.conf __EOF__
ORACLE_DSN      dbi:Oracle:host=192.168.10.201;sid=xxxxxxxx;port=1521
ORACLE_USER     xxxxxxxxx
ORACLE_PWD      xxxxxx

 # Oracle schema/owner to use
 SCHEMA  xxxxxxx
__EOF__

$ cd ./migration/test_project
ora2pg -t SHOW_VERSION -c config/ora2pg.conf
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0

※ 設定ファイルのひな型 :  /etc/ora2pg/ora2pg.conf.dist
$ cp  /etc/ora2pg/ora2pg.conf.dist  ora2pg.conf

【Oracle から Postgresへ変換】
$ ssh ora2pg
$ mkdir Database
$ cd Database
$ mkdir arcsdbcb
$ cd arcsdbcb
$ cp /etc/ora2pg/ora2pg.conf.dist ora2pg.conf
$ vi  ora2pg.conf  <<  __EOF__
ORACLE_DSN      dbi:Oracle:host=10.0.19.2;sid=xxxxxxxx;port=1521
ORACLE_USER     xxxxxxxxx
ORACLE_PWD      xxxxxx
__EOF__

【on the fly 】
$ vi  ora2pg.conf  <<  __EOF__
PG_DSN          dbi:Pg:dbname=ARCSDBMS;host=10.0.18.101;port=5432
PG_USER         xxxxxxcb
PG_PWD          xxxxx00
__EOF__

【表領域出力&パーティション】
$ vi  ora2pg.conf  <<  __EOF__
DATA_LIMIT                     1000          # for out of memory
USE_TABLESPACE        1
KEEP_PKEY_NAMES    0                  # 表領域出力   USE_TABLESPACE=1にしているので、内部で強制的に1になる。
PREFIX_PARTITION      0                 #  RENAME_PARTITION   と同じ動き? → 0指定であとで手動で修正
PG_NUMERIC_TYPE     0                 # numbe(n,m) → real  → decimal(n,m)
PG_INTEGER_TYPE      0                 # number(n)    → bigint  → numeric( n)
STOP_ON_ERROR         0                # for debug     
__EOF__

【修正】
ora2pg_TABLE.sql
1) 1,$s/TABLESPACE ARCSDB/TABLESPACE TABLESPACE_ARCSDB/g
2) 1,$s/_primary/_pkey/
3) rb_xxxx →table_pkey に修正
$ cat *TAB*sql |grep rb_
ALTER TABLE cca002 ADD CONSTRAINT rb_4f3840d101 PRIMARY KEY (acode,gcode,ccode,scode);
ALTER TABLE cca003 ADD CONSTRAINT rb_48edd00701 PRIMARY KEY (acode,gcode,ccode,rcode);
ALTER TABLE cca004 ADD CONSTRAINT rb_48edd02701 PRIMARY KEY (acode,gcode,ccode,tcode);
ALTER TABLE ccc002 ADD CONSTRAINT rb_4f3840ec03 PRIMARY KEY (gcode,ccode,scode);
ALTER TABLE ccc003 ADD CONSTRAINT rb_48edd04105 PRIMARY KEY (gcode,ccode,rcode);
ALTER TABLE ccc004 ADD CONSTRAINT rb_48edd05a04 PRIMARY KEY (gcode,ccode,tcode);

4) サブパーティション名変更
mv ora2pg_PARTITION.sql ora2pg_PARTITION.sql.org
cat ora2pg_PARTITION.sql.org |./convert.py >ora2pg_PARTITION.sql

5) csb008 Primary KEY名不正  (ora2pg_TABLE.sql )
      csb008 -> csb008_pkey
      ysb008  -> ysb008_pkey
      sss016_pkey2 -> sss016_pkey
     TABLESPACE_ARCSDBPA_TBL -> TABLESPACE_ARCSDBSS_TBL (sst999 )

5) ERROR:  テーブル空間 tablespace_arcsdbss_tbl へのアクセスが拒否されました。
arcsdbss  -> arcsdbxx (一部 検索要)     
arcsdbss -> arcsdbtm

$ mkdir -P  ~/Database/arcsdbcb
$ cd Database/arcsdbcb
$ cp  /etc/ora2pg/ora2pg.conf.dist  ora2pg_cb.conf
$  time  ora2pg -c ora2pg_cb.conf -t TABLE -b ~/Database/arcsdbcb/ -o ora2pg_TABLE.sql
[2024-01-10 19:52:19] [========================>] 82/82 tables (100.0%) end of scanning.     
[2024-01-10 19:53:05] [========================>] 82/82 tables (100.0%) end of table export.
real 6m21.216s
user 0m0.367s
sys         0m0.093s
$ time  ora2pg -c ora2pg_cb.conf -t PARTITION -N arcsdbcb -b ~/Database/arcsdbcb/ -o ora2pg_PARTITION.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
[2024-01-22 15:26:27] [========>                ] 3564/9900 partitions (36.0%) end of output.                         

real 7m16.630s
user 0m0.623s
sys        0m0.231s

$ time ora2pg -c ora2pg_cb.conf -t SHOW_REPORT  --dump_as_html  > ora2pg_REPORT.html
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
[2024-01-22 15:47:53] [========================>] 82/82 tables (100.0%) end of scanning.     
[2024-01-22 15:48:10] [========================>] 10/10 objects types (100.0%) end of objects auditing.               
real 5m8.331s
user 0m0.155s
sys 0m0.067s

$  time  ora2pg -c ora2pg_cb.conf -t GRANT   -N arcsdcb  -b  ~/Database/arcsdbcb/ -o ora2pg_GRANT.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
real 1m52.493s
user 0m0.106s
sys         0m0.010s

$ time ora2pg -c ora2pg_ss.conf -t TABLE -b                 ~/Database/arcsdbss/ -o ora2pg_TABLE.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
[2024-01-22 19:05:12] [========================>] 375/375 tables (100.0%) end of scanning.    
[2024-01-22 19:10:02] [========================>] 375/375 tables (100.0%) end of table export.

real 19m48.498s
user 0m1.752s
sys         0m0.362s

$ time ora2pg -c ora2pg_ss.conf -t PARTITION -N arcsdbcb -b ~/Database/arcsdbss/ -o ora2pg_PARTITION.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
[2024-01-22 19:34:16] [========>                ] 28727/79783 partitions (36.0%) end of output.                         

real 22m30.711s
user 0m4.047s
sys   0m1.588s

$ time ora2pg -c ora2pg_ss.conf -t PARTITION -N arcsdbss -b ~/Database/arcsdbss/ -o ora2pg_PARTITION.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 because USE_TABLESPACE is enabled.
[2024-01-22 22:27:11] [========>                ] 28727/79783 partitions (36.0%) end of output.                         

real 23m33.264s
user 0m4.306s
sys         0m1.546s

USAGE  ./CreDB.sh create_tablespace_directory   # 表領域の作成
       ./CreDB.sh dropdatabases_arcsdbms                  # ARCSDBMSデータベースの削除(databae,schema,role,table)
       ./CreDB.sh initdatabases_arcsdbms                     # ARCSDBMS全スキーマ・ROLE作成
       ./CreDB.sh arcsdbms_gettable                               # オラクルからテーブル情報取得
       ./CreDB.sh arcsdbms_createtable                        # ARCSDVMS内全テーブルの作成
       ./CreDB.sh arcsdbms_copy                                     # オラクル環境からの全データのコピー

ERROR:  共有メモリが足りません
HINT:  max_locks_per_transactionを増やす必要があるかもしれません
# vi /var/lib/pgsql/15/data/postgresql.conf
shared_buffers =128MB -> 256MB
max_locks_per_transaction = "" ->512
max_connections = 100 -> 200  
# systemctl restart postgresql-15
→解消されず。
# vi /pg_data/data/postgresql.conf
max_locks_per_transaction = "" ->1024
→ 解消された。

TABLESPACEを指定しないCREATEテーブル文がある。
→
SET default_tablespace = TABLESPACE TABLESPACE_ARCSDBSS_TBL; 追加。


FATAL: ERROR:  リレーション"ccm201"の列"norcode"は存在しません.
→  psql -h 10.0.18.101  -U arcsdbcb -d arcsdbms
      ALTER TABLE arcsdbcb.ccm201 ADD norcode varchar(1) NULL DEFAULT '0';
       psql -h 10.0.18.101  -U vrcsdbcb -d arcsdbms
      ALTER TABLE vrcsdbcb.ccm201 ADD norcode varchar(1) NULL DEFAULT '0';
削除するときは
ALTER TABLE arcsdbcb.ccm201 DROP COLUMN norcode;
※ CXD擬似のxrcsdbcbは、norcodeはなかった。

FATAL: ERROR:  リレーション"ssn003"の列"authoritymasterprod"は存在しません
→
psql -h 10.0.18.101  -U arcsdbss -d arcsdbms
alter table arcsdbss.ssn003 add authoritymasterprod varchar(1) NULL DEFAULT '2';
alter table arcsdbss.ssn003 add authoritymasterdept varchar(1) NULL DEFAULT '2';
alter table arcsdbss.ssn003 add authoritymasterprodgroup varchar(1) NULL DEFAULT '2';
alter table arcsdbss.ssn003 add authoritymastercust varchar(1) NULL DEFAULT '2';
alter table arcsdbss.ssn003 add authoritymasteremployee varchar(1) NULL DEFAULT '2';

FATAL: ERROR:  リレーション"ssz103"の列"month"は存在しません
→
psql -h 10.0.18.101  -U arcsdbss -d arcsdbms
alter table arcsdbss.ssz103 add month numeric(14,0);    
alter table arcsdbss.ssz103 add whcode numeric(14,0);
alter table arcsdbss.ssz103 add actqty numeric(14,0);
alter table arcsdbss.ssz103 add alcqty numeric(14,0);
alter table arcsdbss.ssz103 add resqty numeric(14,0);
alter table arcsdbss.ssz103 add movqty numeric(14,0);
alter table arcsdbss.ssz103 add ordqty numeric(14,0);
alter table arcsdbss.ssz103 add rcvqty numeric(14,0);
alter table arcsdbss.ssz103 add pmonthqty numeric(14,0);
alter table arcsdbss.ssz103 add whinqty numeric(14,0);
alter table arcsdbss.ssz103 add whoutqty numeric(14,0);
alter table arcsdbss.ssz103 add whadjqty numeric(14,0);
alter table arcsdbss.ssz103 add qtypurchaseret numeric(14,0);
alter table arcsdbss.ssz103 add qtysalesret numeric(14,0);
alter table arcsdbss.ssz103 add qtymoveout numeric(14,0);
alter table arcsdbss.ssz103 add qtymovein numeric(14,0);
alter table arcsdbss.ssz103 add qtyinventoryout numeric(14,0);
alter table arcsdbss.ssz103 add qtyinventoryin numeric(14,0);
alter table arcsdbss.ssz103 add qtyrepairout numeric(14,0);
alter table arcsdbss.ssz103 add qtyrepairin numeric(14,0);
alter table arcsdbss.ssz103 add qtyproductout numeric(14,0);
alter table arcsdbss.ssz103 add qtyproductin numeric(14,0);
alter table arcsdbss.ssz103 add qtydismantleout numeric(14,0);
alter table arcsdbss.ssz103 add qtydismantlein numeric(14,0);
alter table arcsdbss.ssz103 add qtyhousebonout numeric(14,0);

※ データもNULLなので、本来なら擬似環境から削除する方が望ましい。

擬似環境ORACLE DLL      
"MONTH" NUMBER(*,0), 
"WHCODE" NUMBER(*,0), 
"ACTQTY" NUMBER(*,0), 
"ALCQTY" NUMBER(*,0), 
"RESQTY" NUMBER(*,0), 
"MOVQTY" NUMBER(*,0), 
"ORDQTY" NUMBER(*,0), 
"RCVQTY" NUMBER(*,0), 
"PMONTHQTY" NUMBER(*,0), 
"WHINQTY" NUMBER(*,0), 
"WHOUTQTY" NUMBER(*,0), 
"WHADJQTY" NUMBER(*,0), 
"QTYPURCHASERET" NUMBER(*,0), 
"QTYSALESRET" NUMBER(*,0), 
"QTYMOVEOUT" NUMBER(*,0), 
"QTYMOVEIN" NUMBER(*,0), 
"QTYINVENTORYOUT" NUMBER(*,0), 
"QTYINVENTORYIN" NUMBER(*,0), 
"QTYREPAIROUT" NUMBER(*,0), 
"QTYREPAIRIN" NUMBER(*,0), 
"QTYPRODUCTOUT" NUMBER(*,0), 
"QTYPRODUCTIN" NUMBER(*,0), 
"QTYDISMANTLEOUT" NUMBER(*,0), 
"QTYDISMANTLEIN" NUMBER(*,0), 
"QTYHOUSEBONOUT" NUMBER(*,0), 


FATAL: ERROR:  行に対応するパーティションがリレーション"ssz103"に見つかりません SSZ103 (1000 recs/sec)
DETAIL:  失敗した行のパーティションキーは(zdate) = (20520120)を含みます。
CONTEXT:  ssz103のCOPY、行 79: "301 1093 0001 7716650000361 20520120 1000000000000004 20220120165711 905 0 -1 0 0 1 905 0 0 00 0 0 ..."
FATAL: ERROR:  行に対応するパーティションがリレーション"ssz104"に見つかりません
DETAIL:  失敗した行のパーティションキーは(month) = (205201)を含みます。
CONTEXT:  ssz104のCOPY、行 64: "301 1093 0001 7716650000361 205201 1000000000000004 20220120165711 905 0 -1 0 0 1 905 0 0 0 00 0 0 ..."
→デフォルトパーティション作成
CREATE TABLE ssz103_default   PARTITION OF ssz103 DEFAULT;
CREATE TABLE ssz104_default   PARTITION OF ssz104 DEFAULT;
CREATE TABLE ssz111_default   PARTITION OF ssz111 DEFAULT;
CREATE TABLE ssz112_default   PARTITION OF ssz112 DEFAULT;
CREATE TABLE ssz113_default   PARTITION OF ssz113 DEFAULT;
CREATE TABLE ssz118_default   PARTITION OF ssz118 DEFAULT;


NOTICE:  リレーション"batchstatuslog_seq"は存在しません、スキップします
→ vi run.sh
time ora2pg -c ora2pg_pa.conf -t SEQUENCE  -N arcsdbpa -b ~/Database/arcsdbpa/ -o ora2pg_SEQUENCE.sql


psql:ora2pg_VIEW.sql:149: ERROR:  列"BUSINESSTYPE"は存在しません
行 3: select "BUSINESSTYPE","PROCESSTYPE","REVERSALTYPE","DEALINGM...
※ ""カット(大文字->小文字)
→129,149s/"//g


FATAL: 1017 ... ORA-01017: invalid username/password; logon denied (DBD ERROR: OCISessionBegin)
※ CXD擬似には、arcsdbtp, darcsdbcb ,trcsdbcb は存在しない。



【参考】
psql コマンド 例
psql -h host -d postgres -U postgres
\l データベース一覧表示
\c arcsdbms データベースを切り替える
\c arcsdbms arcsdbcb データベースとユーザを切り替える
\c - arcsdbss      ユーザのみを切り替える  
\dn スキーマ一覧
\d テーブル一覧表示(viewやsequence含む)
\dt テーブル一覧 (ユーザ切り替え後に実行)
\d
\d arcsdbcb.cca001 列定義一覧
\z arcsdbcb.cca001 テーブルのアクセス権限表示
\du ユーザー(Role)の一覧を表示
\dp    アクセス権限の表示
\z



select current_database();select current_user; 現在のユーザ
select * from pg_user;  ユーザ一覧




























psql -h 10.0.18.101 -d arcsdbms -U arcsdbcb -f ora2pg_TABLE.sql
psql -h 10.0.18.101 -d arcsdbms -U arcsdbcb -f ora2pg_PARTITION.sql

$ time  ora2pg -c ora2pg.conf -t TABLE -b ~/arcsdbcb/ -o ora2pg_TABLE.sql
$ time  ora2pg -c ora2pg.conf -t PARTITION  -N arcsdcb  -b ~/arcsdbcb/ -o ora2pg_PARTITION.sql
$ time  ora2pg -c ora2pg.conf -t TABLESPACE   -N arcsdcb  -b ~/arcsdbcb/ -o ora2pg_TABLESPACE.sql
$ time  ora2pg -c ora2pg.conf -t PROCEDURE   -N arcsdcb  -b  ~/arcsdbcb/ -o ora2pg_PROCEDURE.sql
$ time  ora2pg -c ora2pg.conf -t INSERT  -N arcsdcb  -b ~/arcsdbcb/ -o ora2pg_INSERT.sql
$ time  ora2pg -c ora2pg.conf -t GRANT   -N arcsdcb  -b  ~/arcsdbcb/ -o ora2pg_GRANT.sql
$ time  ora2pg -c ora2pg.conf -t VIEW   -N arcsdcb  -b  ~/arcsdbcb/ -o ora2pg_VIEW.sql
$ time ora2pg -c ora2pg.conf -t SHOW_REPORT  --dump_as_html  > ora2pg_REPORT.html

$ time  ora2pg -c ora2pg.conf -t COPY -b ~/arcsdbcb/ -o ora2pg_COPY.sql

※ 表領域設定の為、一時的にスーパユーザにする。
付与する  ALTER ROLE ARCSDBCB  WITH SUPERUSER;
剥奪する  ALTER ROLE ARCSDBCB  WITH NOSUPERUSER;

psql -h 192.168.210.201 -p 5432 -U arcsdbcb -d ARCSDBMS -f  ora2pg_TABLE.sql
psql -h 192.168.210.201 -p 5432 -U arcsdbcb -d ARCSDBMS -f  ora2pg_PARTITION.sql
$ time  ora2pg -c ora2pg.conf -t COPY -b ~/arcsdbcb/ 
$ time  ora2pg -c ora2pg.conf -t COPY -b ~/arcsdbcb/ -a 'table[ccd002]' -e 'PARTITION[sys_*]'
※ 正規表現*が動作しない。

※ for パスワード自動入力
$ vi ~/.pgpass  <<__EOF__
192.168.210.201:5432:postgres:postgres:Noxxxxx77%
192.168.210.201:5432:ARCSDBMS:admin:caxxx00
__EOF__
$ chmod 0600 ~/.pgpass


SCHEMA_LISTS="ARCSDBCB ARCSDBCO ARCSDBCS ARCSDBPA ARCSDBSS ARCSDBTM ARCSDBTP DRCSDBCB TRCSDBCB VRCSDBCB XRCSDBCB SGNGDBMC SGNGDBMS"

for  sc in ${SCHEMA_LISTS}; do
                if [ ! -d $sc ]; then
                        mkdir $sc
                fi
                echo start init $sc
                cd $sc
                cdir=`pwd`
                cat  ../ora2pg.conf.org  |  sed   -e "s/ARCS_ORACLE_USER/${sc}/" | sed -e "s/ARCS_SCHEMA_NAME/${sc}/" |  sed   -e "s/ARCS_PG_USER/${sc}/" > ora2pg.conf
                time ora2pg -c ora2pg.conf -t TABLE             -N ${sc}  -b ${cdir} -o ora2pg_TABLE.sql
                time ora2pg -c ora2pg.conf -t PARTITION    -N ${sc}  -b ${cdir} -o ora2pg_PARTITION.sql
                time ora2pg -c ora2pg.conf -t SHOW_REPORT  --dump_as_html > ora2pg_REPORT.html
                psql -h 192.168.210.201 -p 5432 -U ${sc} -d ARCSDBMS -f  ora2pg_TABLE.sql
                psql -h 192.168.210.201 -p 5432 -U ${sc} -d ARCSDBMS -f  ora2pg_PARTITION.sql
                cd ..
done

【例】  
$ time  ora2pg -c ora2pg.conf -t TABLE -N arcsdbss  -b ~/arcsdbss/ -o ora2pg_TABLE.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 as USE_TABLESPACE is enabled.
[========================>] 373/373 tables (100.0%) end of scanning.    
[========================>] 373/373 tables (100.0%) end of table export.

real 13m3.017s
user 0m3.534s
sys 0m0.556s
$  time  ora2pg -c ora2pg.conf -t PARTITION -N arscdbss  -b ~/arcsdbss/ -o ora2pg_PARTITION.sql
WARNING: Enforcing KEEP_PKEY_NAMES to 1 as USE_TABLESPACE is enabled.
[========>                ] 25667/71283 partitions (36.0%) end of output.                         

real 14m20.962s
user 0m8.570s
sys 0m1.826s

※ ora2pg.conf 内の
$ time psql -h 192.168.210.201 -p 5432 -U admin -d ARCSDBMS -f  ora2pg_TABLE.sql                            
$ time psql -h 192.168.210.201 -p 5432 -U admin -d ARCSDBMS -f  ora2pg_PARTITION.sql


FATAL: ERROR:  new row for relation "ccd002_part100_subpart1" violates partition constraint
DETAIL:  Failing row contains (201512, 101, 1360, 0002, 0003, 10001000003000000100, 売上集計管理サービス, 1, 5400, 5400, 400, 201512, 20160106125511, 0, null, null, null, 7716610000552, 002001).
CONTEXT:  COPY ccd002_part100_subpart1, line 1: "201512 101 1360 0002 0003 10001000003000000100 売上集計管理サービス 1 5400 5400 400 201512..."
DBI::db=HASH(0x3b50558)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at /home/takahab/perl5/lib/perl5/Ora2Pg.pm line 14637.
Aborting export...
→メインテーブルコピー後に、重複してサブパーティションをコピーした為、
     (サブパーティションは外す)
$  time  ora2pg -c ora2pg.conf -t COPY -b ~/arcsdbcb/ -a 'table[ccp001]'  -e 'table[sys_subp*]'
→正規表現が効かない!!

psql -h 192.168.210.201 -p 5432 -U arcsdbcb -d ARCSDBMS
\COPY test_table (id, food_name) FROM '/xxxxx/test_table.csv' WITH CSV HEADER;

--------------------------------------------------------------------------------------------------
【実行結果例】
$  time  ora2pg -c ora2pg.conf -t COPY -b ~/arcsdbcb/ -a 'table[ccp020]'
WARNING: Enforcing KEEP_PKEY_NAMES to 1 as USE_TABLESPACE is enabled.
[========================>] 1/1 tables (100.0%) end of scanning.     
SET client_encoding TO 'UTF8';
SET synchronous_commit TO off;
[========================>] 7584704/7584704 rows (100.0%) Table CCP020 (2785 recs/sec)
[========================>] 7584704/7584704 total rows (100.0%) - (2723 sec., avg: 2785 recs/sec).
[========================>] 7584704/7584704 rows (100.0%) on total estimated data (2723 sec., avg: 2785 recs/sec)

real 46m11.963s
user 16m58.208s
sys 0m10.782s




---------------------------------------------------------------------------------------------------
スキーマ定義のexport
$ cd migration/test_project
$ ./export_schema

 $ psql -h 192.168.210.201 -U postgres

----------------------------------------------------------------------------------------------------

【移行オブジェクト】

移行対象オブジェクト指定するキーワード説明
テーブルTABLEExport tables, constraints, indexes, ...
パッケージPACKAGEExport packages
データINSERTExport data from table as INSERT statement$  time  ora2pg -c ora2pg_cb.conf -t PARTITION -N arcsdbcb -b ~/Database/arcsdbcb/ -o ora2pg_PARTITION.sql[2024-01-10 20:12:17] [========>                ] 3546/9850 partitions (36.0%) end of output.                         
real 6m49.824suser 0m0.601ssys 0m0.246s

データCOPYExport data from table as COPY statement
ビューVIEWExport views
権限GRANTExport grants
シーケンスSEQUENCEExport sequences
トリガTRIGGERExport triggers
ユーザ関数FUNCTIONExport functions
プロシージャPROCEDUREExport procedures
表領域TABLESPACEExport tablespace (PostgreSQL >= 8 only)
データ型TYPEExport user defined Oracle types
パーティションPARTITIONExport range or list partition (PostgreSQL >= v8.4)
外部表FDWExport table as foreign data wrapper tables
マテリアライズドビューMVIEWExport materialized view as snapshot refresh view
SQL文QUERYConvert Oracle SQL queries from a file.
XMLテンプレートKETTLEGenerate XML ktr template files to be used by Kettle.
シノニムSYNONYM(説明なし)
データベースリンクDBLINK(説明なし)

【データの変換】
属性Oracleのデータ型ora2pgでの変換後のデータ型AWS-SCTでの変換後のデータ型備考
文字列CHAR(n)char(n)character(n)PostgreSQLのnは文字数
NCHAR(n)char(n)character(n)
VARCHAR2(n)varchar(n)character varying(n)PostgreSQLのnは文字数
NVARCHAR2(n)varchar(n)character varying(n)
CLOBtexttext
LONGtexttext
数値NUMBERbigintdouble
NUMBER(n)smallintnumeric(n,0)n=1~4
NUMBER(n)integernumeric(n,0)n=5~9
NUMBER(n)bigintnumeric(n,0)n=10~19
NUMBER(n)decimalnumeric(n,0)n=20~38
NUMBER(n,m)realnumeric(n,m)n=2~6
NUMBER(n,m)double precisionnumeric(n,m)n=7~15
NUMBER(n,m)decimalnumeric(n,m)n=16~38
日付DATEtimestamptimestamp
TIMESTAMPtimestamptimestamp
バイナリBLOBbyteabytea
RAWbyteabytea
その他ROWIDoidcharacter(255)

#----------------------------------------
# 定義
#----------------------------------------

STAGE=test_

POSTGRES_HOST=192.168.210.201
SUPERUSER_NAME=${STAGE}admin
DATABASE_NAME=${STAGE}arcsdbms
#SCHEMA_LISTS="arcsdbcb arcsdbss arcsdbpa arcsdbcs arcsdbco arcsdbtm arcsdbtp vrcsdbcb xrcsdbcb"
#SCHEMA_LISTS="xrcsdbcb vrcsdbcb"
#SCHEMA_LISTS="arcsdbcb"
SCHEMA_LISTS="arcsdbcb arcsdbss arcsdbpa arcsdbcs vrcsdbcb xrcsdbcb"

TABLE_LISTS="ssa000 ssa001"

#----------------------------------------
# Main ルーチン
#----------------------------------------
main(){
case $1 in
new )
new
;;


drop )
drop
;;


all )
clean
init
getdll
report
;;


init )
init
;;


getdll )
getdll
;;


putdll )
putdll
;;


report )
report
;;


copy )
copy
;;


copytable )
if [ -p /dev/stdin ]; then
cat -
else
echo $@
fi | copy_by_table
;;


save )
save
;;


clean )
clean
;;




diff )
diff
;;


show )
show
;;


showtable )
showtable
;;


psql )
psql
;;


*)
echo "usage: ./run clean # スキーマワークディレクトリの削除"
echo "usage: ./run drop # 表領域&データベース&スキーマ&ユーザの削除"
echo "usage: ./run new # 表領域&データベース&スキーマ&ユーザの作成"
echo "usage: ./run init # ora2pg.conf ファイルの初期化とスキーマワークディレクトリの作成"
echo "usage: ./run getdll # OracleDBからDLL取得"
echo "usage: ./run putdll # PostgresDBにDLLi登録"
echo "usage: ./run report # 変換レポートの作成"
echo "usage: ./run copy # oracleDBらデータをexportしてposgreDBにimport"
echo "usage: ./run all (clean/init/getdll/report) # /clean/init/getdll/reportを一括実行"
;;


esac
}


new(){
psql -h ${POSTGRES_HOST} -p 5432 -U postgres << __EOF__
/* --------------------------------------------------+
| create ROLE |
+-------------------------------------------------- */
create user ${SUPERUSER_NAME} with password 'casio00' superuser;


/* --------------------------------------------------+
| create TABLE_SPACE ディレクトはサーバ側に作成 |
+-------------------------------------------------- */
--\! sudo mkdir -p /data
--\! sudo chown postgres:postgres /data
--\! sudo chmod 700 /data


--\! sudo mkdir -p /data/${DATABASE_NAME}_dat
--\! sudo chown postgres:postgres /data/${DATABASE_NAME}_dat
--\! sudo chmod 700 /data/${DATABASE_NAME}_dat
create tablespace ${DATABASE_NAME}_dat owner ${SUPERUSER_NAME} location '/data/${DATABASE_NAME}_dat';


/* --------------------------------------------------+
| create DATABASE |
+-------------------------------------------------- */
create database ${DATABASE_NAME} owner ${SUPERUSER_NAME} tablespace ${DATABASE_NAME}_dat ;
__EOF__
echo DONE CREATE DATABASE database=${DATABASE_NAME} owner=${SUPERUSER_NAME} tablespace=${DATABASE_NAME}_dat ;


for sc in ${SCHEMA_LISTS}; do
psql -h ${POSTGRES_HOST} -p 5432 -U ${SUPERUSER_NAME} -d ${DATABASE_NAME} << __EOF__


\c ${DATABASE_NAME} ${SUPERUSER_NAME}
/* --------------------------------------------------+
| create TABLE_SPACE ディレクトはサーバ側に作成 |
+-------------------------------------------------- */
--\! sudo mkdir -p /data/${STAGE}${sc}_tbl
--\! sudo chown postgres:postgres /data/${STAGE}${sc}_tbl
--\! sudo chmod 700 /data/${STAGE}${sc}_tbl


--\! sudo mkdir -p /data/${STAGE}${sc}_idx
--\! sudo chown postgres:postgres /data/${STAGE}${sc}_idx
--\! sudo chmod 700 /data/${STAGE}${sc}_idx


create tablespace ${STAGE}${sc}_tbl owner ${SUPERUSER_NAME} location '/data/${STAGE}${sc}_tbl';
create tablespace ${STAGE}${sc}_idx owner ${SUPERUSER_NAME} location '/data/${STAGE}${sc}_idx';


/* --------------------------------------------------+
| create ROLE & SCHEMA |
+-------------------------------------------------- */
create user ${STAGE}${sc} with password 'casio00' ;
create schema ${sc} authorization ${STAGE}${sc};
__EOF__
echo "DONE USER=${STAGE}${sc}"
echo create tablespace ${STAGE}${sc}_tbl owner ${SUPERUSER_NAME} location "/data/${STAGE}${sc}_tbl";
echo create tablespace ${STAGE}${sc}_idx owner ${SUPERUSER_NAME} location "/data/${STAGE}${sc}_idx";
done


show_postgres
}


drop(){
echo "データベース(${DATABASE_NAME})を全て削除します。"
echo "他(dbeaver等)で接続している場合は、切断してください。"
yes_no
if [ $? -eq 0 ]; then
echo "削除を開始します。"
else
echo "中止しました。"
return 1
fi
for sc in ${SCHEMA_LISTS}; do
psql -h ${POSTGRES_HOST} -p 5432 -U postgres << __EOF__
\c ${DATABASE_NAME} ${SUPERUSER_NAME}
drop schema ${sc};
drop user ${STAGE}${sc};
drop tablespace ${STAGE}${sc}_tbl;
drop tablespace ${STAGE}${sc}_idx;
__EOF__
done


psql -h ${POSTGRES_HOST} -p 5432 -U postgres << __EOF__
\c postgres postgres
drop database ${DATABASE_NAME};
drop tablespace ${DATABASE_NAME}_dat;
drop user ${SUPERUSER_NAME};
__EOF__
}


show_postgres(){
psql -h ${POSTGRES_HOST} -p 5432 -U postgres << __EOF__
\echo データベース一覧
select * from pg_database;
\echo 表領域一覧
select * from pg_tablespace;
\echo ユーザ一覧
select * from pg_user;
__EOF__
echo psql -h ${POSTGRES_HOST} -p 5432 -U postgres
}


showtable(){
sc=arcsdbss
echo "psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -c '\dt'"
psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -c "\dt"
}


psql(){
echo psql -h ${POSTGRES_HOST} -p 5432 -U postgres
}


show(){
sc=arcsdbcb
cd $sc
cdir=`pwd`
echo POSTGRES_HOST=192.168.210.201
echo SUPERUSER_NAME=${STAGE}admin
echo DATABASE_NAME=${STAGE}arcsdbms
echo time ora2pg -c ora2pg.conf -t TABLE -N ${STAGE}${sc} -b ${cdir} -o ora2pg_TABLE.sql
echo time psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -f ora2pg_TABLE.sql
}


ALL(){
for sc in ${SCHEMA_LISTS}; do
if [ ! -d $sc ]; then
mkdir $sc
fi
echo start init $sc
cd $sc
cdir=`pwd`
cat ../ora2pg.conf.org | sed -e "s/ARCS_ORACLE_USER/${sc}/" | sed -e "s/ARCS_SCHEMA_NAME/${sc}/" | sed -e "s/ARCS_PG_USER/${sc}/" > ora2pg.conf
echo time ora2pg -c ora2pg.conf -t TABLE -N ${sc} -b ${cdir} -o ora2pg_TABLE.sql
time ora2pg -c ora2pg.conf -t TABLE -N ${sc} -b ${cdir} -o ora2pg_TABLE.sql
echo time ora2pg -c ora2pg.conf -t PARTITION -N ${sc} -b ${cdir} -o ora2pg_PARTITION.sql
time ora2pg -c ora2pg.conf -t PARTITION -N ${sc} -b ${cdir} -o ora2pg_PARTITION.sql
echo time ora2pg -c ora2pg.conf -t SHOW_REPORT --dump_as_html > ora2pg_REPORT.html
time ora2pg -c ora2pg.conf -t SHOW_REPORT --dump_as_html > ora2pg_REPORT.html
psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -f ora2pg_TABLE.sql
psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -f ora2pg_PARTITION.sql
cd ..
done
}


init(){
for sc in ${SCHEMA_LISTS}; do
if [ ! -d $sc ]; then
mkdir $sc
fi
echo start init $sc
cd $sc
cdir=`pwd`
cat ../ora2pg.conf.org | sed -e "s/ARCS_ORACLE_USER/${sc}/" | sed -e "s/ARCS_SCHEMA_NAME/${sc}/" | sed -e "s/ARCS_PG_USER/${STAGE}${sc}/" | sed -e "s/ARCS_PG_DBNAME/${DATABASE_NAME}/"> ora2pg.conf
/usr/bin/diff ../ora2pg.conf.org ora2pg.conf
#time ora2pg -c ora2pg.conf -t TABLE -N ${sc} -b ${cdir} -o ora2pg_TABLE.sql
#time ora2pg -c ora2pg.conf -t PARTITION -N ${sc} -b ${cdir} -o ora2pg_PARTITION.sql
#time ora2pg -c ora2pg.conf -t SHOW_REPORT --dump_as_html > ora2pg_REPORT.html
#psql -h ${POSTGRES_HOST} -p 5432 -U ${sc} -d ${DATABASE_NAME} -f ora2pg_TABLE.sql
#psql -h ${POSTGRES_HOST} -p 5432 -U ${sc} -d ${DATABASE_NAME} -f ora2pg_PARTITION.sql
cd ..
done
}


getdll(){
for sc in ${SCHEMA_LISTS}; do
echo start collect table DLL $sc
cd $sc
grep ORACLE_DSN ora2pg.conf | grep -v '#ORACLE_DSN'
cdir=`pwd`
time ora2pg -c ora2pg.conf -t TABLE -N ${sc} -b ${cdir} -o ora2pg_TABLE.sql -e 'TABLE[smp_*]'
time ora2pg -c ora2pg.conf -t PARTITION -N ${sc} -b ${cdir} -o ora2pg_PARTITION.sql
#time ora2pg -c ora2pg.conf -t SHOW_REPORT --dump_as_html > ora2pg_REPORT.html


cp -p ora2pg_TABLE.sql ora2pg_TABLE_org.sql
cat ora2pg_TABLE_org.sql | convert > ora2pg_TABLE.sql
cd ..
done
}


convert(){
sed -e "s/) ;/) TABLESPACE ${STAGE}${sc}_tbl;/" \
| sed -e "s/) TABLESPACE \([^_]*_TBL\);/) TABLESPACE ${STAGE}${sc}_tbl;/" \
| sed -e "s/) TABLESPACE \([^_]*_IDX\);/) TABLESPACE ${STAGE}${sc}_tbl;/" \
| sed -e "s/USING INDEX TABLESPACE \([^_]*_TBL\);/USING INDEX TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/USING INDEX TABLESPACE \([^_]*_IDX\);/USING INDEX TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/PRIMARY KEY (\([^)]*\));/PRIMARY KEY (\1) USING INDEX TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/PRIMARY KEY (\([^)]*\)) USING INDEX TABLESPACE \([^;]*\);/PRIMARY KEY (\1) USING INDEX TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/CREATE INDEX \([^ ]*\) ON \([^ ]*\) (\([^)]*\));/CREATE INDEX \1 ON \2 (\3) TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/CREATE INDEX \([^ ]*\) ON \([^ ]*\) (\([^)]*\)) TABLESPACE \([^;]*\);/CREATE INDEX \1 ON \2 (\3) TABLESPACE ${STAGE}${sc}_idx;/" \
| sed -e "s/ALTER TABLE csb008 ADD CONSTRAINT \([^ ]*\) PRIMARY KEY (\([^)]*\)) USING INDEX TABLESPACE \([^;]*\);/ALTER TABLE csb008 ADD CONSTRAINT \1_primary PRIMARY KEY (\2) USING INDEX TABLESPACE \3;/" \
| sed -e "s/ALTER TABLE ysb008 ADD CONSTRAINT \([^ ]*\) PRIMARY KEY (\([^)]*\)) USING INDEX TABLESPACE \([^;]*\);/ALTER TABLE ysb008 ADD CONSTRAINT \1_primary PRIMARY KEY (\2) USING INDEX TABLESPACE \3;/" \
| sed -e "s/verbose numeric/x_verbose numeric/"
}


report(){
for sc in ${SCHEMA_LISTS}; do
echo start create report $sc
cd $sc
time ora2pg -c ora2pg.conf -t SHOW_REPORT --dump_as_html > ora2pg_REPORT.html
cd ..
done
}


putdll(){
echo "インポートしたDLLでテーブルを作成します。"
echo "一時的にスーパユーザになる必要があります。dbeaver等で${STAGE}userをスーパユーザに設定してください。"
yes_no
if [ $? -eq 0 ]; then
echo "削除を開始します。"
else
echo "中止しました。"
return 1
fi
for sc in ${SCHEMA_LISTS}; do
echo start create $sc
cd $sc
psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -f ora2pg_TABLE.sql
psql -h ${POSTGRES_HOST} -p 5432 -U ${STAGE}${sc} -d ${DATABASE_NAME} -f ora2pg_PARTITION.sql
cd ..
done
}


copy(){
for sc in ${SCHEMA_LISTS}; do
echo start copy data to $sc
cd $sc
cdir=`pwd`
echo ora2pg -c ora2pg.conf -t COPY -N ${sc} -b ${cdir} -e 'table[sys_subp*]'
time ora2pg -c ora2pg.conf -t COPY -N ${sc} -b ${cdir} -e 'table[sys_subp*]'
cd ..
done
}


copy_by_table(){
sc=arcsdbss
for ta in $(cat -); do
echo start copy data to $ta
cd $sc
cdir=`pwd`
echo ora2pg -c ora2pg.conf -t COPY -N ${sc} -b ${cdir} -a "table[${ta}]" -e "table[sys_subp*]"
time ora2pg -c ora2pg.conf -t COPY -N ${sc} -b ${cdir} -a "table[${ta}]" -e "table[sys_subp*]"
cd ..
done
}


clean(){
for sc in ${SCHEMA_LISTS}; do
rm -rf ${sc}
done
echo "ディクトリを削除しました(${SCHEMA_LISTS})"
}


diff(){
/usr/bin/diff -l /etc/ora2pg/ora2pg.conf.dist ora2pg.conf.org
}


save(){
tar cvzf arcsdbms.tar ${SCHEMA_LISTS}
}


#----------------------------------------
# 汎用関数
#----------------------------------------
yes_no(){
echo -n "よろしいですか? [y/N]:"
if tty -s; then
read ANS
else
echo TTY端末からの起動で無いため、強制的に「y」を入力します。
ANS=Yes
fi
case $ANS in
[Yy]* )
#echo "Yes"
return 0
;;
* )
#echo "No"
return 1
;;
esac
}

main $@

NEXTJS PWA化

$ cd frontend $ npm install @ducanh2912/next-pwa $ vi next.config.ts<<__EOF__ import withPWAInit from "@ducanh2912/next-pwa"...