From:       To:      
Home > Documentation > SQL Server to PostgreSQL

Command line for SQL Server to PostgreSQL converter

To perform batch conversion or call conversion procedure from an automation script you can use console version of SQL Server to PostgreSQL converter called M2PAGENT.EXE. in the installation folder. You can either run this tool directly from command line or call it from any script as well. The program supports the following command-line options:

--as_dbo   connect to SQL Server as database owner
--case_sense   make names case sensitive (default is off)
--dest=...   PostgreSQL database or script file
--dump   convert SQL Server database into PostgreSQL file
--help   display help message and exit
--logfile=...   path to the logfile where execution traces will be written
--mode=...   how to process an existing PostgreSQL database (0 - overwrite the entire database, 1 - overwrite existing tables only, 2 - skip existing tables, 3 - merge, 4 - synchronize)
--mssqlh=...   SQL Server IP address or network name
--mssqlu=...   SQL Server user name
--mssqlp=...   SQL Server user password
--owned   convert tables owned by the user only
--pgport=...   PostgreSQL port
--posgsh=...   PostgreSQL server IP address or network name
--posgsu=...   PostgreSQL user name
--posgsp=...   PostgreSQL user password
--owned   convert tables owned by the user only
--profile=...   path to the file to load conversion settings from
--silent   use this option to disable program output
--skip_idx   skip converting indexes
--src=...   MS SQL database name
--tab_def   convert table definitions only
--tab_file=...   name of the file containing table names to convert (one table name per line)

In the following example the program converts local SQL Server database "db1" into PostgreSQL database "db1 from mssql" on the remote PostgreSQL server "PostgreSQLhost" using table names file "c:\tabfile1.txt":

M2PAGENT.EXE --src=db1 --dest="db1 from mssql" --posgsh=mysqlhost --posgsu=administrator 
--posgsp=the_passsword --tab_file=c:\tabfile1.txt

Table names file should be formatted as follows:

Table_1
Table_2
...
Table_N

Notes:

  1. If you specified a profile, there is no need to specify any other parameters
  2. You can omit 'mssqlh' or 'mysqlh' to connect local database server
  3. You can omit 'mssqlu' and 'mssqlp' parameters to connect to SQL Server using Windows authentication
  4. It is necessary to specify PostgreSQL port parameter only if it differs from the default: 5432
  5. If you omit 'tab_file' parameter, all database tables will be converted
  6. If you omit 'mode' parameter, default mode 'overwrite the entire database' will be used
  7. Command line parameters that contain spaces should be enclosed in quotes (for example --dest="my database")