Skip to content
hjort edited this page Jun 12, 2011 · 2 revisions

Usage sample on how to create database dumps from MS SQL.

First you might invoke dump2pg with -l argument just to know existing table names:

$ dump2pg -d net.sourceforge.jtds.jdbc.Driver -r jdbc:jtds:sqlserver://myserver:1433 \
          -u guest -p pass -c catalog -l

Then you can issue dump creation by using -f argument. You can even specify a single table or several ones. Take a look:

$ dump2pg -d net.sourceforge.jtds.jdbc.Driver -r jdbc:jtds:sqlserver://myserver:1433 \
          -u guest -p pass -c catalog -f dump.sql -t tb_uf

The result is a generated dump file filled with bulk insertion commands in PostgreSQL specific COPY syntax:

$ cat dump.sql 

-- Schema: null, Table: tb_uf
copy TB_UF (coduf, descuf, codufreg) from stdin;
AC	Acre                          	N 
AL	Alagoas                       	NE
AM	Amazonas                      	N 
AP	Amapá                         	N 
BA	Bahia                         	NE
CE	Ceará                         	NE
DF	Distrito Federal              	CO
ES	Espírito Santo                	SD
GO	Goiás                         	CO
MA	Maranhão                      	NE
MG	Minas Gerais                  	SD
MS	Mato Grosso do Sul            	CO
MT	Mato Grosso                   	CO
PA	Pará                          	N 
PB	Paraíba                       	NE
PE	Pernambuco                    	NE
PI	Piauí                         	NE
PR	Paraná                        	S 
RJ	Rio de Janeiro                	SD
RN	Rio Grande do Norte           	NE
RO	Rondônia                      	N 
RR	Roraima                       	N 
RS	Rio Grande do Sul             	S 
SC	Santa Catarina                	S 
SE	Sergipe                       	NE
SP	São Paulo                     	SD
TO	Tocantins                     	N 
\.

That's it! Now you can ask your DBA (if not you) and simply call a psql command passing the dump file.

Clone this wiki locally