PostgreSQL for Oracle Developers and DBA's

37
Command Prompt, Inc. http://www.commandprompt.com/ @cmdpromptinc Postgres for Oracle people

Transcript of PostgreSQL for Oracle Developers and DBA's

Page 1: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Postgres for Oracle people

Page 2: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Professional Services

For professional services or support contracts for all of your Oracle to PostgreSQL or Open Source needs, please contact CMD at:

● +1.503.667.4564● [email protected]● https://www.commandprompt.com/

Page 3: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Who Am I

● @jdatcmd/@linuxhiker

[email protected]

● Lead Architect – Command Prompt, Inc.

● Director & Founder – PgUS (501c3)

Page 4: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Why PostgreSQL

● Licensing● Community● Business● Tech!

Page 5: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Licensing

● BSD licensed● Can I?

Page 6: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Can I?

● Fork it?: Yes● Close it?: Yes● Modify it?: Yes● Not share it?: Yes● Throw it away?: Yes● Sue you?: Nein!

Page 7: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Community

● Large International Community:– Postgresql.org

● Postgresql.us● Postgresql.eu

– Germany, Nordic, France, Italy...● Postgresql.jp● Postgres.cn

Page 8: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Business

● Costs● Support

Page 9: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Costs

● PostgreSQL is 100% free.– Zero cost to download

– Zero cost to install

– Zero cost to support (assuming expertise)

Page 10: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Established companies(Support)

● Command Prompt, Inc (oldest, yes that’s us)● Crunchy● Credativ● OmniTI● OpenSCG● 2ndQuadrant

(list goes on and on)

Page 11: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

EnterpriseDB?

● They specialize in a closed source fork not Open Source PostgreSQL

Page 12: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Tech

● The basics● Features● Quirks

Page 13: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

The basics

● ACID Compliant

● Rich datatypes

– Standards such as varchar(), integer, numeric etc..

– XML, JSON/B, Money, Hstore...

● Rich builtin functions

– to_char(),to_date(),overlaps(),enum_first(),xpath(),greatest(),in(),any(),some(),trim,overlay()...

● Constraints

– CHECK, PRIMARY KEY, NOT NULL…

● Referential Integrity

– Foreign Keys (Deferrable, Initially Deferred)

● Partitioning

● SCHEMA (namespaces)

Page 14: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Features

● Solid SQL implementation● Mature code base● “Enterprise”● Cool stuff’● Of note

Page 15: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Solid SQL Implementation

No current version of any database management system claims full conformance to Core SQL:2011.

PostgreSQL supports most of the major features of SQL:2011. Out of 179 mandatory features required for full Core conformance, PostgreSQL conforms to at least 160. In addition, there is a long list of supported optional features.

Page 16: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

ISO/IEC SQL Implementation

● ISO/IEC 9075-1 (SQL/Framework)

● ISO/IEC 9075-2 (SQL/Foundation)

● ISO/IEC 9075-9 (SQL/MED)

– FDW, DBI-LINK

● ISO/IEC 9075-11 (SQL/Schemata)

● ISO/IEC 9075-14 (SQL/XML)

– Native XML handling and functions● ISO/IEC 9075-13 (SQL/JRT(Java))

– PL/JAVA

Page 17: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Mature code base

PostgreSQL started as Ingres at the University of California, Berkeley in the 1970s.

Current iterations have been in continual development since 1997.

Page 18: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Enterprise features

● It’s Free! No licensing audits.● FDW● Backup and recovery● Replication● Table spaces● Transactional DDL● UDF

– We don’t have packages

Page 19: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

It’s free. No licensing audits

● Oracle has spawned an entire industry to defend against the possibility of an audit.

● PostgreSQL has spawned an entire industry letting businesses and developers use a database.

Page 20: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

FDW

Foreign Data Wrappers

Connect to external data sources including Oracle! (CREATE DATABASE LINK)

Page 21: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Backups and Recovery

● Online logical backups (pg_dump/pg_dumpall)● Online binary backups (pg_basebackup,

pgBackrest, (tar,cpio,cp,rsync))● Point In Time Recovery (PITR)

Page 22: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Replication

● Logical Replication (pgLogical, Slony, Londiste)● Binary Replication (Warm,Cold and Hot

Standby). SYNC AND ASYNC● Load balancing

– Pgpool-II->Master->(n)Slaves

Page 23: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Table Spaces

Postmaster

Warehouse TBLSpace

Transactional TBLSpace

Indexes

Page 24: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Transactional DDL

BEGIN;

CREATE TABLE foo (

id BIGSERIAL PRIMARY KEY,

fname TEXT NOT NULL

CHECK(fname ~ ‘[^[:alnum:]_]’)

);

COMMIT/ROLLBACK;

BEGIN;

ALTER TABLE foo ADD COLUMN lname TEXT NOT NULL;

SELECT test_foo_column_laname();

COMMIT/ROLLBACK;

Page 25: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

UDF

● Can be written in a number of languages– C

– SQL

– PL/PgSQL (similar to PL/SQL)

– Python

– Ruby

– Perl

– V8 (JavaScript)

– Java

– Lots more

Page 26: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Cool stuff

● Savepoints● Two Phase Commit

– XA

● SELinux integration● Column, Row permissions (versus just relation)● Extensions● GIS/Postgis

Page 27: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Savepoints

● Similar to Oracle:

BEGIN;

INSERT INTO table1 VALUES (1);

SAVEPOINT my_savepoint;

INSERT INTO table1 VALUES (2);

ROLLBACK TO SAVEPOINT my_savepoint;

INSERT INTO table1 VALUES (3);

COMMIT;

Page 28: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Two Phase Commit

● Intended use by external transaction managers– XA implementation via JDBC driver

● Can be used via SQL● Review: max_prepared_transactions

configuration parameter● Always clean up, will interfere with maintenance

Page 29: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

selinux

● For more information visit:https://wiki.postgresql.org/wiki/SEPostgreSQL_SELinux_Overview

Page 30: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Column/Row Permissions

● Column level privs are set using standard GRANT/REVOKE

● ROW level privs are set via a policy method:https://www.postgresql.org/docs/9.5/static/ddl-rowsecurity.html

Page 31: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Extensions

● Column Database (Citus)● Auditing (PgAudit)● Case insensitive index search (Citext)● And more (pgxn.org)

Page 32: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Of note● Use TEXT for CLOB, BYTEA (or lo) for BLOB● NULL is different:

postgres=# create table bar(a text);CREATE TABLEpostgres=# insert into bar values('');postgres=# select * from bar where a IS NULL; a ---(0 rows)postgres=# insert into bar values(NULL);postgres=# select * from bar where a IS NULL; a --- (1 row)

● PostgreSQL has a boolean data type.

Page 33: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

GIS/PostGIS

● Full Geometric support including– Datatypes

– Functions

● Extended support through PostGIS (external project).

Page 34: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Of note (2)

● No connect by– Use “WITH RECURSIVE”

● PostgreSQL is much more reliant on the host operating system than Oracle. Make sure you are running an LTS, UNIX (Solaris) or FreeBSD.

Page 35: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Tools for easing migration

● Ora2pg– Complete migration toolkit

● Orafce– Implements compatibility layers that are 10g

compatible including but not limited to:● Oracle date functions● Oracle.date data type● Oracle data operators etc...

Page 36: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

What we don’t have

● No RAC● No Packages● No Flashback (on main system, can be

achieved via PITR/Cold standby)

Page 37: PostgreSQL for Oracle Developers and DBA's

Command Prompt, Inc.http://www.commandprompt.com/

@cmdpromptinc

Questions?

● Business● Community● Technical