@@ -1377,216 +1377,4 @@ archive_command = 'local_backup_script.sh'
13771377 </sect2>
13781378 </sect1>
13791379
1380- <sect1 id="migration">
1381- <title>Migration Between Releases</title>
1382-
1383- <indexterm zone="migration">
1384- <primary>upgrading</primary>
1385- </indexterm>
1386-
1387- <indexterm zone="migration">
1388- <primary>version</primary>
1389- <secondary>compatibility</secondary>
1390- </indexterm>
1391-
1392- <para>
1393- This section discusses how to migrate your database data from one
1394- <productname>PostgreSQL</> release to a newer one.
1395- The software installation procedure <foreignphrase>per se</> is not the
1396- subject of this section; those details are in <xref linkend="installation">.
1397- </para>
1398-
1399- <para>
1400- <productname>PostgreSQL</> major versions are represented by the
1401- first two digit groups of the version number, e.g., 8.4.
1402- <productname>PostgreSQL</> minor versions are represented by the
1403- third group of version digits, e.g., 8.4.2 is the second minor
1404- release of 8.4. Minor releases never change the internal storage
1405- format and are always compatible with earlier and later minor
1406- releases of the same major version number, e.g., 8.4.2 is compatible
1407- with 8.4, 8.4.1 and 8.4.6. To update between compatible versions,
1408- you simply replace the executables while the server is down and
1409- restart the server. The data directory remains unchanged —
1410- minor upgrades are that simple.
1411- </para>
1412-
1413- <para>
1414- For <emphasis>major</> releases of <productname>PostgreSQL</>, the
1415- internal data storage format is subject to change, thus complicating
1416- upgrades. The traditional method for moving data to a new major version
1417- is to dump and reload the database. Other, less-well-tested possibilities
1418- are available, as discussed below.
1419- </para>
1420-
1421- <para>
1422- New major versions also typically introduce some user-visible
1423- incompatibilities, so application programming changes may be required.
1424- Cautious users will want to test their client applications on the new
1425- version before switching over fully; therefore, it's often a good idea to
1426- set up concurrent installations of old and new versions. When
1427- testing a <productname>PostgreSQL</> major upgrade, consider the
1428- following categories of possible changes:
1429- </para>
1430-
1431- <variablelist>
1432-
1433- <varlistentry>
1434- <term>Administration</term>
1435- <listitem>
1436- <para>
1437- The capabilities available for administrators to monitor and control
1438- the server often change and improve in each major release.
1439- </para>
1440- </listitem>
1441- </varlistentry>
1442-
1443- <varlistentry>
1444- <term>SQL</term>
1445- <listitem>
1446- <para>
1447- Typically this includes new SQL command capabilities and not changes
1448- in behavior, unless specifically mentioned in the release notes.
1449- </para>
1450- </listitem>
1451- </varlistentry>
1452-
1453- <varlistentry>
1454- <term>Library API</term>
1455- <listitem>
1456- <para>
1457- Typically libraries like <application>libpq</> only add new
1458- functionality, again unless mentioned in the release notes.
1459- </para>
1460- </listitem>
1461- </varlistentry>
1462-
1463- <varlistentry>
1464- <term>System Catalogs</term>
1465- <listitem>
1466- <para>
1467- System catalog changes usually only affect database management tools.
1468- </para>
1469- </listitem>
1470- </varlistentry>
1471-
1472- <varlistentry>
1473- <term>Server C-language API</term>
1474- <listitem>
1475- <para>
1476- This involves changes in the backend function API, which is written
1477- in the C programming language. Such changes affect code that
1478- references backend functions deep inside the server.
1479- </para>
1480- </listitem>
1481- </varlistentry>
1482-
1483- </variablelist>
1484-
1485- <sect2 id="migration-methods-pgdump">
1486- <title>Migrating Data via <application>pg_dump</></title>
1487-
1488- <para>
1489- To dump data from one major version of <productname>PostgreSQL</> and
1490- reload it in another, you must use <application>pg_dump</>; file system
1491- level backup methods will not work. (There are checks in place that prevent
1492- you from using a data directory with an incompatible version of
1493- <productname>PostgreSQL</productname>, so no great harm can be done by
1494- trying to start the wrong server version on a data directory.)
1495- </para>
1496-
1497- <para>
1498- It is recommended that you use the <application>pg_dump</> and
1499- <application>pg_dumpall</> programs from the newer version of
1500- <productname>PostgreSQL</>, to take advantage of enhancements
1501- that might have been made in these programs. Current releases of the
1502- dump programs can read data from any server version back to 7.0.
1503- </para>
1504-
1505- <para>
1506- The least downtime can be achieved by installing the new server in
1507- a different directory and running both the old and the new servers
1508- in parallel, on different ports. Then you can use something like:
1509-
1510- <programlisting>
1511- pg_dumpall -p 5432 | psql -d postgres -p 6543
1512- </programlisting>
1513-
1514- to transfer your data. Or you can use an intermediate file if you wish.
1515- Then you can shut down the old server and start the new server using
1516- the port the old one was running on. You should make sure that the
1517- old database is not updated after you begin to run
1518- <application>pg_dumpall</>, otherwise you will lose those updates. See
1519- <xref linkend="client-authentication"> for information on how to prohibit
1520- access.
1521- </para>
1522-
1523- <para>
1524- If you cannot or do not want to run two servers in parallel, you can
1525- do the backup step before installing the new version, bring down
1526- the old server, move the old version out of the way, install the new
1527- version, start the new server, and restore the data. For example:
1528-
1529- <programlisting>
1530- pg_dumpall > backup
1531- pg_ctl stop
1532- mv /usr/local/pgsql /usr/local/pgsql.old
1533- # Rename any tablespace directories as well
1534- cd ~/postgresql-&version;
1535- gmake install
1536- initdb -D /usr/local/pgsql/data
1537- postgres -D /usr/local/pgsql/data
1538- psql -f backup postgres
1539- </programlisting>
1540-
1541- See <xref linkend="runtime"> about ways to start and stop the
1542- server and other details. The installation instructions will advise
1543- you of strategic places to perform these steps.
1544- </para>
1545-
1546- <note>
1547- <para>
1548- When you <quote>move the old installation out of the way</quote>
1549- it might no longer be perfectly usable. Some of the executable programs
1550- contain absolute paths to various installed programs and data files.
1551- This is usually not a big problem, but if you plan on using two
1552- installations in parallel for a while you should assign them
1553- different installation directories at build time. (This problem
1554- is rectified in <productname>PostgreSQL</> version 8.0 and later, so long
1555- as you move all subdirectories containing installed files together;
1556- for example if <filename>/usr/local/postgres/bin/</> goes to
1557- <filename>/usr/local/postgres.old/bin/</>, then
1558- <filename>/usr/local/postgres/share/</> must go to
1559- <filename>/usr/local/postgres.old/share/</>. In pre-8.0 releases
1560- moving an installation like this will not work.)
1561- </para>
1562- </note>
1563- </sect2>
1564-
1565- <sect2 id="migration-methods-other">
1566- <title>Other Data Migration Methods</title>
1567-
1568- <para>
1569- The <filename>contrib</> program
1570- <link linkend="pgupgrade"><application>pg_upgrade</application></link>
1571- allows an installation to be migrated in-place from one major
1572- <productname>PostgreSQL</> version to the next. Keep in mind that this
1573- method does not provide any scope for running old and new versions
1574- concurrently. Also, <application>pg_upgrade</application> is much less
1575- battle-tested than <application>pg_dump</application>, so having an
1576- up-to-date backup is strongly recommended in case something goes wrong.
1577- </para>
1578-
1579- <para>
1580- It is also possible to use certain replication methods, such as
1581- <productname>Slony</>, to create a standby server with the updated version of
1582- <productname>PostgreSQL</>. The standby can be on the same computer or
1583- a different computer. Once it has synced up with the master server
1584- (running the older version of <productname>PostgreSQL</>), you can
1585- switch masters and make the standby the master and shut down the older
1586- database instance. Such a switch-over results in only several seconds
1587- of downtime for an upgrade.
1588- </para>
1589-
1590- </sect2>
1591- </sect1>
15921380</chapter>
0 commit comments