In 1987, Sybase Adaptive Server Enterprise (Sybase ASE, now SAP ASE) was released to the public, and was adopted by a fair number of users over the years. However, nothing lasts forever; SAP has announced the end of mainstream maintenance (EoMM) by 2025. Sybase ASE is dead. Those still using Sybase face the need to migrate to a new platform.
Table of Contents
PostgreSQL is a logical choice and offers Sybase clients freedom from license costs (as well as some other inconveniences imposed by the legacy product).
There hasn’t been much innovation in Sybase for at least a decade - the platform has long spread the aura of “legacy and decay”, in my judgement. In other words, even without SAP officially quitting support, it is a good idea to move to PostgreSQL and enjoy the benefits of a more vivid and innovative platform.
PostgreSQL is the best alternative to Sybase. The question is: How can I move from legacy Sybase ASE to PostgreSQL? There are various options:
tds_fdw
Let’s inspect these options in more detail.
tds_fdw
to migrateThe first option which comes to mind is to use tds_fdw
. As you might know, Sybase is the grandfather of Microsoft SQL Server. In 1993, Microsoft bought code from Sybase and used it as the foundation for what we now know as MS SQL Server. Why is that relevant? A lot of the legacy code from Sybase is still present in MS SQL Server. What is especially important is that both systems use the TDS (Tabular Data Stream) protocol between client and server. The advantage from a PostgreSQL point of view is that we can use the tds_fdw
(TDS Foreign Data Wrapper) to fetch data from Sybase as well as from MS SQL.
If you use MS SQL, you can actually use IMPORT FOREIGN SCHEMA
in PostgreSQL:
1 2 3 4 5 6 7 8 9 10 11 |
postgres=# h IMPORT Command: IMPORT FOREIGN SCHEMA Description: import table definitions from a foreign server Syntax: IMPORT FOREIGN SCHEMA remote_schema [ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ] FROM SERVER server_name INTO local_schema [ OPTIONS ( option 'value' [, ... ] ) ] URL: https://www.postgresql.org/docs/16/sql-importforeignschema.html |
The point is that this command relies on the existence of an information schema and the access to it, which means that in the case of Sybase, you might have to write up the foreign tables individually, rather than in a bulk operation.
Once you have configured your foreign tables, you can transfer the data rather easily:
[sql gutter="false"]
CREATE TABLE table_pg AS SELECT * FROM table_sybase;
This is a good and easy way to extract data and predict the data structure on the PostgreSQL side, but this will not give you indexes, constraints, etc. This information has to be extracted separately. In MS SQL Server, you'd use the information schema to extract this type of information.
Which leaves us with the trickiest part: Server side code and stored procedures. With tds_fdw
, there is no way to translate function code from Sybase’s Transact-SQL to PostgreSQL’s PL/pgSQL. That's critical, because the code has to be rewritten from scratch. From a PostgreSQL consultant’s point of view, there is no easy way to translate the code automatically. Transact-SQL is quite different from what we have on the PostgreSQL side.
One way to solve the problem is to do a “soft migration” in two steps. Babelfish is a modified version of PostgreSQL which exposes itself as a TDS data source (= MS SQL Server). The advantage is that you can basically stay on Sybase / MS SQL Server while just changing the underlying storage engine, which is especially useful if you manage tons of stored procedure code.
The beauty is that Babelfish can execute Sybase / MS SQL Server stored procedures in most cases - which makes the transition a lot easier. However, there is a catch. While Babelfish is really close to Sybase and MS SQL Server, it’s not Sybase and it’s not MS SQL. And yes, it is a lot slower: all the code has to be translated to PostgreSQL internals.
The main advantage is that you can get rid of Sybase fairly quickly while already beginning to work on a flavor of PostgreSQL which supports the same backup methods as PostgreSQL itself. Again: Keep in mind that Babelfish is NOT going to give you 1 million transactions per second, like official PostgreSQL does on modern hardware. However, it is a relatively quick and cheap way to move applications which do not require high performance. If you are interested in this process, we can assist you.
Once you are safely established on Babelfish, the transition to real PostgreSQL is a lot easier and faster to facilitate: much of the infrastructure you will need is already in place and working. Therefore, a two-stage process makes sense, if you have no opportunity to move all the procedure code in one go.
A second reason to go for Babelfish is to be able to change the database engine without touching the application code (in many cases). Let me say it directly: There are hardly any new and modern Sybase applications which were recently developed. Most of the Sybase-related apps are legacy solutions, often there is no access to the code anymore, and the companies which developed those applications are long gone. Babelfish might be a good option to run code which can be supported by a company like CYBERTEC, rather than running Sybase unsupported.
I did a lot of work with Sybase many years ago, so there are some things I want to point out which might cause you a headache.
Consider the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
begin tran select @@trancount /* @@trancount = 1 */ begin tran select @@trancount /* @@trancount = 2 */ begin tran select @@trancount /* @@trancount = 3 */ commit tran commit tran commit tran select @@trancount /* @@ trancount = 0 */ |
In Sybase, there is the notion of nested transactions. Unfortunately, this feature is not present in PostgreSQL and thus poses a challenge when moving stored procedure code. The problem is similar to porting autonomous transactions from Oracle to PostgreSQL. However, the Sybase side is even more tricky. In general, this type of code needs a lot of re-engineering and maybe a handful of changes on the application side too, in order to model correct, desired behavior on the new platform.
In the future, we plan to add support for MS SQL Server (and therefore also partly for Sybase) to our CYBERTEC Migrator. Most customers seem to want to get away from both platforms and move to PostgreSQL, so it might be worthwhile to develop this solution further, to cover the old TDS data sources.
+43 (0) 2622 93022-0
office@cybertec.at
You are currently viewing a placeholder content from Facebook. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More Information
From SAP note 1922006:
- ASE 16.0 - EoMM 2027-12-31 (SP04 PL05 is planned for release in Q3 2023)
- ASE 16.1 - EoMM 2030-12-31 (v16.1 is planned for release in Q4 2024)
It looks like Sybase ASE is not dead after all. But it doesn't mean that one should stay on it any further 🙂 Postgres is certainly a much better choice.
DO you recommend a high OLTP environment to move of Postgres instead of MS SQL Server? I am really new to Postgres - is it capable to handle heavy loads?
Yes, we would recommend PostgreSQL for OLTP workloads. But maybe you should also ask people who are less biased towards PostgreSQL than we are...