281 points · by jka · 6y ago · 71 comments
Orafce - An extension to bundle in Oracle functions -https://github.com/orafce/orafce
OracleFDW - A foreign data wrapper to query directly into Oracle from Postgres - https://github.com/laurenz/oracle_fdw
intro blog post: https://www.cybertec-postgresql.com/en/ora_migrator-moving-f...
Disclaimer: I work at CYBERTEC
In my case, the applications were relatively simple, but many of the queries used sequences explicitly, and the lack of a common syntax there was a slight pain point.
Or is it that Oracle runs on the fumes of legacy lock ins?
The answer is still: No, not really.
The price tag of Oracles database license is simply to high, compared to any benefit you might get. It's much better to try to redesign your application to work around any feature you might be missing in Postgresql, or MariaDB.
For many organisations, the licensing costs of an Oracle or Microsoft RDBMS are trivial compared to the costs of the projects they're supporting, and it's easy to find where the value might be. Everything that's difficult about running an RDBMS at scale (clustering, failover/replication, statistics collection, plan management, monitoring, online index rebuilding, table partitioning...) is easier with the features and management tools those companies provide. Add actually decent support to that, and you've got a very clear value proposition.
A Postgres instance will require a lot more hands on management, and a deeper understanding of how the database engine works. At smaller scale, these factors are much less likely to cause problems, and many organisations are unlikely to ever reach actually large scales (many TB instance, running hundreds or thousands of transactions per second). But if you want to start scaling an RDBMS application up, you're going to have to confront those costs in one way or another. After a point, licensing expensive features can start to look better than deploying more specialised labor.
I remember some colleagues rolling out a project to thousands of postal service branch offices. Oracle was very happy to provide 24/7 emergency DBA services in case anything went wrong with any of the instances (local to the branch offices).
Just an additional guarantee of "if one of them behaves weirdly, we will be right on it" (as a service).
Unless you get a Postgres-based consultancy to do the same for you (and ofc they're not first party), that support is just unbeatable (in terms of what you're selling to your customer, the post offices).
But it also seems to be uncontroversial that no good could plausibly come out of attempting to sue Oracle.
You have to live with them anyway?
You obviously don't try to sue them, their company is 90% legal staff [0]. (Sorry I can't find the original source)
[0] https://am21.mediaite.com/tms/cnt/uploads/2011/06/org-charts...
The support is pretty good although it's usually only needed because the products themselves are filled with obscure bugs, edge cases and combinations of features which don't work well together.
Mainframe is the CA of CAP.
Personally I chose SQLite sharded on S3 and dynamodb.
Why would they use AWS? They have their own cloud: https://cloud.ibm.com/catalog#services
This sounds interesting, would you mind sharing details?
But you can do a lot with Oracle XE and Apex (which are free). and you can link them up with Postgresql through HA or FDW.
Also some customers feel more safe when they know they've paid $10 000 or probably more for an oracle license.
Source: I once suggested to my boss that maybe we could save around $10 000 pr customer site and also save ourselves tons of work by using Postgres instead.
Firebird db is the only other database I know of that has package functionality. For a portable database, that is pretty impressive...
A TIMESTAMP WITH TIME ZONE data type that makes sense and is usable.
I am monthly approached by Oracle the opposite way tho, to migrate services I architect from Postgres to Oracle db. Never succumbed to this date (I would rather switch to farming TBH).
With this tool, I can go offensive :) Somebody also mentioned in the comments orafce extension - even more awesome, I can tell them that I already use Oracle db , its just inside Postgres which is technical detail :D.
Beware of John Deere though, I heard they're the Oracle of farming ;)
1. Ora2Pg will create a file that has all of your tables, columns, indices, keys etc. in Postgres format. Unfortunately it is great as a first pass, but we found that we had to do a lot of manually tweaking to get it into a really usable state. For instance, it does it's best guess at picking the right data type, but we didn't agree with all of its choices so we had to look through each one and decide which needed changing. Also, the way primary keys are setup on Oracle and Postgres is very different Ora2Pg takes a literal translation of translating how Oracle primary keys are set up instead of using the Postgres way - so we had to fix all of these.
2. It can't really convert functions and triggers. All of these had to be rewritten by hand.
3. It takes a ton of tweaking and experimentation to get Ora2Pg to transfer the data in a decent amount of time. Our first try took nearly 24 hears. We eventually tweaked it down to about an hour.
4. You will still need to rewrite all of your SQL queries into Postgres format. This is the part that took the most time since we have about 5,000 queries and each one had to be checked.
5. The biggest pain is that we couldn't stop development while the database migration was going on. So every time changes were made to the Oracle database, we had to manually make those same changes to the Postgres DDL files.
Sigh. I am so glad that project is behind me. I don't ever want to be involved in something like that again. It was totally worth it (Postgres is a dream to work with compared to Oracle), but the process was a nightmare.
Some notes about converting queries from Oracle to Postgres:
"foo IN (a, b, c)" can often be better done as "foo = ANY(ARRAY[a, b, c])" in Postgres - not least because you can shift to passing in an array of variable size without having to construct a special statement for each.
for sorting on the result of a function, consider using a subselect. "SELECT foo FROM (select fun(z) as foo from blaz) tmp order by 1".
replace nvl with coalesce
replace rownum <= 1 with LIMIT 1
replace listagg with string_agg
replace recursive hierarchy (start with/connect by/prior) with recursive
replace minus with except
replace SYSDATE with CURRENT_TIMESTAMP
replace trunc(sysdate) with CURRENT_DATE
replace trunc(datelastupdated) with DATE(datelastupduted) or datelastupdated::date
replace artificial date sentinels/fenceposts like to_date(’01 Jan 1900’) with '-infinity'::date
remove dual table references
replace decode with case statements
replace unique with distinct
replace to_number with ::integer
replace regexp_like() with ~ or ~*
replace mod with % operator
replace merge into with INSERT ... ON CONFLICT… DO UPDATE/NOTHING
change the default of any table using sys_guid() as a default to gen_random_uuid()
oracle pivot and unpivot do not work in postgres - use unnest
ORDER BY NLSSORT(english, 'NLS_SORT=generic_m') becomes ORDER BY gin(insensitive_query(english) gin_trgm_ops)
replace UNISTR( with U&’
Oracle: uses IS NULL to check for empty string; postgres uses empty string and null are different
If a varchar/text column has a unique index a check needs to be made to make sure empty strings are changed to nulls before adding or updating the column.
PostgreSQL requires a sub-SELECT surrounded by parentheses, and an alias must be provided for it. - SELECT * FROM ( ) A
any functions in the order by clause must be moved to the select statement (e.g. order by lower(column_name))
Any sort of numeric/integer/bigint/etc. inside of a IN statement must not be a string (including 'null' - don't bother trying to use null="", it won't work).
Concatenating a NULL with a NOT NULL will result in a NULL.
Pay attention to any left joins. If a column from a left join is used in a where or select clause it might be null.
For sequences, instead of sequence_name.nextval use nextval('sequence_name')
When using Oracle and the values are not static/a literal you should be using
foo = ANY(SELECT column_value FROM TABLE(?))
with an array as a bind parameter. This saves on hard parses, increases the effectiveness of cached session cursors and any client side prepared statement cache.I don't know anything about Oracle, and I realize the semantics of "null" are subtle, but this seems like a peculiar design decision that conflates two different things. With Oracle, how would one represent the state of a text field we don't know anything about? An empty string implies "we know the value and it is <nothing>" versus "it could be anything; we just don't know".
[edit: reworded for clarity]
By far and away, the way NULLs are handled in Oracle is the biggest problem with moving to a different database.
[1]: https://www.getdbt.com/product/
I’ve been looking at writing a script that parses the daily files for the California State Senate and State Assembly to create an API along with exposing a web app that offers a UI to view and search changes so folks interested can look around.
https://www.senate.ca.gov/dailyfile
https://clerk.assembly.ca.gov/daily-file
They give raw sql files in there but also a bunch of oracle that I have had no way to read.
This tool might help me see if there are differences in the file types.