SlideShare a Scribd company logo
Oracle to PostgreSQL
Top 10 Mistakes
Who Am I?
●
Jim Mlodgenski
– jimm@openscg.com
– @jim_mlodgenski
●
Co-Chair
– PGConf US
●
Director
– United States PostgreSQL (www.postgresql.us)
●
Co-organizer of
– Philly PUG (www.phlpug.org)
– NYC PUG (www.nycpug.org)
●
CTO, OpenSCG
– www.openscg.com
Why?
●
Project deadline
– Looming Oracle renewal
●
Lack of education
●
Attitude
– Only see the world through an Oracle lens
●
Using migration tools or other short cuts
Oracle postgre sql-mirgration-top-10-mistakes
System Tuning
●
When moving to PostgreSQL, many
admins start with configuring values
similar to the Oracle settings
– My SGA was set to 16GB so
shared_buffers is 16GB
– My redo logs are 2GB so max_wal_size
is 2GB
System Tuning
●
In Oracle, I get better performance with
a 32k block size
configure –with-blocksize=32
make
make install
Oracle postgre sql-mirgration-top-10-mistakes
Uppercase Folding
●
In Oracle, all meta-data folds to uppercase
SQL> DESC USERS
Name Null? Type
---------- ------- ------------------------
FNAME VARCHAR2(100)
MNAME VARCHAR2(100)
LNAME VARCHAR2(100)
Uppercase Folding
●
In PostgreSQL, all meta-data folds to
lowercase
test=# d users
Table "public.users"
Column | Type | Nullable
--------+------------------------+---------
fname | character varying(100) |
mname | character varying(100) |
lname | character varying(100) |
Uppercase Folding
●
Many migration tools carry the uppercase
from Oracle over to PostgreSQL
test=# d "USERS"
Table "public.USERS"
Column | Type | Nullable
--------+------------------------+----------
FNAME | character varying(100) |
MNAME | character varying(100) |
LNAME | character varying(100) |
Uppercase Folding
●
Becomes very tedious needing to double quote everything
test=# SELECT "FNAME", "MNAME", "LNAME" FROM "USERS";
FNAME | MNAME | LNAME
---------+--------+------------
George | | Washington
John | | Adams
Thomas | | Jefferson
James | | Madison
James | | Monroe
Andrew | | Jackson
Martin | | Van Buren
John | | Tyler
John | Quincy | Adams
William | Henry | Harrison
(10 rows)
Oracle postgre sql-mirgration-top-10-mistakes
Table Spaces
●
In Oracle, table spaces are critical for storing data
●
Generally many table spaces are used for indexes and
tables
CREATE TABLESPACE ts_data1
LOGGING
DATAFILE '/data/ts_data1.dbf'
SIZE 32m
AUTOEXTEND ON
NEXT 32m MAXSIZE 2048m
EXTENT MANAGEMENT local;
Table Spaces
●
In PostgreSQL, table spaces are just
directory locations
●
Provide no real benefit unless the
database spans multiple mount points
CREATE TABLESPACE ts_data1
LOCATION '/data/ts_data1';
Table Spaces
●
Additional table spaces makes operations
more cumbersome like
– Backup and restore
– Replication setup
– Major version upgrades
Oracle postgre sql-mirgration-top-10-mistakes
Dual Table
SQL> SELECT SYSDATE FROM DUAL;
SYSDATE
---------
09-MAY-17
Dual Table
●
In PostgreSQL, the FROM clause is optional
and is unnecessary
●
Don’t mock a DUAL table
test=# SELECT CURRENT_DATE;
current_date
--------------
2017-05-09
(1 row)
Oracle postgre sql-mirgration-top-10-mistakes
Exceptions
●
Many Oracle procedures use exceptions
as part of standard practice
– Application developers are comfortable
catching exceptions
●
Some applications have exception
handling in every procedure and function
●
Most migration tools simply translate the
code to pl/pgsql
Exceptions
CREATE FUNCTION get_first_name(p_lname varchar2)
RETURN varchar2
IS
l_fname varchar2(100);
BEGIN
SELECT fname
INTO l_fname
FROM users
WHERE lname = p_lname;
RETURN l_fname;
EXCEPTION
WHEN no_data_found THEN
l_fname := null;
RETURN l_fname;
END get_first_name;
Exceptions
CREATE FUNCTION get_first_name(p_lname varchar)
RETURNS varchar
AS $$
DECLARE
l_fname varchar;
BEGIN
SELECT fname
INTO l_fname
FROM users
WHERE lname = p_lname;
RETURN l_fname;
EXCEPTION
WHEN no_data_found THEN
l_fname := null;
RETURN l_fname;
END
$$ LANGUAGE plpgsql;
Exceptions
●
PostgreSQL uses sub transactions to handle
exceptions
CREATE OR REPLACE FUNCTION get_first_name(p_lname varchar)
RETURNS varchar
AS $$
DECLARE
l_fname varchar := null;
BEGIN
SELECT fname
INTO l_fname
FROM users
WHERE lname = p_lname;
RETURN l_fname;
END
$$ LANGUAGE plpgsql;
Oracle postgre sql-mirgration-top-10-mistakes
Fine Tuning Queries
●
“I added a hint to use an index but
PostgreSQL does not use it”
– PostgreSQL does not have hints
●
It treats Oracle hints as comments
●
PostgreSQL’s optimizer is different than
Oracle so queries are tuned differently
Fine Tuning Queries
●
B-tree
●
Hash
●
GIN
●
GiST
●
SP-GiST
●
BRIN
●
“I didn’t index my column in Oracle, why
would I in PostgreSQL?”
●
PostgreSQL has more and different types
of indexes than Oracle
Fine Tuning Queries
●
PostgreSQL can even use indexes on LIKE queries
CREATE INDEX idx_users_lname
ON users USING gin (lname gin_trgm_ops);
EXPLAIN SELECT * FROM users WHERE lname LIKE '%ing%';
QUERY PLAN
-----------------------------------------------------
Bitmap Heap Scan on users (cost=8.00..12.02 rows=1
width=654)
Recheck Cond: ((lname)::text ~~ '%ing%'::text)
-> Bitmap Index Scan on idx_users_lname
(cost=0.00..8.00 rows=1 width=0)
Index Cond: ((lname)::text ~~ '%ing%'::text)
Oracle postgre sql-mirgration-top-10-mistakes
Not Using Native Features
●
PostgreSQL is more feature rich for
developers than Oracle
– Stored Procedure Languages
– Foreign Data Wrappers
– Data Types
– Spatial
Not Using Native Features
CREATE OR REPLACE FUNCTION has_valid_keys(doc json)
RETURNS boolean AS
$$
if (!doc.hasOwnProperty('fname'))
return false;
if (!doc.hasOwnProperty('lname'))
return false;
return true;
$$ LANGUAGE plv8 IMMUTABLE;
ALTER TABLE user_collection
ADD CONSTRAINT collection_key_chk
CHECK (has_valid_keys(doc::json));
Not Using Native Features
CREATE TABLE login_history (
user_id bigint,
host inet,
login_ts timestamptz
);
SELECT user_id, count(*)
FROM login_history
WHERE host << '17.0.0.0/8'::inet
AND login_ts > now() - '7 days'::interval
GROUP BY 1;
Oracle postgre sql-mirgration-top-10-mistakes
Synonyms
“PostgreSQL doesn’t have synonyms so I
can’t migrate my application”
CREATE PUBLIC SYNONYM emp
FOR SCOTT.emp;
●
Synonyms are used to not fully qualify cross
schema objects
●
Mostly a convenience feature
Synonyms
●
In PostgreSQL, search_path can
accomplish many of the same things and is
less tedious to setup
test=# show search_path;
search_path
-----------------
"$user", public
(1 row)
Synonyms
CREATE FUNCTION user1.get_int()
RETURNS int AS
$$
SELECT 1;
$$ LANGUAGE sql;
CREATE FUNCTION user2.get_int()
RETURNS int AS
$$
SELECT 2;
$$ LANGUAGE sql;
CREATE FUNCTION public.get_number()
RETURNS float8 AS
$$
SELECT 3.14::float8;
$$ LANGUAGE sql;
Synonyms
test=# SELECT get_int();
2017-05-08 17:38:50.367 EDT [28855] ERROR: function
get_int() does not exist at character 8
2017-05-08 17:38:50.367 EDT [28855] HINT: No
function matches the given name and argument types.
You might need to add explicit type casts.
2017-05-08 17:38:50.367 EDT [28855] STATEMENT:
SELECT get_int();
ERROR: function get_int() does not exist
LINE 1: SELECT get_int();
^
HINT: No function matches the given name and
argument types. You might need to add explicit type
casts.
Synonyms
test=# SET search_path = user1,
user2, public;
SET
test=# SELECT get_int();
get_int
---------
1
(1 row)
Synonyms
test=# SET search_path = user2,
user1, public;
SET
test=# SELECT get_int();
get_int
---------
2
(1 row)
Synonyms
test=# select get_number();
get_number
------------
3.14
(1 row)
Oracle postgre sql-mirgration-top-10-mistakes
Nulls
●
PostgreSQL and Oracle handle nulls a bit
differently
– Need to account for them appropriately
– Most often seen with string concatenation
Nulls
CREATE TABLE users (
fname VARCHAR2(100),
mname VARCHAR2(100),
lname VARCHAR2(100)
);
SELECT
fname || ' ' || mname || ' ' || lname
FROM users;
Nulls
SQL> SELECT fname || ' ' || mname || ' ' || lname FROM users;
FNAME||''||MNAME||''||LNAME
---------------------------------------------------------------
George Washington
John Adams
Thomas Jefferson
James Madison
James Monroe
Andrew Jackson
Martin Van Buren
John Tyler
John Quincy Adams
William Henry Harrison
10 rows selected.
Nulls
test=# SELECT fname || ' ' || mname || ' ' || lname FROM
users;
?column?
------------------------
John Quincy Adams
William Henry Harrison
(10 rows)
Nulls
test=# SELECT COALESCE(fname, '') || ' ' || COALESCE(mname,
'') || ' ' || COALESCE(lname, '') FROM users;
?column?
------------------------
George Washington
John Adams
Thomas Jefferson
James Madison
James Monroe
Andrew Jackson
Martin Van Buren
John Tyler
John Quincy Adams
William Henry Harrison
(10 rows)
Oracle postgre sql-mirgration-top-10-mistakes
Data Types
●
Oracle has a few main data types that are
typically used
– VARCHAR2
– DATE
– NUMBER
●
And a couple Large Object types
– CLOB
– BLOB
Data Types
●
PostgreSQL comes with 64 base types
and can be extended for more
abstime
aclitem
bit
bool
box
bpchar
bytea
char
cid
cidr
circle
date
float4
float8
gtsvector
inet
int2
int2vector
int4
int8
interval
json
jsonb
line
lseg
macaddr
money
name
numeric
oid
oidvector
path
pg_lsn
pg_node_tree
point
polygon
refcursor
regclass
regconfig
regdictionar
y
regnamespace
regoper
regoperator
regproc
regprocedure
regrole
regtype
reltime
smgr
text
tid
time
timestamp
timestamptz
timetz
tinterval
tsquery
tsvector
txid_snapshot
uuid
varbit
varchar
xid
xml
Data Types
●
Don’t assume that the perceived equivalent
in PostgreSQL behaves the same as Oracle
– For example, managing CLOBS
●
Length
●
Substrings
DBMS_LOB.GETLENGTH(x)
Data Types
●
In PostgreSQL, VARCHAR and TEXT are equivalent
and behave the same
CREATE TABLE max_varchar (
a varchar(4001)
);
CREATE TABLE max_varchar (
a varchar(10485760)
);
Data Types
CREATE TABLE max_varchar (
a varchar
);
CREATE TABLE max_varchar (
a text
);
Data Types
test=# INSERT INTO max_varchar SELECT
repeat('x', 1073741800);
INSERT 0 1
test=# SELECT length(a) from
max_varchar ;
length
------------
1073741800
(1 row)
Data Types
Data Types
●
Most migration tools translate an Oracle
NUMBER to a PostgreSQL NUMERIC
– A PostgreSQL NUMERIC can hold
●
131072 before the decimal point
●
16383 after the decimal point
●
It is not the same are NUMBER
SELECT to_number(n, n)
FROM repeat('9', 131071) n;
Summary
●
System Tuning
●
Case Folding
●
Table Spaces
●
Dual Table
●
Exceptions
●
Fine Tuning
●
Native Features
●
Synonyms
●
Nulls
●
Data Types
Oracle postgre sql-mirgration-top-10-mistakes
Oracle postgre sql-mirgration-top-10-mistakes
Biggest Mistake
●
Paying for a commercial database when it
is not necessary
– Listening to the FUD
– Building new solutions on Oracle
– Not learning PostgreSQL to leverage its great
features and functionality
Questions?
jimm@openscg.com
@jim_mlodgenski
Ad

