Back to blog

// OSSeva Blog

Migration

PostgreSQL vs Oracle: SQL Syntax Differences, Performance and Licensing Compared

Randall McClure10 min read

The short answer

PostgreSQL is a credible replacement for Oracle Database in most applications you control, and Oracle remains the stronger choice for a few specific needs. PostgreSQL is free under a permissive licence, runs anywhere, and covers the core of what OLTP applications use: transactions, stored procedures, partitioning, replication, JSON and a large extension ecosystem. Oracle charges licence and support fees and sells options such as Real Application Clusters, Partitioning and Active Data Guard separately, but it offers features PostgreSQL has no direct equivalent for, above all RAC's shared-storage clustering, and it is the only certified database for some packaged software. The move between them is a programme of months, mostly spent on PL/SQL, data types and testing.

PostgreSQL vs Oracle at a glance

PostgreSQLOracle Database
LicencePostgreSQL License, permissive and freeCommercial; Oracle AI Database 26ai Free limited to 2 CPUs, 2 GB of RAM and 12 GB of user data
Support modelCommunity releases for 5 years per major; support from any vendor or in-houseOracle Premier, Extended and Sustaining Support, or third-party support
Procedural languagePL/pgSQL, plus others such as PL/PythonPL/SQL, with packages
ClusteringOne writable primary with streaming replicas; read-only hot standbysRAC: several servers read and write one database (extra-cost option on Enterprise Edition)
PartitioningDeclarative range, list and hash, built inOracle Partitioning, an extra-cost option on Enterprise Edition
Empty stringsAn empty string is not NULLA zero-length string is treated as NULL
DATE typeDate only; timestamp holds the timeDATE holds date and time to the second

Licensing and cost structure

PostgreSQL has no licence fee at any scale. You pay for hardware or cloud capacity and for support, whether from a vendor or your own team. Oracle Database is licensed commercially. On Enterprise Edition, RAC, Partitioning, Advanced Compression and Active Data Guard are extra-cost options, and the Diagnostics and Tuning Packs are extra-cost packs, according to Oracle's own licensing information manual. That structure is often what starts the comparison: a feature an application already uses can carry its own licence line. If an audit is what prompted the question, read your options after an Oracle licence audit. Oracle also offers a free edition, Oracle AI Database 26ai Free, capped at two CPUs, 2 GB of RAM and 12 GB of user data, which suits development rather than production.

PostgreSQL vs Oracle SQL syntax differences

Both follow the SQL standard closely enough that simple queries port unchanged. The differences cluster in a few places:

AreaOraclePostgreSQL
String typeVARCHAR2(100)varchar(100) or text
NumbersNUMBER(10,2), NUMBERnumeric(10,2), or integer / bigint where the values are whole
Date with timeDATEtimestamp (PostgreSQL date has no time)
Empty string'' is NULL'' is a value; WHERE col IS NULL no longer matches it
Null replacementNVL(a, b)COALESCE(a, b)
Conditional valueDECODE(x, 1, 'a', 'b')CASE x WHEN 1 THEN 'a' ELSE 'b' END
Limiting rowsROWNUM <= 10 or FETCH FIRST 10 ROWS ONLYLIMIT 10 or FETCH FIRST 10 ROWS ONLY
HierarchiesCONNECT BY PRIORWITH RECURSIVE
Expressions without a tableSELECT 1 FROM DUAL (optional from release 23)SELECT 1
Next sequence valuemy_seq.NEXTVALnextval('my_seq'), or an identity column

The empty-string row causes the most silent bugs, because nothing fails. Oracle's own SQL reference says the database treats a zero-length character value as null and advises against relying on it. Code that writes '' and then tests IS NULL behaves differently after the move, and unique constraints may start rejecting rows that Oracle accepted as NULLs. The DATE row is the second trap: mapping Oracle DATE to PostgreSQL date drops the time of day.

PL/SQL vs PL/pgSQL

The PostgreSQL manual has a chapter on porting from Oracle PL/SQL. The differences that cost the most time:

  • No packages. PostgreSQL has no package construct and no package-level variables. The manual suggests schemas to group functions and temporary tables for per-session state.
  • Function syntax. The body is a string literal, usually written with dollar quoting; RETURN in the header becomes RETURNS, IS becomes AS, and a LANGUAGE plpgsql clause is required.
  • Exceptions. A PL/pgSQL block with an EXCEPTION clause rolls back everything since the block's BEGIN when an error is caught, which equals an Oracle savepoint and rollback. Exception names differ, for example dup_val_on_index becomes unique_violation, and raise_application_error becomes RAISE EXCEPTION.
  • Smaller traps. FOR ... IN REVERSE loops take their bounds in the opposite order, query loop variables must be declared, ambiguous names raise an error by default instead of resolving to the column, and there is no built-in instr.

A common approach is to let Ora2Pg, an open source migration tool, convert the bulk and have engineers rewrite what it cannot. Our Oracle to PostgreSQL migration challenges post covers the hard cases, and the migration guide covers the sequence.

PostgreSQL vs Oracle performance

