Skip to content
CH IMG

CH IMG

General Blog

Primary Menu
  • Finance
  • Health
  • Travel
  • Auto
  • Business
  • Law
  • Food
Watch
  • Home
  • Tech
  • SQL Server to PostgreSQL
  • Tech

SQL Server to PostgreSQL

Dom Danny July 7, 2023
SQL Server to PostgreSQL

The Microsoft SQL (MS SQL) database management system (DBMS) is popular due to its user-friendly interface and ease of understanding. However, it has two significant drawbacks: strict licensing policies and a high cost of ownership, particularly for managing large databases. To reduce ownership costs, it is recommended to consider open-source databases like PostgreSQL. PostgreSQL is a widely used open-source DBMS that combines relational and object-oriented database functionality, offering data integrity and high reliability.

To migrate a database from SQL Server to PostgreSQL, the following process is required.

  1. Export SQL Server table definitions:
  • For SQL 2008 and earlier versions, right-click on the database in Management Studio, select Tasks, and then Generate Scripts. Ensure that the “data” option is set to false (default).
  • For SQL 2012 and later versions, follow the same steps but on the “Set scripting options” tab, click on Advanced, and choose “data only” or “data and schema” for “Types of data to script” (in the General section).

Correct the resulting script before proceeding to the next step.

  1. Load the statements exported from SQL Server to PostgreSQL with the following pre-processing:
  • Remove SQL Server specific statements such as “SET ANSI_NULLS ON,” “SET QUOTED_IDENTIFIER ON,” and “SET ANSI_PADDING ON.”
  • In database object names all square brackets must be replaced by double quotes.
  • Replace the default SQL Server schema “dbo” with PostgreSQL’s “public.”
  • Remove all optional keywords not supported by the target DBMS, such as “WITH NOCHECK” and “CLUSTERED.”
  • Remove all references to file groups (e.g., “ON PRIMARY”) since this feature is not supported by PostgreSQL.
  • Auto-increment attribute of integer type “INT IDENTITY(…)” must be converted into PostgreSQL SERIAL data type.
  • Carefully map all SQL Server data types that are not supported by PostgreSQL. For example, DATETIME must be converted into TIMESTAMP, MONEY must be converted into NUMERIC(19,4).
  • Replace the SQL Server query terminator “GO” with the PostgreSQL terminator “;”.
  1. The next step is to process the data, which can be done using SQL Server Management Studio:
  • Right-click on the database, select Tasks, and then Export Data.
  • Go through the wizard and choose “Microsoft OLE DB Provider for SQL Server” as the data source and “Flat File Destination” as the destination.
  • Once the export is performed, the data will be in the destination file in comma-separated values (CSV) format.
  • If some tables contain binary data, a workaround is required. On the wizard page called “Specify Table Copy or Query,” select the option “Write a query to specify the data to transfer.” On the next page called “Provide a Source Query” design the following SELECT-query to process the binary data:

SELECT

nonbinaryfield1,

nonbinaryfield2,

cast( master.sys.fn_varbintohexstr(

cast( binaryfield as varbinary(max))) as varchar(max)

) as binary-field-name

FROM

mssql_table_name

  1. To load the resulting CSV file into the target PostgreSQL table, use the “COPY” command:

COPY <table name> FROM <path to CSV file> DELIMITER ‘,’ CSV.

If you encounter a “Permission denied” error message with the “COPY” command, try using the “\COPY” command instead.

It’s important to note that SQL Server to PostgreSQL database migration requires significant effort and can be a complex process. Manual conversions are costly, time-consuming, and prone to data loss or corruption. However, there are modern tools available that facilitate data conversion and migration between the two DBMS with just a few clicks.

One such tool is SQL Server to PostgreSQL converter provided by Intelligent Converters, a vendor specializing in database conversion and synchronization since 2001. This tool enables direct connection to both source and target databases, offering high-quality conversion without the need for ODBC drivers or middleware components. SQL Server to PostgreSQL converter can handle migration of the following database entries: schema, data, indexes, constraints, foreign keys and views. It also supports scripting, automation, and scheduling of conversions.

Continue Reading

Previous: Discovering the Unique Properties of THC-O and its Effects
Next: SEC Focus on Communication Compliance

Related Stories

Top LED Lights Supplier Philippines Revealed
  • Tech

Ready to Brighten Up? Top LED Lights Supplier Philippines Revealed!

David Curry June 1, 2025
CLOUD FARE'S URL SCANNER
  • Tech

CLOUD FARE’S URL SCANNER

Paul Petersen October 28, 2024
  • Tech

SEC Focus on Communication Compliance

David Curry July 14, 2023

Categories

  • Art
  • Auto
  • Beauty
  • Business
  • Casino
  • Dating
  • Education
  • Entertainment
  • Fashion
  • Featured
  • Finance
  • Food
  • Gifts
  • Health
  • Home
  • Industrial
  • Insurance
  • Internet Marketing
  • Law
  • Lifestyle
  • Music
  • Pet
  • SEO
  • Shopping
  • Sports
  • Storage
  • Tech
  • Travel
  • Treatment
  • Wedding

Trending News

What to Pack When You Miss Home: Singaporean Snacks That Travel Well Singaporean Snacks That Travel Well 1

What to Pack When You Miss Home: Singaporean Snacks That Travel Well

August 22, 2025
What are the stages of a successful crypto presale? FEATURED IMAGE 2

What are the stages of a successful crypto presale?

August 11, 2025
How Commercial Asphalt Paving Handles Heavy Truck Loads How Commercial Asphalt Paving Handles Heavy Truck Loads 3

How Commercial Asphalt Paving Handles Heavy Truck Loads

August 2, 2025
What Defines Quality in Mobile Home Property Management Today Image 4

What Defines Quality in Mobile Home Property Management Today

July 26, 2025
M&D Supply Inc’s Top Gifts for New Homeowners in Rosenberg, TX eowners in 5

M&D Supply Inc’s Top Gifts for New Homeowners in Rosenberg, TX

July 1, 2025

You may have missed

Singaporean Snacks That Travel Well
  • Food

What to Pack When You Miss Home: Singaporean Snacks That Travel Well

Sheri Gill August 22, 2025
FEATURED IMAGE
  • Finance

What are the stages of a successful crypto presale?

David Curry August 11, 2025
How Commercial Asphalt Paving Handles Heavy Truck Loads
  • Home

How Commercial Asphalt Paving Handles Heavy Truck Loads

David Curry August 2, 2025
Image
  • Home

What Defines Quality in Mobile Home Property Management Today

Sheri Gill July 26, 2025
  • Get in Touch
  • About
© 2024 Copyright by ch-img.com. All rights reserved. | MoreNews by AF themes.