More Related Content

What's hot (19)

SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade DowntimeSCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
Jeff Frost
 
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
Mark Wong
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQL
Mark Wong
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
Sergey Petrunya
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
Peter Eisentraut
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
Sergey Petrunya
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2
afa reg
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
Jeremy Coates
 
FIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11GFIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11G
N/A
 
Apollo ecosystem
Apollo ecosystemApollo ecosystem
Apollo ecosystem
James Akwuh
 
Quick reference for mongo shell commands
Quick reference for mongo shell commandsQuick reference for mongo shell commands
Quick reference for mongo shell commands
Rajkumar Asohan, PMP
 
Basic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition PresentationBasic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition Presentation
N/A
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
Antony T Curtis
 
Test Dml With Nologging
Test Dml With NologgingTest Dml With Nologging
Test Dml With Nologging
N/A
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
Sergey Petrunya
 
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade DowntimeSCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
Jeff Frost
 
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam 2018 - Daniel Westermann - What we already know about Postgre...
PGDay.Amsterdam
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
Mark Wong
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQL
Mark Wong
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
Sergey Petrunya
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
Peter Eisentraut
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
Sergey Petrunya
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2
afa reg
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
Jeremy Coates
 
FIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11GFIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11G
N/A
 
Apollo ecosystem
Apollo ecosystemApollo ecosystem
Apollo ecosystem
James Akwuh
 
