Note: I'm sorry, all screenshots were lost in the planet crash. But I managed to recover the text, hopefully it helps someone.
There can be many reasons for wanting to replicate your data from a MS SQL Server installation to your PostgreSQL installation. For example, as a step in migration or to be able to use PostgreSQL features for data analysis while not having to touch existing clients working with MSSQL. For me in this case, I wanted to use tsearch2 to search some fulltext data, because the fulltext indexer in SQL Server really isn't very good.
It turns out that SQL Server ships with replication functionality that can solve this problem with relatively little pain (depending on your schema of course), providing full transactional replication. It's master/slave only, and SQL Server will be the master, but it's still quite useful. Here are the steps to do this for a simple example database - should work for more complex database as well of course. It expects you to set up a user named sqlrepl in the PostgreSQL database, that the replication system will use to connect with. Make sure that this user has permissions to connect from the SQL Server machine in pg_hba.conf.
Make sure you have the PostgreSQL ODBC drivers installed on the SQL Server machine (I'm using version 8.01.02).
Create the example databases:
CREATE DATABASE origin go USE origin go CREATE TABLE tab1( id int identity not null primary key, t varchar(128) not null) INSERT INTO tab1 (t) VALUES ('Test 1') INSERT INTO tab1 (t) VALUES ('Test 2')
CREATE DATABASE slave OWNER sqlrepl; \connect slave CREATE TABLE tab1(id int not null primary key, t varchar(128) not null); ALTER TABLE tab1 OWNER TO sqlrepl;
Create a ODBC System Datasource on the SQL Server. This is done using the odbcad32 command. Make sure that you create a system datasource, and make sure you use the PostgreSQL ANSI driver (there are some problems with the UNICODE driver in the way SQL Server uses it)
Start SQL Server Enterprise Manager. Create a new linked server. This is done by right-clicking the Linked Servers node under Security and picking New Linked Server. Enter the name of the linked server (in all uppercase, in our case PGSLAVE), and pick the driver Microsoft OLE DB Provider for ODBC Drivers. Note that you should not pick the PostgreSQL ODBC driver here. Finally, enter the name of the ODBC datasource just created. Make sure the link works by clicking the Tables node and verify that you can see the tables of you database.
Configure the subscriber:
Click OK and close all dialogs
Create the publication:
If you have more advanced needs (which you often do), you can use most other features of SQL Server replication, such as row and column filtering.
I read this a couple of years ago and I still use it. Thanks for sharing this.