Migrate from SQL Server to PostgreSQL with Babelfish on FoundryDB
SQL Server licensing costs add up fast. Per-core pricing, Software Assurance renewals, and the looming end of extended support for older versions push teams to look for alternatives. PostgreSQL is the obvious destination, but rewriting thousands of stored procedures, converting T-SQL syntax, and updating every connection string is a project nobody wants to start.
Babelfish for PostgreSQL changes the equation. It adds a SQL Server wire-protocol layer (TDS) on top of PostgreSQL, so your existing applications connect to port 1433 and run T-SQL queries as before. No driver changes. No syntax rewrites. On FoundryDB, you get a fully managed Babelfish instance running on PostgreSQL 16 with backups, TLS, monitoring, and point-in-time recovery built in.
What Is Babelfish?
Babelfish is an open source extension for PostgreSQL, originally developed by AWS and now maintained by the community. It adds two capabilities to a standard PostgreSQL instance:
- TDS wire protocol on port 1433. SQL Server clients (SSMS, sqlcmd, ADO.NET, JDBC with the SQL Server driver) connect to this port and interact with the database using their native protocol.
- T-SQL language support. Stored procedures, functions, triggers, and queries written in Transact-SQL execute on the PostgreSQL engine without modification.
The underlying database is still PostgreSQL. You get full access to the PostgreSQL wire protocol on port 5432 in parallel, which means new services can use standard PostgreSQL drivers while legacy applications continue using TDS.
Dual-Protocol Access
Every Babelfish service on FoundryDB exposes two ports:
| Port | Protocol | Use Case |
|---|---|---|
1433 | TDS (SQL Server wire) | Existing .NET apps, SSMS, sqlcmd, JDBC SQL Server driver |
5432 | PostgreSQL | psql, pgAdmin, any PostgreSQL driver, new microservices |
Both ports point to the same data. A row inserted via TDS on port 1433 is immediately visible through a PostgreSQL query on port 5432. This dual-protocol model lets you migrate incrementally: keep the legacy app on TDS while building new features against the PostgreSQL interface.
Provisioning a Babelfish Service
A single API call provisions a production-ready Babelfish instance. FoundryDB handles the custom PostgreSQL 16 binary, the Babelfish extension initialization, TLS certificates, and firewall rules.
# Via CLI
fdb services create \
--name legacy-crm \
--engine mssql \
--version 4.8 \
--plan tier-4 \
--storage 100 \
--storage-tier maxiops \
--zone se-sto1
# Via API
curl -u admin:password -X POST \
https://api.foundrydb.com/managed-services \
-H "Content-Type: application/json" \
-d '{
"name": "legacy-crm",
"database_type": "mssql",
"version": "4.8",
"plan_name": "tier-4",
"storage_size_gb": 100,
"storage_tier": "maxiops",
"zone": "se-sto1"
}'
Under the hood, FoundryDB provisions a VM from a pre-built Packer template that includes the Babelfish-patched PostgreSQL 16 binary at /opt/babelfish/. The agent initializes the cluster with data checksums enabled, loads the babelfishpg_tds extension, creates the internal babelfish_db database, and calls sys.initialize_babelfish to set up the T-SQL catalog. The TDS listener starts on port 1433 automatically.
Provisioning typically completes in under five minutes.
Connecting Your Application
Once the service is running, retrieve your credentials and DNS hostname from the FoundryDB dashboard or API.
SQL Server Clients (TDS, Port 1433)
Use any SQL Server driver or tool. The connection looks identical to connecting to a real SQL Server instance.
# sqlcmd
sqlcmd -S your-service.db.foundrydb.com,1433 -U app_user -P 'your-password' \
-Q "SELECT @@VERSION"
# .NET / ADO.NET connection string
Server=your-service.db.foundrydb.com,1433;Database=defaultdb;User Id=app_user;Password=your-password;Encrypt=true;TrustServerCertificate=false;
# JDBC (SQL Server driver)
jdbc:sqlserver://your-service.db.foundrydb.com:1433;databaseName=defaultdb;user=app_user;password=your-password;encrypt=true;
PostgreSQL Clients (Port 5432)
PGPASSWORD='your-password' psql \
"host=your-service.db.foundrydb.com user=app_user dbname=defaultdb sslmode=verify-full"
SQL Server Management Studio (SSMS)
Open SSMS and enter:
- Server name:
your-service.db.foundrydb.com,1433 - Authentication: SQL Server Authentication
- Login: your database user
- Password: your database password
Check "Encrypt connection" in the connection properties. SSMS will connect over TDS and display the database objects as it would for any SQL Server instance.
What T-SQL Syntax Works
Babelfish 4.x supports a broad subset of T-SQL. For most CRUD applications, stored procedure logic, and reporting queries, the migration is straightforward.
Supported:
- DML:
SELECT,INSERT,UPDATE,DELETE,MERGE - Programmability:
CREATE PROCEDURE,CREATE FUNCTION,CREATE TRIGGER - SQL Server data types:
NVARCHAR,DATETIME,UNIQUEIDENTIFIER,BIT,MONEY, and others - System views: partial
sys.catalog emulation,INFORMATION_SCHEMAviews - Session settings:
SET NOCOUNT ON,SET ANSI_NULLS ON, and other commonSEToptions
Not supported:
| Feature | Status |
|---|---|
| SQL Server Agent jobs | Not supported |
| Linked servers | Not supported |
| CLR integration (.NET assemblies) | Not supported |
Full-text search (CONTAINS, FREETEXT) | Not supported |
OPENROWSET / OPENDATASOURCE | Not supported |
| Distributed transactions (MSDTC) | Not supported |
| Change Data Capture (CDC) | Not supported |
FOR XML clauses | Limited support |
Spatial data types (GEOMETRY, GEOGRAPHY) | Limited support |
If your application uses SQL Server Agent for scheduled jobs, replace those with cron, a task scheduler like Celery, or an external orchestrator. For full-text search, consider pairing your Babelfish service with an OpenSearch instance on FoundryDB.
For the complete compatibility matrix, refer to the official Babelfish documentation.
Migration Steps
1. Assess Your T-SQL Codebase
Use the Babelfish Compass tool to analyze your existing SQL Server database. It scans DDL scripts, stored procedures, and functions, then reports which constructs are supported, partially supported, or unsupported.
# Export your schema from SQL Server
sqlcmd -S old-server -U sa -Q "EXEC sp_generate_inserts" -o schema.sql
# Run Babelfish Compass against the DDL
java -jar BabelfishCompass.jar schema.sql
2. Provision and Load Schema
Create your FoundryDB Babelfish service, then connect via TDS and run your DDL scripts directly.
sqlcmd -S your-service.db.foundrydb.com,1433 -U app_user -P 'your-password' \
-i schema.sql
3. Migrate Data
For initial data loads, export from SQL Server using bcp or a custom ETL pipeline, then import via the same TDS connection. For smaller datasets, INSERT ... SELECT over linked tooling works fine.
4. Update Connection Strings
Point your application's SQL Server connection string to the FoundryDB hostname. Since the TDS protocol is the same, most applications require only a hostname change.
5. Validate with Both Protocols
Run your application test suite against the TDS endpoint. In parallel, connect via PostgreSQL on port 5432 to verify that the data is accessible from both protocols.
Backups and Recovery
Babelfish on FoundryDB uses pgBackRest for continuous WAL archiving. Point-in-time recovery (PITR) lets you restore to any second within the retention window.
curl -u admin:password -X POST \
https://api.foundrydb.com/managed-services/{id}/backups/restore \
-H "Content-Type: application/json" \
-d '{
"restore_point": "2026-04-05T14:30:00Z",
"target_service_name": "crm-restored"
}'
PostgreSQL Configuration
Since Babelfish runs on PostgreSQL 16, you tune it like any PostgreSQL instance. Adjust shared_buffers, max_connections, and other parameters through the FoundryDB configuration API.
curl -u admin:password -X PATCH \
https://api.foundrydb.com/managed-services/{id}/configuration \
-H "Content-Type: application/json" \
-d '{
"parameters": {
"max_connections": "200",
"shared_buffers": "2GB"
}
}'
Feature Matrix
FoundryDB's Babelfish service includes the same operational features as other engines on the platform:
| Feature | Supported |
|---|---|
| High Availability | Yes |
| Point-in-Time Recovery | Yes |
| TLS / SSL | Yes |
| Connection Pooling | Yes |
| Auto Failover | Yes |
| Monitoring and Alerts | Yes |
When Babelfish Is the Right Choice
Babelfish works best for applications where the T-SQL surface area is standard CRUD, reporting, and stored procedure logic. If your codebase avoids CLR integration, linked servers, and SQL Server Agent, the migration path is clean.
For applications that depend heavily on SQL Server-specific features, a full PostgreSQL rewrite may still be the better long-term investment. Babelfish gives you a middle ground: move off SQL Server licensing today, then gradually shift T-SQL code to native PostgreSQL syntax at your own pace.
Get Started
Provision a Babelfish service on FoundryDB and run your T-SQL workload against it. The dual-protocol access means you can test without touching your application code.