Home > Documentation > PostgreSQL to MS SQL

Command line version of PostgreSQL to MS SQL converter

To perform batch conversion or call conversion procedure from an automation script you can use console version of PostgreSQL-to-MSSQL called P2MAGENT.EXE. Find this file in PostgreSQL-to-MSSQL 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:

--dest=...   MS SQL database name
--dump   convert PostgreSQL database into T-SQL script file
--help   display help message and exit
--logfile=...   path to the logfile where execution traces will be written
--mode=...   how to process existing MS SQL database
(0 - overwrite the entire database, 1 - overwrite existing tables only, 2 - skip existing tables, 3 - merge, 4 - synchronize)
--mssqlh=...   Oracle server IP address or network name
--mssqlu=...   Oracle user name
--mssqlp=...   Oracle user password
--no_schema   do not include schema name in table name
--pgport=...   PostgreSQL port
--posgsh=...   PostgreSQL server IP address or network name
--posgsu=...   PostgreSQL user name
--posgsp=...   PostgreSQL user password
--profile=...   path to the file to load conversion settings from
--silent   use this option to disable program output
--skip_idx   skip converting indexes
--src=...   PostgreSQL database name
--tab_def   convert table definitions only
--tab_file=...   file containing table names to convert (one table name per line)
--views   convert PostgreSQL views into MS SQL format

In the following example the program converts all tables from PostgreSQL database "db 1" into MS SQL database "db1_mss":

P2MAGENT.EXE --src="db 1" --posgsu=postgres --posgsp=qwerty --dest="db1_mss" 
--mssqlh=FRACTAL --mssqlu=sa --mssqlp=the_passsword

Notes:

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