No honest comparison puts a single number on this. Performance depends on the schema, the queries, the hardware, the configuration and how well each system is tuned, and a workload that was tuned for years on Oracle will not show its best on PostgreSQL until it has been tuned there too. What can be said from each product's own documentation:

  • Scaling writes. Oracle RAC lets several servers read and write the same database, which Oracle describes as transparently scaling both reads and writes. PostgreSQL has one writable primary per cluster; its standbys serve read-only queries. Write scaling beyond one server means sharding, for example with the Citus extension, or splitting the workload.
  • Large queries. PostgreSQL can run one query across several CPUs with parallel query, and partition pruning works with its built-in declarative partitioning. Oracle offers parallel execution and partitioning too, with Partitioning licensed as an option on Enterprise Edition.
  • Diagnostics. Oracle's Diagnostics and Tuning Packs are mature, paid tools. PostgreSQL relies on EXPLAIN, statistics views and extensions such as pg_stat_statements, which do the job but ask more of the DBA.

The practical approach is to migrate a representative slice, replay real queries against both, and tune before comparing. Treat any general claim in either direction as a hypothesis for that test. Applications that rely on RAC for write throughput need a redesign, not a port.

Other differences that matter in practice

  • Transactions and DDL. PostgreSQL can roll back most DDL inside a transaction. Oracle commits DDL implicitly, so migration scripts written for Oracle often assume each statement stands alone.
  • Identifier case. Oracle folds unquoted names to upper case, the SQL standard behaviour; PostgreSQL folds them to lower case. Applications that quote upper-case names need consistent handling.
  • Extensions. PostgreSQL adds capabilities through extensions: PostGIS for geospatial, pgvector for vectors, Citus for distribution. Oracle builds most features into the product and its options.
  • Where it runs. PostgreSQL runs on Linux, Windows, containers and every major cloud, and adding servers adds no licence fee. With Oracle, each new server or option is a licensing question as well as a technical one.

When Oracle is the better choice

  • Packaged applications whose vendor certifies only Oracle Database.
  • Systems that depend on RAC for write scaling or on Oracle-specific features with no PostgreSQL equivalent.
  • Estates where the migration effort, retesting and retraining outweigh the licence and support savings over the planning horizon.

For those, the choice is between Oracle's own support calendar and a third-party Oracle support provider. Our posts on Oracle 19c end of life and the Oracle Database comparison cover those routes.

When PostgreSQL is the better choice

  • Applications you own, where you can change SQL and stored code.
  • Licence or audit pressure, or Oracle options adding cost for features an application barely uses.
  • A plan to standardise on one open source engine across Oracle, SQL Server and MySQL estates.

Oracle Database alternatives compares PostgreSQL with the other targets, and Oracle to PostgreSQL migration cost factors sets out what drives the effort.

Where OSSeva fits

OSSeva does not support or patch Oracle Database. If you stay on Oracle, Oracle or a third-party Oracle support provider is the right partner. If you decide to leave, OSSeva's Oracle to PostgreSQL offer runs the assessment, ora2pg conversion, data migration, parallel run and cutover, then supports the PostgreSQL cluster from day one on your own servers, VMs, Kubernetes or cloud account. OSSeva Assure includes Oracle-to-PostgreSQL migration design; OSSeva Operate adds 24/7 replication and failover monitoring with a 15-minute P1 response. Because OSSeva for PostgreSQL also patches versions after community end of life, the version you land on stays covered if the programme runs long. PostgreSQL then sits under one contract with MySQL, MariaDB, Redis and Kafka, priced per cluster. Book a discovery call for a quote.

Frequently asked questions

What are the PostgreSQL vs Oracle SQL syntax differences?

The main ones are data types (VARCHAR2, NUMBER and DATE map to varchar or text, numeric or integer, and timestamp), empty strings being NULL in Oracle but not PostgreSQL, NVL and DECODE against COALESCE and CASE, ROWNUM against LIMIT, CONNECT BY against WITH RECURSIVE, DUAL, sequence syntax, and PL/SQL packages, which PostgreSQL does not have.

PostgreSQL vs Oracle performance: which is faster?

Neither in general; it depends on the workload, the schema and the tuning on each side. Oracle RAC can scale writes across servers, which PostgreSQL cannot do without sharding. Migrate a representative slice and test with your own queries after tuning both.

What are the main differences between PostgreSQL and Oracle?

Licensing (free and permissive against commercial with paid options), clustering (single writable primary against RAC), procedural code (PL/pgSQL without packages against PL/SQL), data type and NULL semantics, and the support model.

Can PostgreSQL replace Oracle?

For most applications you control, yes, after a migration that converts schema, PL/SQL and queries and tests them. Packaged software certified only on Oracle, and systems built on RAC write scaling, are the usual exceptions.

Does PostgreSQL have packages like Oracle?

No. The PostgreSQL manual recommends schemas to group functions and temporary tables for session state that Oracle would keep in package variables.

Is there a free version of Oracle Database?

Yes. Oracle AI Database 26ai Free can use up to two CPUs, 2 GB of RAM and 12 GB of user data. It suits development and learning; production workloads usually exceed those limits.

Tags

PostgreSQLOracleComparisonMigrationPL/SQL

Ready to get your open source under control?

Talk to an OSSeva engineer about CVE coverage, compliance, and migration support for your stack.