Quick reference for mongo shell commands
Quick reference for mongo shell commandsQuick reference for mongo shell commands
Quick reference for mongo shell commands
Rajkumar Asohan, PMP
 
Basic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition PresentationBasic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition Presentation
N/A
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
Antony T Curtis
 
Test Dml With Nologging
Test Dml With NologgingTest Dml With Nologging
Test Dml With Nologging
N/A
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
Sergey Petrunya
 

Similar to Oracle postgre sql-mirgration-top-10-mistakes (20)

Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
Yuriy Gerasimov
 
AutoDOPandRest
AutoDOPandRestAutoDOPandRest
AutoDOPandRest
Rick van Ek
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
FromDual GmbH
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
anandology
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
Anurag Srivastava
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
Andrew Dunstan
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
InMobi Technology
 
Php modul-3
Php modul-3Php modul-3
Php modul-3
Kristophorus Hadiono
 
Getting by with just psql
Getting by with just psqlGetting by with just psql
Getting by with just psql
Corey Huinker
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
PostgreSQL 9.5 Features
PostgreSQL 9.5 FeaturesPostgreSQL 9.5 Features
PostgreSQL 9.5 Features
Saiful
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
Odoo
 
Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
Valeriy Kravchuk
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
Yuriy Gerasimov
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
FromDual GmbH
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
anandology
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
Andrew Dunstan
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
InMobi Technology
 
Getting by with just psql
Getting by with just psqlGetting by with just psql
Getting by with just psql
Corey Huinker
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
PostgreSQL 9.5 Features
PostgreSQL 9.5 FeaturesPostgreSQL 9.5 Features
PostgreSQL 9.5 Features
Saiful
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
Odoo
 
Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
Valeriy Kravchuk
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Ad

More from Jim Mlodgenski (8)

Debugging Your PL/pgSQL Code
Debugging Your PL/pgSQL CodeDebugging Your PL/pgSQL Code
Debugging Your PL/pgSQL Code
Jim Mlodgenski
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
Jim Mlodgenski
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
Postgresql Federation
Postgresql FederationPostgresql Federation
Postgresql Federation
Jim Mlodgenski
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentLeveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
Scaling PostreSQL with Stado
Scaling PostreSQL with StadoScaling PostreSQL with Stado
Scaling PostreSQL with Stado
Jim Mlodgenski
 
Multi-Master Replication with Slony
Multi-Master Replication with SlonyMulti-Master Replication with Slony
Multi-Master Replication with Slony
Jim Mlodgenski
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
Jim Mlodgenski
 
Debugging Your PL/pgSQL Code
Debugging Your PL/pgSQL CodeDebugging Your PL/pgSQL Code
Debugging Your PL/pgSQL Code
Jim Mlodgenski
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
Jim Mlodgenski
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentLeveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
Scaling PostreSQL with Stado
Scaling PostreSQL with StadoScaling PostreSQL with Stado
Scaling PostreSQL with Stado
Jim Mlodgenski
 
Multi-Master Replication with Slony
Multi-Master Replication with SlonyMulti-Master Replication with Slony
Multi-Master Replication with Slony
Jim Mlodgenski
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
Jim Mlodgenski
 
Ad

Recently uploaded (15)

introduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.pptintroduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.ppt
SherifElGohary7
 
Breaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdfBreaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdf
Internet Bundle Now
 
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
Taqyea
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
werhkr1
 
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
Paper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdfPaper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdf
Steven McGee
 
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
Taqyea
 
Presentation Mehdi Monitorama 2022 Cancer and Monitoring
Presentation Mehdi Monitorama 2022 Cancer and MonitoringPresentation Mehdi Monitorama 2022 Cancer and Monitoring
Presentation Mehdi Monitorama 2022 Cancer and Monitoring
mdaoudi
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
IoT PPT introduction to internet of things
IoT PPT introduction to internet of thingsIoT PPT introduction to internet of things
IoT PPT introduction to internet of things
VaishnaviPatil3995
 
AG-FIRMA Ai Agent for Agriculture | RAG ..
AG-FIRMA Ai Agent for Agriculture  | RAG ..AG-FIRMA Ai Agent for Agriculture  | RAG ..
AG-FIRMA Ai Agent for Agriculture | RAG ..
Anass Nabil
 
Cloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptxCloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptx
marketing140789
 
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
emestica1
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
introduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.pptintroduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.ppt
SherifElGohary7
 
Breaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdfBreaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdf
Internet Bundle Now
 
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
Taqyea
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
werhkr1
 
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
Paper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdfPaper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdf
Steven McGee
 
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
Taqyea
 
Presentation Mehdi Monitorama 2022 Cancer and Monitoring
Presentation Mehdi Monitorama 2022 Cancer and MonitoringPresentation Mehdi Monitorama 2022 Cancer and Monitoring
Presentation Mehdi Monitorama 2022 Cancer and Monitoring
mdaoudi
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
IoT PPT introduction to internet of things
IoT PPT introduction to internet of thingsIoT PPT introduction to internet of things
IoT PPT introduction to internet of things
VaishnaviPatil3995
 
AG-FIRMA Ai Agent for Agriculture | RAG ..
AG-FIRMA Ai Agent for Agriculture  | RAG ..AG-FIRMA Ai Agent for Agriculture  | RAG ..
AG-FIRMA Ai Agent for Agriculture | RAG ..
Anass Nabil
 
Cloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptxCloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptx
marketing140789
 
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
emestica1
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 

Oracle postgre sql-mirgration-top-10-mistakes

  • 2. Who Am I? ● Jim Mlodgenski – jimm@openscg.com – @jim_mlodgenski ● Co-Chair – PGConf US ● Director – United States PostgreSQL (www.postgresql.us) ● Co-organizer of – Philly PUG (www.phlpug.org) – NYC PUG (www.nycpug.org) ● CTO, OpenSCG – www.openscg.com
  • 3. Why? ● Project deadline – Looming Oracle renewal ● Lack of education ● Attitude – Only see the world through an Oracle lens ● Using migration tools or other short cuts
  • 5. System Tuning ● When moving to PostgreSQL, many admins start with configuring values similar to the Oracle settings – My SGA was set to 16GB so shared_buffers is 16GB – My redo logs are 2GB so max_wal_size is 2GB
  • 6. System Tuning ● In Oracle, I get better performance with a 32k block size configure –with-blocksize=32 make make install
  • 8. Uppercase Folding ● In Oracle, all meta-data folds to uppercase SQL> DESC USERS Name Null? Type ---------- ------- ------------------------ FNAME VARCHAR2(100) MNAME VARCHAR2(100) LNAME VARCHAR2(100)
  • 9. Uppercase Folding ● In PostgreSQL, all meta-data folds to lowercase test=# d users Table "public.users" Column | Type | Nullable --------+------------------------+--------- fname | character varying(100) | mname | character varying(100) | lname | character varying(100) |
  • 10. Uppercase Folding ● Many migration tools carry the uppercase from Oracle over to PostgreSQL test=# d "USERS" Table "public.USERS" Column | Type | Nullable --------+------------------------+---------- FNAME | character varying(100) | MNAME | character varying(100) | LNAME | character varying(100) |
  • 11. Uppercase Folding ● Becomes very tedious needing to double quote everything test=# SELECT "FNAME", "MNAME", "LNAME" FROM "USERS"; FNAME | MNAME | LNAME ---------+--------+------------ George | | Washington John | | Adams Thomas | | Jefferson James | | Madison James | | Monroe Andrew | | Jackson Martin | | Van Buren John | | Tyler John | Quincy | Adams William | Henry | Harrison (10 rows)
  • 13. Table Spaces ● In Oracle, table spaces are critical for storing data ● Generally many table spaces are used for indexes and tables CREATE TABLESPACE ts_data1 LOGGING DATAFILE '/data/ts_data1.dbf' SIZE 32m AUTOEXTEND ON NEXT 32m MAXSIZE 2048m EXTENT MANAGEMENT local;
  • 14. Table Spaces ● In PostgreSQL, table spaces are just directory locations ● Provide no real benefit unless the database spans multiple mount points CREATE TABLESPACE ts_data1 LOCATION '/data/ts_data1';
  • 15. Table Spaces ● Additional table spaces makes operations more cumbersome like – Backup and restore – Replication setup – Major version upgrades
  • 17. Dual Table SQL> SELECT SYSDATE FROM DUAL; SYSDATE --------- 09-MAY-17
  • 18. Dual Table ● In PostgreSQL, the FROM clause is optional and is unnecessary ● Don’t mock a DUAL table test=# SELECT CURRENT_DATE; current_date -------------- 2017-05-09 (1 row)
  • 20. Exceptions ● Many Oracle procedures use exceptions as part of standard practice – Application developers are comfortable catching exceptions ● Some applications have exception handling in every procedure and function ● Most migration tools simply translate the code to pl/pgsql
  • 21. Exceptions CREATE FUNCTION get_first_name(p_lname varchar2) RETURN varchar2 IS l_fname varchar2(100); BEGIN SELECT fname INTO l_fname FROM users WHERE lname = p_lname; RETURN l_fname; EXCEPTION WHEN no_data_found THEN l_fname := null; RETURN l_fname; END get_first_name;
  • 22. Exceptions CREATE FUNCTION get_first_name(p_lname varchar) RETURNS varchar AS $$ DECLARE l_fname varchar; BEGIN SELECT fname INTO l_fname FROM users WHERE lname = p_lname; RETURN l_fname; EXCEPTION WHEN no_data_found THEN l_fname := null; RETURN l_fname; END $$ LANGUAGE plpgsql;
  • 23. Exceptions ● PostgreSQL uses sub transactions to handle exceptions CREATE OR REPLACE FUNCTION get_first_name(p_lname varchar) RETURNS varchar AS $$ DECLARE l_fname varchar := null; BEGIN SELECT fname INTO l_fname FROM users WHERE lname = p_lname; RETURN l_fname; END $$ LANGUAGE plpgsql;
  • 25. Fine Tuning Queries ● “I added a hint to use an index but PostgreSQL does not use it” – PostgreSQL does not have hints ● It treats Oracle hints as comments ● PostgreSQL’s optimizer is different than Oracle so queries are tuned differently
  • 26. Fine Tuning Queries ● B-tree ● Hash ● GIN ● GiST ● SP-GiST ● BRIN ● “I didn’t index my column in Oracle, why would I in PostgreSQL?” ● PostgreSQL has more and different types of indexes than Oracle
  • 27. Fine Tuning Queries ● PostgreSQL can even use indexes on LIKE queries CREATE INDEX idx_users_lname ON users USING gin (lname gin_trgm_ops); EXPLAIN SELECT * FROM users WHERE lname LIKE '%ing%'; QUERY PLAN ----------------------------------------------------- Bitmap Heap Scan on users (cost=8.00..12.02 rows=1 width=654) Recheck Cond: ((lname)::text ~~ '%ing%'::text) -> Bitmap Index Scan on idx_users_lname (cost=0.00..8.00 rows=1 width=0) Index Cond: ((lname)::text ~~ '%ing%'::text)
  • 29. Not Using Native Features ● PostgreSQL is more feature rich for developers than Oracle – Stored Procedure Languages – Foreign Data Wrappers – Data Types – Spatial
  • 30. Not Using Native Features CREATE OR REPLACE FUNCTION has_valid_keys(doc json) RETURNS boolean AS $$ if (!doc.hasOwnProperty('fname')) return false; if (!doc.hasOwnProperty('lname')) return false; return true; $$ LANGUAGE plv8 IMMUTABLE; ALTER TABLE user_collection ADD CONSTRAINT collection_key_chk CHECK (has_valid_keys(doc::json));
  • 31. Not Using Native Features CREATE TABLE login_history ( user_id bigint, host inet, login_ts timestamptz ); SELECT user_id, count(*) FROM login_history WHERE host << '17.0.0.0/8'::inet AND login_ts > now() - '7 days'::interval GROUP BY 1;
  • 33. Synonyms “PostgreSQL doesn’t have synonyms so I can’t migrate my application” CREATE PUBLIC SYNONYM emp FOR SCOTT.emp; ● Synonyms are used to not fully qualify cross schema objects ● Mostly a convenience feature
  • 34. Synonyms ● In PostgreSQL, search_path can accomplish many of the same things and is less tedious to setup test=# show search_path; search_path ----------------- "$user", public (1 row)
  • 35. Synonyms CREATE FUNCTION user1.get_int() RETURNS int AS $$ SELECT 1; $$ LANGUAGE sql; CREATE FUNCTION user2.get_int() RETURNS int AS $$ SELECT 2; $$ LANGUAGE sql; CREATE FUNCTION public.get_number() RETURNS float8 AS $$ SELECT 3.14::float8; $$ LANGUAGE sql;
  • 36. Synonyms test=# SELECT get_int(); 2017-05-08 17:38:50.367 EDT [28855] ERROR: function get_int() does not exist at character 8 2017-05-08 17:38:50.367 EDT [28855] HINT: No function matches the given name and argument types. You might need to add explicit type casts. 2017-05-08 17:38:50.367 EDT [28855] STATEMENT: SELECT get_int(); ERROR: function get_int() does not exist LINE 1: SELECT get_int(); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
  • 37. Synonyms test=# SET search_path = user1, user2, public; SET test=# SELECT get_int(); get_int --------- 1 (1 row)
  • 38. Synonyms test=# SET search_path = user2, user1, public; SET test=# SELECT get_int(); get_int --------- 2 (1 row)
  • 41. Nulls ● PostgreSQL and Oracle handle nulls a bit differently – Need to account for them appropriately – Most often seen with string concatenation
  • 42. Nulls CREATE TABLE users ( fname VARCHAR2(100), mname VARCHAR2(100), lname VARCHAR2(100) ); SELECT fname || ' ' || mname || ' ' || lname FROM users;
  • 43. Nulls SQL> SELECT fname || ' ' || mname || ' ' || lname FROM users; FNAME||''||MNAME||''||LNAME --------------------------------------------------------------- George Washington John Adams Thomas Jefferson James Madison James Monroe Andrew Jackson Martin Van Buren John Tyler John Quincy Adams William Henry Harrison 10 rows selected.
  • 44. Nulls test=# SELECT fname || ' ' || mname || ' ' || lname FROM users; ?column? ------------------------ John Quincy Adams William Henry Harrison (10 rows)
  • 45. Nulls test=# SELECT COALESCE(fname, '') || ' ' || COALESCE(mname, '') || ' ' || COALESCE(lname, '') FROM users; ?column? ------------------------ George Washington John Adams Thomas Jefferson James Madison James Monroe Andrew Jackson Martin Van Buren John Tyler John Quincy Adams William Henry Harrison (10 rows)
  • 47. Data Types ● Oracle has a few main data types that are typically used – VARCHAR2 – DATE – NUMBER ● And a couple Large Object types – CLOB – BLOB
  • 48. Data Types ● PostgreSQL comes with 64 base types and can be extended for more abstime aclitem bit bool box bpchar bytea char cid cidr circle date float4 float8 gtsvector inet int2 int2vector int4 int8 interval json jsonb line lseg macaddr money name numeric oid oidvector path pg_lsn pg_node_tree point polygon refcursor regclass regconfig regdictionar y regnamespace regoper regoperator regproc regprocedure regrole regtype reltime smgr text tid time timestamp timestamptz timetz tinterval tsquery tsvector txid_snapshot uuid varbit varchar xid xml
  • 49. Data Types ● Don’t assume that the perceived equivalent in PostgreSQL behaves the same as Oracle – For example, managing CLOBS ● Length ● Substrings DBMS_LOB.GETLENGTH(x)
  • 50. Data Types ● In PostgreSQL, VARCHAR and TEXT are equivalent and behave the same CREATE TABLE max_varchar ( a varchar(4001) ); CREATE TABLE max_varchar ( a varchar(10485760) );
  • 51. Data Types CREATE TABLE max_varchar ( a varchar ); CREATE TABLE max_varchar ( a text );
  • 52. Data Types test=# INSERT INTO max_varchar SELECT repeat('x', 1073741800); INSERT 0 1 test=# SELECT length(a) from max_varchar ; length ------------ 1073741800 (1 row)
  • 54. Data Types ● Most migration tools translate an Oracle NUMBER to a PostgreSQL NUMERIC – A PostgreSQL NUMERIC can hold ● 131072 before the decimal point ● 16383 after the decimal point ● It is not the same are NUMBER SELECT to_number(n, n) FROM repeat('9', 131071) n;
  • 55. Summary ● System Tuning ● Case Folding ● Table Spaces ● Dual Table ● Exceptions ● Fine Tuning ● Native Features ● Synonyms ● Nulls ● Data Types
  • 58. Biggest Mistake ● Paying for a commercial database when it is not necessary – Listening to the FUD – Building new solutions on Oracle – Not learning PostgreSQL to leverage its great features and functionality
  翻译: