mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-10 08:17:00 +02:00
The website is moving to pgloader.org and readthedocs.io is going to be integrated. Let's see what happens. The docs build fine locally with the sphinx tools and the docs/Makefile. Having separate files for the documentation should help ease the maintenance and add new topics, such as support for Common Lisp Hackers level docs, which are currently missing.
236 lines
15 KiB
HTML
236 lines
15 KiB
HTML
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<title>Migrating a MS SQL Database to PostgreSQL — pgloader 3.4.1 documentation</title>
|
||
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
<script type="text/javascript">
|
||
var DOCUMENTATION_OPTIONS = {
|
||
URL_ROOT: '../',
|
||
VERSION: '3.4.1',
|
||
COLLAPSE_INDEX: false,
|
||
FILE_SUFFIX: '.html',
|
||
HAS_SOURCE: true,
|
||
SOURCELINK_SUFFIX: '.txt'
|
||
};
|
||
</script>
|
||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="Transformation Functions" href="transforms.html" />
|
||
<link rel="prev" title="Migrating a SQLite database to PostgreSQL" href="sqlite.html" />
|
||
|
||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||
|
||
</head>
|
||
<body>
|
||
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<div class="section" id="migrating-a-ms-sql-database-to-postgresql">
|
||
<h1>Migrating a MS SQL Database to PostgreSQL<a class="headerlink" href="#migrating-a-ms-sql-database-to-postgresql" title="Permalink to this headline">¶</a></h1>
|
||
<p>This command instructs pgloader to load data from a MS SQL database.
|
||
Automatic discovery of the schema is supported, including build of the
|
||
indexes, primary and foreign keys constraints.</p>
|
||
<p>Here’s an example:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span>load database
|
||
from mssql://user@host/dbname
|
||
into postgresql:///dbname
|
||
|
||
including only table names like 'GlobalAccount' in schema 'dbo'
|
||
|
||
set work_mem to '16MB', maintenance_work_mem to '512 MB'
|
||
|
||
before load do $$ drop schema if exists dbo cascade; $$;
|
||
</pre></div>
|
||
</div>
|
||
<p>The <cite>mssql</cite> command accepts the following clauses and options.</p>
|
||
<div class="section" id="ms-sql-database-source-specification-from">
|
||
<h2>MS SQL Database Source Specification: FROM<a class="headerlink" href="#ms-sql-database-source-specification-from" title="Permalink to this headline">¶</a></h2>
|
||
<p>Connection string to an existing MS SQL database server that listens and
|
||
welcome external TCP/IP connection. As pgloader currently piggybacks on the
|
||
FreeTDS driver, to change the port of the server please export the <cite>TDSPORT</cite>
|
||
environment variable.</p>
|
||
</div>
|
||
<div class="section" id="ms-sql-database-migration-options-with">
|
||
<h2>MS SQL Database Migration Options: WITH<a class="headerlink" href="#ms-sql-database-migration-options-with" title="Permalink to this headline">¶</a></h2>
|
||
<p>When loading from a <cite>MS SQL</cite> database, the same options as when loading a
|
||
<cite>MySQL</cite> database are supported. Please refer to the MySQL section. The
|
||
following options are added:</p>
|
||
<blockquote>
|
||
<div><ul>
|
||
<li><p class="first"><em>create schemas</em></p>
|
||
<p>When this option is listed, pgloader creates the same schemas as found
|
||
on the MS SQL instance. This is the default.</p>
|
||
</li>
|
||
<li><p class="first"><em>create no schemas</em></p>
|
||
<p>When this option is listed, pgloader refrains from creating any schemas
|
||
at all, you must then ensure that the target schema do exist.</p>
|
||
</li>
|
||
</ul>
|
||
</div></blockquote>
|
||
</div>
|
||
<div class="section" id="ms-sql-database-casting-rules">
|
||
<h2>MS SQL Database Casting Rules<a class="headerlink" href="#ms-sql-database-casting-rules" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="cast">
|
||
<h3>CAST<a class="headerlink" href="#cast" title="Permalink to this headline">¶</a></h3>
|
||
<p>The cast clause allows to specify custom casting rules, either to overload
|
||
the default casting rules or to amend them with special cases.</p>
|
||
<p>Please refer to the MySQL CAST clause for details.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ms-sql-partial-migration">
|
||
<h2>MS SQL Partial Migration<a class="headerlink" href="#ms-sql-partial-migration" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="including-only-table-names-like">
|
||
<h3>INCLUDING ONLY TABLE NAMES LIKE<a class="headerlink" href="#including-only-table-names-like" title="Permalink to this headline">¶</a></h3>
|
||
<p>Introduce a comma separated list of table name patterns used to limit the
|
||
tables to migrate to a sublist. More than one such clause may be used, they
|
||
will be accumulated together.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">including</span> <span class="n">only</span> <span class="n">table</span> <span class="n">names</span> <span class="n">lile</span> <span class="s1">'GlobalAccount'</span> <span class="ow">in</span> <span class="n">schema</span> <span class="s1">'dbo'</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="excluding-table-names-like">
|
||
<h3>EXCLUDING TABLE NAMES LIKE<a class="headerlink" href="#excluding-table-names-like" title="Permalink to this headline">¶</a></h3>
|
||
<p>Introduce a comma separated list of table name patterns used to exclude
|
||
table names from the migration. This filter only applies to the result of
|
||
the <em>INCLUDING</em> filter.</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">excluding</span> <span class="n">table</span> <span class="n">names</span> <span class="n">matching</span> <span class="s1">'LocalAccount'</span> <span class="ow">in</span> <span class="n">schema</span> <span class="s1">'dbo'</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ms-sql-schema-transformations">
|
||
<h2>MS SQL Schema Transformations<a class="headerlink" href="#ms-sql-schema-transformations" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="alter-schema-rename-to">
|
||
<h3>ALTER SCHEMA ‘…’ RENAME TO ‘…’<a class="headerlink" href="#alter-schema-rename-to" title="Permalink to this headline">¶</a></h3>
|
||
<p>Allows to rename a schema on the flight, so that for instance the tables
|
||
found in the schema ‘dbo’ in your source database will get migrated into the
|
||
schema ‘public’ in the target database with this command:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">alter</span> <span class="n">schema</span> <span class="s1">'dbo'</span> <span class="n">rename</span> <span class="n">to</span> <span class="s1">'public'</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="alter-table-names-matching-in-schema">
|
||
<h3>ALTER TABLE NAMES MATCHING … IN SCHEMA ‘…’<a class="headerlink" href="#alter-table-names-matching-in-schema" title="Permalink to this headline">¶</a></h3>
|
||
<p>See the MySQL explanation for this clause above. It works the same in the
|
||
context of migrating from MS SQL, only with the added option to specify the
|
||
name of the schema where to find the definition of the target tables.</p>
|
||
<p>The matching is done in pgloader itself, with a Common Lisp regular
|
||
expression lib, so doesn’t depend on the <em>LIKE</em> implementation of MS SQL,
|
||
nor on the lack of support for regular expressions in the engine.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ms-sql-driver-setup-and-encoding">
|
||
<h2>MS SQL Driver setup and encoding<a class="headerlink" href="#ms-sql-driver-setup-and-encoding" title="Permalink to this headline">¶</a></h2>
|
||
<p>pgloader is using the <cite>FreeTDS</cite> driver, and internally expects the data to
|
||
be sent in utf-8. To achieve that, you can configure the FreeTDS driver with
|
||
those defaults, in the file <cite>~/.freetds.conf</cite>:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span><span class="k">global</span><span class="p">]</span>
|
||
<span class="n">tds</span> <span class="n">version</span> <span class="o">=</span> <span class="mf">7.4</span>
|
||
<span class="n">client</span> <span class="n">charset</span> <span class="o">=</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="default-ms-sql-casting-rules">
|
||
<h2>Default MS SQL Casting Rules<a class="headerlink" href="#default-ms-sql-casting-rules" title="Permalink to this headline">¶</a></h2>
|
||
<p>When migrating from MS SQL the following Casting Rules are provided:</p>
|
||
<p>Numbers:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">tinyint</span> <span class="n">to</span> <span class="n">smallint</span>
|
||
|
||
<span class="nb">type</span> <span class="nb">float</span> <span class="n">to</span> <span class="nb">float</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">real</span> <span class="n">to</span> <span class="n">real</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">double</span> <span class="n">to</span> <span class="n">double</span> <span class="n">precision</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">numeric</span> <span class="n">to</span> <span class="n">numeric</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">decimal</span> <span class="n">to</span> <span class="n">numeric</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">money</span> <span class="n">to</span> <span class="n">numeric</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
<span class="nb">type</span> <span class="n">smallmoney</span> <span class="n">to</span> <span class="n">numeric</span> <span class="n">using</span> <span class="nb">float</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">string</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Texts:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">char</span> <span class="n">to</span> <span class="n">text</span> <span class="n">drop</span> <span class="n">typemod</span>
|
||
<span class="nb">type</span> <span class="n">nchat</span> <span class="n">to</span> <span class="n">text</span> <span class="n">drop</span> <span class="n">typemod</span>
|
||
<span class="nb">type</span> <span class="n">varchar</span> <span class="n">to</span> <span class="n">text</span> <span class="n">drop</span> <span class="n">typemod</span>
|
||
<span class="nb">type</span> <span class="n">nvarchar</span> <span class="n">to</span> <span class="n">text</span> <span class="n">drop</span> <span class="n">typemod</span>
|
||
<span class="nb">type</span> <span class="n">xml</span> <span class="n">to</span> <span class="n">text</span> <span class="n">drop</span> <span class="n">typemod</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Binary:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">binary</span> <span class="n">to</span> <span class="n">bytea</span> <span class="n">using</span> <span class="n">byte</span><span class="o">-</span><span class="n">vector</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">bytea</span>
|
||
<span class="nb">type</span> <span class="n">varbinary</span> <span class="n">to</span> <span class="n">bytea</span> <span class="n">using</span> <span class="n">byte</span><span class="o">-</span><span class="n">vector</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">bytea</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Date:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">datetime</span> <span class="n">to</span> <span class="n">timestamptz</span>
|
||
<span class="nb">type</span> <span class="n">datetime2</span> <span class="n">to</span> <span class="n">timestamptz</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Others:</p>
|
||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">bit</span> <span class="n">to</span> <span class="n">boolean</span>
|
||
<span class="nb">type</span> <span class="n">hierarchyid</span> <span class="n">to</span> <span class="n">bytea</span>
|
||
<span class="nb">type</span> <span class="n">geography</span> <span class="n">to</span> <span class="n">bytea</span>
|
||
<span class="nb">type</span> <span class="n">uniqueidentifier</span> <span class="n">to</span> <span class="n">uuid</span> <span class="n">using</span> <span class="n">sql</span><span class="o">-</span><span class="n">server</span><span class="o">-</span><span class="n">uniqueidentifier</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">uuid</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper"><div class="relations">
|
||
<h3>Related Topics</h3>
|
||
<ul>
|
||
<li><a href="../index.html">Documentation overview</a><ul>
|
||
<li>Previous: <a href="sqlite.html" title="previous chapter">Migrating a SQLite database to PostgreSQL</a></li>
|
||
<li>Next: <a href="transforms.html" title="next chapter">Transformation Functions</a></li>
|
||
</ul></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3>Quick search</h3>
|
||
<form class="search" action="../search.html" method="get">
|
||
<div><input type="text" name="q" /></div>
|
||
<div><input type="submit" value="Go" /></div>
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="footer">
|
||
©2017, Dimitri Fontaine.
|
||
|
||
|
|
||
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.5</a>
|
||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
|
||
|
||
|
|
||
<a href="../_sources/ref/mssql.rst.txt"
|
||
rel="nofollow">Page source</a>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |