Oracle迁移到PostgreSQL的一些经验
来源:互联网 发布:java web开发书籍推荐 编辑:程序博客网 时间:2024/05/16 19:49
原文地址:
http://blog.sina.com.cn/s/blog_8742444201012y03.html
http://blog.sina.com.cn/s/blog_8742444201012y0h.html
Oracle迁移到PostgreSQL的一些经验(一)
(2012-04-09 16:36:34)最近遇到数据库由Oracle迁移到PostgreSQL的一些问题,结合网上搜索到信息,将我的解决办法记录如下:
1 安装及配置
1.1 安装
在windowXP下安装 PostgreSQL 9.1:
Ø
Ø
Ø
Ø
Ø
1.2 配置
1.1.1远程连接:
修改文件:D:\PostgreSQL\9.1\data\pg_hba.conf, 增加:
**********************************
host
**********************************
使得ip在 192.168.0.0 到 192.168.0.255 之间的客户端可以通过密码访问数据库.
修改文件:D:\PostgreSQL\9.1\data\postgresql.conf,确保:
**********************************
listen_address = '*'
**********************************
1.1.2 表空间访问权限
创建表空间文件夹:
2 创建数据库脚本
2.1 创建用户及表空间脚本
CreateTableSpace.sql
**********************************
CREATE ROLE myuser LOGIN
CREATE TABLESPACE mytablespace
OWNER myuser
LOCATION 'E:/PostgreSQL/mytablespace';**********************************
2.2 创建数据库脚本
CreateTableSpace.sql
**********************************
CREATE DATABASE mydb
**********************************
2.3 建表脚本
CREATE TABLE
(
);
ALTER TABLE mytable OWNER TO myuser;2.4 导入缺省数据
Insert.sql
**********************************
insert into mytable (id, value)
insert into
**********************************
2.5 批处理文件
set PGUSER=postgres
set PGPASSWORD=postgres
c:\Progra~1\PostgreSQL\9.1\bin\psql.exe -f CreateTableSpace.sql
c:\Progra~1\PostgreSQL\9.1\bin\psql.exe -d mydb -f CreateTable.sql
Oracle迁移到PostgreSQL的一些经验(二)
(2012-04-09 16:43:29)3
3.1
Oracle
PostgreSQL
VARCHAR2
VARCHAR
Long、
TEXT
DATE
DATE/TIME/TIMESTAMP
NUMBER
SMALLINT/INTEGER/BIGINT/NUMERIC/REAL/DOUBLE PRECISION
BLOB
SMALLINT/INTEGER/BIGINT/NUMERIC/REAL/DOUBLE PRECISION
sysdate
now()、O_TIMESTAMP(CURRENT_TIMESTAMP,'YYYY-MM-DD HH24:MI:SS')、CURRENT_TIMESTAMP
Tips: PostgreSQL 中字段名区分大小写,为保证兼容行,强烈建议脚本中的字符均用小写,这样在Sql语句中将忽略大小写。
3.2
Function
Returns
Example
to_char(timestamp, text)
text
to_char(timestamp 'now','HH12:MI:SS')
to_char(interval, text)
text
to_char(interval '15h 2m 12s','HH24:MI:SS')
to_char(int, text)
text
to_char(125, '999')
to_char(double precision, text)
text
to_char(125.8, '999D9')
to_char(numeric, text)
text
to_char(numeric '-125.8', '999D99S')
to_date(text, text)
date
to_date('05 Dec 2000', 'DD Mon YYYY')
to_timestamp(text, text)
timestamp
to_timestamp('05 Dec 2000', 'DD Mon YYYY')
to_number(text, text)
numeric
to_number('12,454.8-', '99G999D9S')
3.3
Oracle
PostgreSQL
Constraint
alter table schema.prefix_info add (
constraint pk_prefix_info primary key (info_id));
alter table schema.prefix_info add constraint prefix_info_pkey primary key(info_id);
Default Maximun in sequence
create sequence prefix_info_sequence
increment by 1
start with 582
minvalue 1
maxvalue 999999999999999999999999
nocycle
cache 20
noorder;
create sequence schema.prefix_info_sequence
increment 1
minvalue 1
maxvalue 9223372036854775807
start 582
cache 20;
||
select a||b from table1;
returns null when there is one null value in a and b.
Dual table
select sysdate from dual;
select now();
Associated query
select count(distinct(a.col1)) as rcount from
schema.prefix_table1 a,schema.prefix_table2 b
where 1 = 1
and a.col2 = b.col2(+)
and a.col3 > 0
and a.col4 = '1'
select count(distinct(a.col1)) as rcount from
schema.prefix_table1 a left outer join schema.prefix_table2 b on (a.col2 = b.col2)
where 1 = 1
select count(distinct(a.col1)) as rcount from
schema.prefix_table1 a,schema.prefix_table2 b,schema.prefix_table3 c,schema.prefix_table4 d
where 1 = 1
and a.col2 = b.col2
and a.col3 = c.col3(+)
and a.col4 = d.col4(+)
and a.col5 > 0
and a.col6 = '1'
select count(distinct(a.col1)) as rcount from
schema.prefix_table1 a inner join schema.prefix_table2 b on (a.col2 = b.col2)
left outer join schema.prefix_table3 c on (a.col3 = c.col3)
left outer join schema.prefix_table4 d on (a.col4 = d.col4)
where 1 = 1
and a.col5 > 0
and a.col6 = '1'
Subquery
oracle:
select * from (
select * from (
select * from schema.prefix_table order by col1
) where x=1 order by col2
) where y=2 order by col3
select * from (
select * from (
select * from schema.prefix_table order by col1 alias1
) where x=1 order by col2 alias2
) where y=2 order by col3
Rownum
Vs
limit
select * from ( select * from (select * from schema.prefix_table1 order by col1 desc,col2 asc) where rownum <= 50 order by col3 asc,col4 desc)
where rownum <= 20 order by col5 desc,col6 asc;
select * from ( select * from (select * from schema.prefix_table1 order by col1 desc,col2 asc) selb order by col3 asc,col4 desc limit 50 ) sela
order by col5 desc,col6 asc limit 20;
limit must be used after order by
sequence
select schema.prefix_table1_sequence.nextval as ncode from dual
select nextval('schema.prefix_table1_sequence') as ncode
AS
select a.col1
select a.col1 as a_col1,a.col2 as a_col2
NVL
select nvl(sum(value11),0) fs_value1, nvl(sum(value21),0) fs_value2
select
from
Decode
select decode(endflag,'1','a','b') endflagfrom
select (caseendflag
参考:
http://ken-81710.iteye.com/blog/346639
- Oracle迁移到PostgreSQL的一些经验
- Cocolog 从 PostgreSQL 迁移到 MySQL 的经验
- postgresql数据库迁移到oracle
- Oracle迁移到PostgreSQL问题
- Oracle迁移Postgresql 遇到的一些问题记录
- 使用ora2pg完成从oracle到postgresql的迁移工作
- mysql 迁移到postgresql
- oracle向PostgreSQL迁移
- Oracle迁移PostgreSQL经验总结
- Mac上使用Ora2Pg迁移Oracle到PostgreSQL
- Oracle迁移到MySQL 一些注意
- 从jbuilder迁移到netbeans的经验
- 从jbuilder迁移到netbeans的经验
- ORACLE迁移中的一些经验(一)批量导出sequence
- 数据库迁移,postgresql到oracle9i
- MySQL数据库迁移到PostgreSQL
- Berkeley DB迁移到PostgreSQL遇到的问题
- 将MySQL数据迁移到PostgreSQL的工具 - mysql2psql
- rails 4.0.0 rails bootstrap
- artDialog双击会关闭对话框
- UNIX网络编程,时间获取服务器的搭建,程序运行
- 使用 PyInstaller 把python程序 .py转为 .exe 可执行程序
- VS2010+VMWare 远程调试exe程序的配置总结
- Oracle迁移到PostgreSQL的一些经验
- 哈佛气质课
- 【Java工程师之路】[2-4.3]OCI方式访问Oracle数据库
- oracle缩小表空间
- 自定义按住按钮拖动窗体
- android 更新SDK 失败解决办法
- canvas讲解进阶篇四
- C#操作XML文件
- ubuntu svn安装和使用