调整位置
This commit is contained in:
99
postgresql_and_edb/EDB(postgresql 商业版)分区表.md
Normal file
99
postgresql_and_edb/EDB(postgresql 商业版)分区表.md
Normal file
@ -0,0 +1,99 @@
|
||||
# edb 12 创建分区表
|
||||
|
||||
edb12 兼容oracle 11g
|
||||
|
||||
可以使用Oracle 的自动分区。
|
||||
|
||||
```sql
|
||||
CREATE TABLE ckw_test (
|
||||
id bigserial NOT NULL,
|
||||
"name" varchar(255) NULL,
|
||||
afferent_date timestamp NOT null
|
||||
)PARTITION BY RANGE (afferent_date)
|
||||
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
|
||||
(
|
||||
partition part_202209 values less than('20221001')
|
||||
) ;
|
||||
```
|
||||
|
||||
|
||||
|
||||
普通分区转自动分区
|
||||
|
||||
```sql
|
||||
ALTER TABLE <table_name> SET INTERVAL (<constant> | <expression>);
|
||||
|
||||
ALTER TABLE ckw_test SET INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
|
||||
|
||||
```
|
||||
|
||||
自动分区单位
|
||||
|
||||
```sql
|
||||
--年-月
|
||||
NUMTOYMINTERVAL(1,'year')
|
||||
NUMTOYMINTERVAL(1,'month')
|
||||
|
||||
|
||||
--日-时-分-秒
|
||||
numtodsinterval(1,'day')
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
查询分区表信息
|
||||
|
||||
```sql
|
||||
select * from dba_tab_partitions where table_name='TCN_STAT';
|
||||
SELECT * FROM ALL_TAB_PARTITIONS;
|
||||
```
|
||||
|
||||
|
||||
|
||||
分区表操作
|
||||
|
||||
```sql
|
||||
-- 分离分区表
|
||||
ALTER TABLE tcn_stat DETACH PARTITION tcn_stat_part_default;
|
||||
|
||||
-- 附加分区表(数据不能与分区规则冲突)
|
||||
-- 默认分区
|
||||
ALTER TABLE ckw_test ATTACH PARTITION ckw_test_part_default DEFAULT;
|
||||
-- 小于2022-10-01 的数据
|
||||
ALTER TABLE ckw_test ATTACH PARTITION ckw_test_part_default values less than('20221001')
|
||||
-- 区间数据
|
||||
ALTER TABLE ckw_test ATTACH PARTITION ckw_test_part_default VALUES from ('20190101') TO ('20190201');
|
||||
|
||||
|
||||
|
||||
-- 合并操作
|
||||
select table_name,high_value,partition_name from dba_tab_partitions where table_name='t1';
|
||||
|
||||
alter table t1 merge partitions p2,p1 into partition p1_2;
|
||||
|
||||
|
||||
|
||||
-- 拆分分区
|
||||
-- at() 括号里为分割条件 如 '20190101'
|
||||
alter table t1 split partition p1_2 at(100) into (partition p1,partition p2);
|
||||
|
||||
|
||||
|
||||
-- 删除分区
|
||||
alter table t1 drop partition p3;
|
||||
|
||||
|
||||
|
||||
|
||||
-- 交换分区
|
||||
-- 用表test_t1 替换 t1的分区p2
|
||||
create table test_t1 (id int,name varchar2(20));
|
||||
alter table t1 exchange partition p2 with table test_t1;
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
176
postgresql_and_edb/mysql 迁移数据至postgresql.md
Normal file
176
postgresql_and_edb/mysql 迁移数据至postgresql.md
Normal file
@ -0,0 +1,176 @@
|
||||
# mysql 迁移数据至postgresql
|
||||
|
||||
|
||||
|
||||
业务需要 需要将mysql 数据迁移到 postgresql 12
|
||||
|
||||
|
||||
|
||||
百度了许久 迁移工具还是挺多的
|
||||
|
||||
如
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker pull quay.io/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
|
||||
|
||||
docker pull ghcr.dockerproxy.com/username/image:tag
|
||||
|
||||
|
||||
|
||||
docker pull quay.io/username/image:tag
|
||||
|
||||
docker pull quay.dockerproxy.com/username/image:tag
|
||||
|
||||
|
||||
|
||||
docker run -d \
|
||||
--name some-postgres \
|
||||
-e POSTGRES_PASSWORD=cEnq!rnvWV7Z!~+7ag \
|
||||
-p 5444:5444\
|
||||
quay.io/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
|
||||
docker run -d --name some-postgres \
|
||||
-e POSTGRES_PASSWORD=cEnq!rnvWV7Z!~+7ag \
|
||||
quay.io/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker run -it \
|
||||
--name some-postgres \
|
||||
quay.io/enterprisedb/postgresql:12 \
|
||||
psql -U postgres
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mytsql 172.17.0.3
|
||||
|
||||
|
||||
|
||||
|
||||
GitHub Container Registry
|
||||
常规镜像代理
|
||||
官方命令:docker pull ghcr.io/username/image:tag
|
||||
代理命令:docker pull ghcr.dockerproxy.com/username/image:tag
|
||||
|
||||
|
||||
|
||||
docker run -d \
|
||||
--name pgsql-12 \
|
||||
-e POSTGRES_PASSWORD=yiling \
|
||||
-p 5432:5432 \
|
||||
-v /opt/postgresql/data:/var/lib/postgresql/data \
|
||||
ghcr.dockerproxy.com/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
docker run -d --name pgsql-12 -e POSTGRES_PASSWORD=yiling -p 5432:5432 -v /opt/postgresql/data:/var/lib/postgresql/data ghcr.dockerproxy.com/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$ docker run -d \
|
||||
--name some-postgres \
|
||||
-e POSTGRES_PASSWORD=mysecretpassword \
|
||||
ghcr.dockerproxy.com/enterprisedb/postgresql:12
|
||||
|
||||
|
||||
|
||||
|
||||
bin:/usr/pgsql-12
|
||||
|
||||
|
||||
data /var/lib/postgresql/data/pgdata
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker run -d -v /opt/pgload/pgload.load:/opt/pgload/pgload.load --name pgloader dimitri/pgloader:latest pgloader /opt/pgload/pgload.load
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mysql_native_password
|
||||
|
||||
|
||||
|
||||
caching_sha2_password
|
||||
|
||||
|
||||
|
||||
|
||||
镜像
|
||||
docker run -itd --name=ubuntu ubuntu:18.04 /bin/bash
|
||||
|
||||
apt-get update && apt-get install lsb-core
|
||||
|
||||
|
||||
|
||||
su -c 'echo "deb [arch=amd64] https://apt.enterprisedb.com/$(lsb_release -cs)-edb/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/edb-$(lsb_release -cs).list'
|
||||
|
||||
|
||||
su -c 'echo "machine apt.enterprisedb.com login start password oIVqaoGTDFL5aYHD" > /etc/apt/auth.conf.d/edb.conf'
|
||||
|
||||
apt-get -y install apt-transport-https
|
||||
|
||||
apt-get install -y dialog
|
||||
|
||||
apt-get install -y wget
|
||||
|
||||
apt-get install -y vim
|
||||
|
||||
wget -q -O - https://apt.enterprisedb.com/edb-deb.gpg.key | apt-key add -
|
||||
|
||||
apt update
|
||||
|
||||
apt-get -y install edb-as12-server
|
||||
|
||||
/usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log start
|
||||
|
||||
|
||||
|
||||
/usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log restart
|
||||
|
||||
|
||||
|
||||
su - enterprisedb
|
||||
|
||||
docker run -itd -v /opt/edb-as:/var/lib/edb-as/ -v /var/log/edb-as:/var/log/edb-as -p 5444:5444 --name=myedb myedb:12 /bin/bash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker run -itd -v /opt/edb-as:/var/lib/edb-as/ -v /var/log/edb-as:/var/log/edb-as/ -p 5444:5444 --name=myedb_v2 myedb:12_v2 /bin/bash
|
||||
|
||||
|
||||
|
||||
su enterprisedb && /usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log restart
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker run -itd -p 5445:5444 --name=myedb_test myedb:12 /bin/bash
|
14
postgresql_and_edb/postgresql 数据备份 .md
Normal file
14
postgresql_and_edb/postgresql 数据备份 .md
Normal file
@ -0,0 +1,14 @@
|
||||
## postgresql 数据备份
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
以9.6为例
|
||||
|
||||
root 账号进入 /opt/postgresql/as9.6/bin
|
||||
|
||||
|
||||
|
||||
执行
|
||||
|
134
postgresql_and_edb/postgresql导入导出.md
Normal file
134
postgresql_and_edb/postgresql导入导出.md
Normal file
@ -0,0 +1,134 @@
|
||||
```
|
||||
//导入
|
||||
pg_restore
|
||||
psql -Uicc -dicc -f ./xxx.sql
|
||||
psql -Uicc -dicc -h10.23.101.52 -f ./schema/tables/table.sql
|
||||
|
||||
//导出表 模式 数据
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc> ~/dum.sql
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc -f icc.dmp
|
||||
|
||||
报错停止 -v ON_ERROR_STOP=1
|
||||
|
||||
-a 只要数据
|
||||
-s 只要表结构
|
||||
-O 不设置表归属
|
||||
-n, --schema=SCHEMA 只转储指定名称的模式
|
||||
-T 排除表
|
||||
-t 指定表
|
||||
-Z 压缩0-9
|
||||
|
||||
|
||||
pg_dump -U postgres vendemo | gzip > /vendemo.gz 备份下来只有30多k
|
||||
|
||||
// 导出压缩文件
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc -t 表名 -t表名 -a -O | gzip > iccData.gz
|
||||
pg_dump -Uicc -dicc | gzip > iccData.gz
|
||||
|
||||
|
||||
//导入压缩文件
|
||||
gzip -d iccData.gz | psql -Uicc -dicc -h10.23.101.52
|
||||
//没测试过
|
||||
psql -Uicctestedb -dicctestedb < gzip -d iccData.gz
|
||||
|
||||
|
||||
|
||||
|
||||
psql -U iccedb -d iccedb -h 192.168.53.118 -n 'icc2' | gzip > ~/iccedb_icc2_202206301142.gz
|
||||
|
||||
psql -U iccedb -d iccedb -h 192.168.53.118 -v schema=icc2 | gzip > ~/iccedb_icc2_202206301142.gz
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pg_dump -Uenterprisedb -dicc -h10.23.101.119 \
|
||||
-T icc.t_icc_inv_leg \
|
||||
-T icc.t_icc_inv_leg_rate \
|
||||
-T icc.tcn_stat_new | gzip > ~/icc_icc_202207081500.gz
|
||||
|
||||
|
||||
|
||||
./pg_dump -Uenterprisedb -dicc -h10.23.101.119 -O \
|
||||
-n icc -s \
|
||||
-f ~/icc_data_20220719_2130.sql
|
||||
|
||||
yiing&654
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#导出 icc 模式下 排除 t_icc_inv_seg 等表 采用自定义格式压缩等级9(最大)
|
||||
|
||||
./pg_dump -Uenterprisedb -dicc -h10.23.101.119 \
|
||||
-O -v -F c -Z 9 \
|
||||
-t 'icc.*' \
|
||||
-T '*.t_icc_inv_seg' \
|
||||
-T '*.t_icc_inv_leg_rate' \
|
||||
-T '*.t_icc_hsd_inv_leg' \
|
||||
-T '*.t_icc_inv_leg' \
|
||||
-T '*.tcn_stat_new' \
|
||||
-T '*.tcn_stat_sales_volume_total' \
|
||||
-T '*.t_foreign_ticket_record' \
|
||||
-T '*.tcn_stat_sales_volume_tmp' \
|
||||
-T '*.t_icc_hsd_inv_seg' \
|
||||
-T '*.tcn_stat_sales_volume' \
|
||||
-T '*.t_icc_inv_seg_cabin' \
|
||||
-f ~/icc_data_20220719_test.sql
|
||||
|
||||
|
||||
#恢复
|
||||
|
||||
./pg_restore -Uenterprisedb -dtest2 -h10.23.101.119 \
|
||||
-F c ~/icc_data_20220719_test.sql
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uat
|
||||
psql -Uiccedb -diccedb -h192.168.53.118 -f ~/
|
||||
|
||||
|
||||
sit
|
||||
psql -Uicctestedb -dicctestedb -h192.168.53.123 -f ~/
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
导出导出部分数据
|
||||
|
||||
```
|
||||
COPY (select * from icc.tcn_stat
|
||||
where afferent_date between to_date('20220701','yyyymmdd') and to_date('20220714','yyyymmdd') ) TO '/home/edbdata/test.csv' WITH csv;
|
||||
|
||||
|
||||
|
||||
COPY (
|
||||
|
||||
select * from icc.tcn_stat_sales_volume_total
|
||||
where flight_date between to_date('20220701','yyyymmdd') and to_date('20221231','yyyymmdd')
|
||||
|
||||
) TO '/home/edbdata/tcn_stat_sales_volume_total.csv' WITH csv;
|
||||
|
||||
|
||||
|
||||
|
||||
COPY tcn_stat_sales_volume_total FROM '/home/edbdata/tcn_stat_sales_volume_total.csv' WITH csv;
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
39
postgresql_and_edb/postgresql锁表查询.md
Normal file
39
postgresql_and_edb/postgresql锁表查询.md
Normal file
@ -0,0 +1,39 @@
|
||||
```
|
||||
SELECT locker.pid,
|
||||
pc.relname,
|
||||
locker.mode,
|
||||
locker_act.application_name,
|
||||
least(query_start,xact_start) start_time,
|
||||
locker_act.state,
|
||||
CASE
|
||||
WHEN granted='f' THEN
|
||||
'wait_lock'
|
||||
WHEN granted='t' THEN
|
||||
'get_lock'
|
||||
END lock_satus,current_timestamp - least(query_start,xact_start) AS runtime,
|
||||
locker_act.query
|
||||
FROM pg_locks locker,pg_stat_activity locker_act, pg_class pc
|
||||
WHERE locker.pid=locker_act.pid
|
||||
AND NOT locker.pid=pg_backend_pid()
|
||||
AND application_name<>'pg_statsinfod'
|
||||
AND locker.relation = pc.oid
|
||||
AND pc.reltype<>0 --and pc.relname='t'
|
||||
ORDER BY runtime desc;
|
||||
|
||||
|
||||
SELECT pg_terminate_backend(14448)
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
```
|
||||
playboy=> select pg_size_pretty(pg_total_relation_size('test')); //查看表的总大小,包括索引大小
|
||||
pg_size_pretty
|
||||
|
||||
playboy=> select pg_size_pretty(pg_relation_size('test')); //以KB,MB,GB的方式来查看表大小
|
||||
pg_size_pretty
|
||||
|
||||
|
||||
```
|
||||
|
548
postgresql_and_edb/使用 ora2pg 将oracle 数据导入 postgresql.md
Normal file
548
postgresql_and_edb/使用 ora2pg 将oracle 数据导入 postgresql.md
Normal file
@ -0,0 +1,548 @@
|
||||
# 使用 ora2pg 将oracle 数据导入 postgresql
|
||||
|
||||
## 安装edb
|
||||
##### 安装edb 源
|
||||
|
||||
```
|
||||
|
||||
yum -y install https://yum.enterprisedb.com/edbrepos/edb-repo-latest.noarch.rpm
|
||||
|
||||
```
|
||||
|
||||
##### 设置账号密码
|
||||
|
||||
```
|
||||
|
||||
sed -i "s@<username>:<password>@start:oIVqaoGTDFL5aYHD@" /etc/yum.repos.d/edb.repo
|
||||
|
||||
```
|
||||
|
||||
##### 安装 扩展包 源
|
||||
|
||||
```
|
||||
|
||||
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
|
||||
|
||||
```
|
||||
|
||||
##### 安装edb
|
||||
|
||||
```
|
||||
|
||||
yum -y install edb-as14-server
|
||||
|
||||
```
|
||||
|
||||
##### 初始化
|
||||
|
||||
```
|
||||
|
||||
PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as14/bin/edb-as-14-setup initdb
|
||||
|
||||
PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as12/bin/edb-as-12-setup initdb
|
||||
|
||||
|
||||
|
||||
PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as12/bin/edb-as-12-setup initdb
|
||||
|
||||
```
|
||||
|
||||
##### 启动 edb
|
||||
|
||||
```
|
||||
|
||||
systemctl start edb-as-14
|
||||
|
||||
```
|
||||
|
||||
##### 连接edb
|
||||
```
|
||||
|
||||
sudo su - enterprisedb
|
||||
psql edb
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
### 常见问题
|
||||
|
||||
- 远程连接数据库失败 修改文件 data/pg_hba.conf 添加
|
||||
|
||||
```
|
||||
|
||||
host all all 0.0.0.0/0 md5
|
||||
|
||||
```
|
||||
|
||||
- 修改数据库密码(在edb 库执行)
|
||||
|
||||
```
|
||||
|
||||
ALTER USER enterprisedb WITH PASSWORD 'yiing&654';
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 安装 ora2pg
|
||||
|
||||
### 安装 perl 环境
|
||||
|
||||
```
|
||||
yum install -y perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
|
||||
yum -y install perl-CPAN
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 安装Oracle客户端
|
||||
|
||||
官网下载 Oracle Instant Client 等包 上传服务器安装
|
||||
|
||||
```
|
||||
rpm -ivh oracle-instantclient19.15-basic-19.15.0.0.0-1.x86_64.rpm
|
||||
rpm -ivh oracle-instantclient19.15-devel-19.15.0.0.0-1.x86_64.rpm
|
||||
rpm -ivh oracle-instantclient19.15-jdbc-19.15.0.0.0-1.x86_64.rpm
|
||||
rpm -ivh oracle-instantclient19.15-sqlplus-19.15.0.0.0-1.x86_64.rpm
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 设置环境变量ORACLE_HOME
|
||||
```
|
||||
export ORACLE_HOME=/usr/lib/oracle/19.15/client64/
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 本地已安装有Oracle数据库
|
||||
|
||||
ORACLE_HOME如下设置
|
||||
|
||||
```
|
||||
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
|
||||
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 安装 perl 依赖
|
||||
|
||||
```
|
||||
perl -MCPAN -e 'install DBD::Oracle'
|
||||
perl -MCPAN -e 'install DBI'
|
||||
perl -MCPAN -e 'install DBD::Pg'
|
||||
```
|
||||
|
||||
按照自己 的路径设置 环境变量
|
||||
|
||||
```
|
||||
export POSTGRES_HOME=/usr/edb/as14
|
||||
export POSTGRES_HOME=/var/lib/edb/as14
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 常见问题
|
||||
|
||||
```
|
||||
Can't locate Test/NoWarnings.pm in @INC (@INC contains: t/lib /root/.cpan/build/DBD-Oracle-1.83-LDK8k0/blib/lib /root/.cpan/build/DBD-Oracle-1.83-LDK8k0/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at t/26exe_array.t line 15.
|
||||
```
|
||||
|
||||
安装 perl-Test-NoWarnings-1.04-2.el7.noarch 解决
|
||||
|
||||
|
||||
|
||||
提示测试不通过 手动下载源码 安装
|
||||
|
||||
下载地址:https://metacpan.org/release/DBI
|
||||
|
||||
```
|
||||
tar -zxvf DBI-1.642.tar.gz
|
||||
cd DBI-1.642
|
||||
perl Makefile.PL
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### 安装ora2pg
|
||||
|
||||
下载软件包
|
||||
https://github.com/darold/ora2pg/releases
|
||||
|
||||
默认安装在`/usr/local/bin/` 目录下
|
||||
|
||||
```
|
||||
[root@Test01 ~]# tar -xjf ora2pg-20.0.tar.bz2
|
||||
[root@Test01 ~]# cd ora2pg-xx/
|
||||
[root@Test01 ~]# perl Makefile.PL PREFIX=<your_install_dir>
|
||||
[root@Test01 ora2pg-18.2]# make && make install
|
||||
```
|
||||
|
||||
简单检查
|
||||
ora2pg --help
|
||||
|
||||
## 迁移数据
|
||||
### 初始化项目
|
||||
|
||||
```
|
||||
//初始化项目
|
||||
ora2pg --init_project ora2pg
|
||||
|
||||
|
||||
ora2pg -t SHOW_VERSION -c config/ora2pg.conf
|
||||
ora2pg -t SHOW_SCHEMA -c config/ora2pg.conf
|
||||
ora2pg -t SHOW_TABLE -c config/ora2pg.conf
|
||||
ora2pg -t SHOW_COLUMN -c config/ora2pg.conf
|
||||
ora2pg -t SHOW_ENCODING -c config/ora2pg.conf
|
||||
```
|
||||
|
||||
### 配置配置文件
|
||||
|
||||
默认配置文件即可 需要修改
|
||||
|
||||
```
|
||||
# Set Oracle database connection (datasource, user, password)
|
||||
ORACLE_DSN dbi:Oracle:host=dev-db.yldev.net;sid=hcc;port=1521
|
||||
ORACLE_USER icc
|
||||
ORACLE_PWD ICCICC
|
||||
|
||||
# Oracle schema/owner to use
|
||||
SCHEMA ICC
|
||||
|
||||
|
||||
|
||||
# Set which object to export from. By default Ora2Pg export all objects.
|
||||
# Value must be a list of object name or regex separated by space. Note
|
||||
# that regex will not works with 8i database, use % placeholder instead
|
||||
# Ora2Pg will use the LIKE operator. There is also some extended use of
|
||||
# this directive, see chapter "Limiting object to export" in documentation.
|
||||
|
||||
|
||||
# 可以使用正则 如 t_.* 可以排除 不想导出的对象 如!t_t2
|
||||
#配置中文释义 https://blog.csdn.net/Loiterer_Y/article/details/110927688
|
||||
#ALLOW TABLE_TEST
|
||||
|
||||
# The value can be a comma delimited list of schema but not when using TABLE
|
||||
# export type because in this case it will generate the CREATE SCHEMA statement
|
||||
# and it doesn't support multiple schema name. For example, if you set PG_SCHEMA
|
||||
# to something like "user_schema, public", the search path will be set like this
|
||||
# SET search_path = user_schema, public;
|
||||
# forcing the use of an other schema (here user_schema) than the one from Oracle
|
||||
# schema set in the SCHEMA directive. You can also set the default search_path
|
||||
# for the PostgreSQL user you are using to connect to the destination database
|
||||
# by using:
|
||||
# ALTER ROLE username SET search_path TO user_schema, public;
|
||||
#in this case you don't have to set PG_SCHEMA.
|
||||
#PG_SCHEMA LLOW
|
||||
PG_SCHEMA icc
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 测试连接
|
||||
|
||||
执行以下命令 返回oracle 版本则连接成功
|
||||
|
||||
```
|
||||
ora2pg -t SHOW_VERSION -c config/ora2pg.conf
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 导出表结构
|
||||
|
||||
先安装 screen 防止意外断开 导出失败
|
||||
|
||||
```
|
||||
yum install -y screen
|
||||
|
||||
```
|
||||
|
||||
#### screen 常用命令
|
||||
|
||||
```
|
||||
//开启一个screen
|
||||
screen -S name
|
||||
//进入一个 screen
|
||||
screen -r name
|
||||
// screen 列表
|
||||
screen -ls
|
||||
|
||||
可以用快捷键 Ctrl+a d(即按住 Ctrl,依次再按 a,d),而会话中的程序不会关闭
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 导出数据
|
||||
|
||||
该命令根据数据库大小 表大小等待时间不一 建议使用screen 运行
|
||||
|
||||
```
|
||||
ora2pg -t COPY -o data.sql -b ./data -c ./config/ora2pg.conf
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 修改校验表结构
|
||||
|
||||
导出完成后 在 `./schema/tables` 下有转换好的表结构(主要修改关键字段)
|
||||
|
||||
```
|
||||
oid
|
||||
tableoid
|
||||
xmin
|
||||
cmin
|
||||
xmax
|
||||
cmax
|
||||
ctid
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 导入数据库
|
||||
|
||||
切换到`enterprisedb` 用户
|
||||
|
||||
执行 `sh import_all.sh` 按照提示导入数据
|
||||
|
||||
|
||||
|
||||
## 附录
|
||||
|
||||
#### 修改用户组 权限
|
||||
|
||||
```
|
||||
chown [-R] ownname:groupname filename
|
||||
chmod -R 777 filename
|
||||
|
||||
```
|
||||
|
||||
#### 追踪服务日志
|
||||
|
||||
```
|
||||
journalctl -f -u icc-analysis.service
|
||||
```
|
||||
|
||||
#### 查看文件大小
|
||||
|
||||
```
|
||||
df -hl
|
||||
df -h path
|
||||
ls -lht
|
||||
|
||||
du -ah --max-depth=1 /path
|
||||
|
||||
查看删除的文件
|
||||
lsof -n | grep deleted
|
||||
|
||||
du -bsh /
|
||||
```
|
||||
|
||||
#### Linux 替换命令 sed
|
||||
|
||||
```
|
||||
参数说明:
|
||||
|
||||
-e<script>或--expression=<script> 以选项中指定的script来处理输入的文本文件。
|
||||
-f<script文件>或--file=<script文件> 以选项中指定的script文件来处理输入的文本文件。
|
||||
-h或--help 显示帮助。
|
||||
-n或--quiet或--silent 仅显示script处理后的结果。
|
||||
-V或--version 显示版本信息。
|
||||
|
||||
动作说明:
|
||||
|
||||
a :新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~
|
||||
c :取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!
|
||||
d :删除,因为是删除啊,所以 d 后面通常不接任何东东;
|
||||
i :插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);
|
||||
p :打印,亦即将某个选择的数据印出。通常 p 会与参数 sed -n 一起运行~
|
||||
s :取代,可以直接进行取代的工作哩!通常这个 s 的动作可以搭配正规表示法!例如 1,20s/old/new/g 就是啦!
|
||||
实例
|
||||
|
||||
可以使用正则 特殊字符\转义
|
||||
|
||||
|
||||
sed ”s/要被取代的字串/新的字串/g“ fileName
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### psql 导入导出文件
|
||||
|
||||
```
|
||||
//导入
|
||||
pg_restore
|
||||
psql -Uicc -dicc -f ./xxx.sql
|
||||
psql -Uicc -dicc -h10.23.101.52 -f ./schema/tables/table.sql
|
||||
|
||||
//导出表 模式 数据
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc> ~/dum.sql
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc -f icc.dmp
|
||||
|
||||
报错停止 -v ON_ERROR_STOP=1
|
||||
|
||||
-a 只要数据
|
||||
-s 只要表结构
|
||||
-O 不设置表归属
|
||||
-n, --schema=SCHEMA 只转储指定名称的模式
|
||||
-T 排除表
|
||||
-t 指定表
|
||||
-Z 压缩0-9
|
||||
|
||||
|
||||
pg_dump -U postgres vendemo | gzip > /vendemo.gz 备份下来只有30多k
|
||||
|
||||
// 导出压缩文件
|
||||
pg_dump -h10.23.101.52 -Uicc -dicc -t 表名 -t表名 -a -O | gzip > iccData.gz
|
||||
pg_dump -Uicc -dicc | gzip > iccData.gz
|
||||
|
||||
|
||||
//导入压缩文件
|
||||
gzip -d iccData.gz | psql -Uicc -dicc -h10.23.101.52
|
||||
//没测试过
|
||||
psql -Uicctestedb -dicctestedb < gzip -d iccData.gz
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
./pg_dump -h10.23.101.119 -Uicc -dicc -o | gzip > ~/iccData_202206231632.gz
|
||||
|
||||
|
||||
psql -U iccedb -d iccedb -h 192.168.53.118 -n 'icc2' | gzip > ~/iccedb_icc2_202206301142.gz
|
||||
|
||||
psql -U iccedb -d iccedb -h 192.168.53.118 -v schema=icc2 | gzip > ~/iccedb_icc2_202206301142.gz
|
||||
|
||||
|
||||
gzip -d ~/iccData_202206231634.gz | psql -Uiccedb -diccedb -h192.168.53.118
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pg_dump -Uenterprisedb -diccedb -h192.168.53.118 -n icc2 | gzip > ~/iccedb_icc2_202206301214.gz
|
||||
|
||||
|
||||
|
||||
pg_dump -Uenterprisedb -dicc -h10.23.101.119 -n icc | gzip > ~/icc_icc_202207011859.gz
|
||||
|
||||
|
||||
pg_dump -t 'icc.*' -T icc.t_icc_inv_leg -T icc.t_icc_inv_leg_rate -T tcn_stat_new-dicc > ~/icc_icc_202207081700.sql
|
||||
|
||||
|
||||
|
||||
pg_dump -Uenterprisedb -dicc -h10.23.101.119 \
|
||||
-T t_icc_inv_leg \
|
||||
-T t_icc_inv_leg_rate \
|
||||
-T tcn_stat_new | gzip > ~/icc_icc_202207081500.gz
|
||||
|
||||
|
||||
|
||||
./pg_dump -Uenterprisedb -dicc -h10.23.101.119 -O \
|
||||
-n icc -s \
|
||||
-f ~/icc_data_20220719_2130.sql
|
||||
|
||||
yiing&654
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#导出 icc 模式下 排除 t_icc_inv_seg 等表 采用自定义格式压缩等级9(最大)
|
||||
|
||||
./pg_dump -Uenterprisedb -dicc -h10.23.101.119 \
|
||||
-O -v -F c -Z 9 \
|
||||
-t 'icc.*' \
|
||||
-T '*.t_icc_inv_seg' \
|
||||
-T '*.t_icc_inv_leg_rate' \
|
||||
-T '*.t_icc_hsd_inv_leg' \
|
||||
-T '*.t_icc_inv_leg' \
|
||||
-T '*.tcn_stat_new' \
|
||||
-T '*.tcn_stat_sales_volume_total' \
|
||||
-T '*.t_foreign_ticket_record' \
|
||||
-T '*.tcn_stat_sales_volume_tmp' \
|
||||
-T '*.t_icc_hsd_inv_seg' \
|
||||
-T '*.tcn_stat_sales_volume' \
|
||||
-T '*.t_icc_inv_seg_cabin' \
|
||||
-f ~/icc_data_20220719_test.sql
|
||||
|
||||
|
||||
恢复
|
||||
./pg_restore -Uenterprisedb -dtest2 -h10.23.101.119 \
|
||||
-F c -c --strict-names ~/icc_data_20220719_test.sql
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
./pg_dump -Uenterprisedb -diccedb -h192.168.53.118 -O -a -f ~/diccedb_202207_29.data.sql
|
||||
|
||||
|
||||
|
||||
|
||||
./pg_dump -h10.23.101.242 -Uenterprisedb -dalgorithm | gzip > /home/algorithmEdbData.gz
|
||||
|
||||
|
||||
算法私服
|
||||
/usr/edb/as12/bin/psql -Uenterprisedb -dalgorithm -h172.27.127.101 -f /home/wayne/algorithmEdbData
|
||||
/usr/edb/as12/bin/pg_dump -h10.23.101.242 -Uenterprisedb -dalgorithm | gzip > /home/algorithmEdbData.gz
|
||||
|
||||
|
||||
|
||||
算法
|
||||
./psql -Uenterprisedb -dalgorithm -h10.23.101.242
|
||||
./pg_dump -h10.23.101.242 -Uenterprisedb -dalgorithm | gzip > /home/algorithmEdbData.gz
|
||||
|
||||
|
||||
uat
|
||||
psql -Uiccedb -diccedb -h192.168.53.118 -f ~/
|
||||
|
||||
|
||||
sit
|
||||
psql -Uicctestedb -dicctestedb -h192.168.53.123 -f ~/
|
||||
|
||||
|
||||
```
|
||||
|
||||
#### 查询连接数
|
||||
|
||||
```
|
||||
show max_connections;
|
||||
SELECT COUNT(*) from pg_stat_activity;
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### edb9 启动方式
|
||||
|
||||
```
|
||||
Linux:
|
||||
/etc/init.d/ppas-9.x <start|stop|restart|status|reload>
|
||||
service ppas-9.x <start|stop|restart|status|reload>
|
||||
通用方式:
|
||||
sudo su - enterprisedb
|
||||
$PGHOME/bin/pg_ctl <start|stop|restart|status|reload> [options]
|
||||
|
||||
opt/PostgresPlus/9.5AS
|
||||
```
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user