File: installation.xml

package info (click to toggle)
postgis 2.1.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 35,424 kB
  • ctags: 8,886
  • sloc: sql: 113,491; ansic: 97,254; xml: 41,127; sh: 11,925; java: 5,662; perl: 3,113; makefile: 2,265; python: 1,198; yacc: 438; lex: 114
file content (1769 lines) | stat: -rw-r--r-- 74,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="postgis_installation">
  <title>PostGIS Installation</title>

  <para>
	This chapter details the steps required to install PostGIS.
  </para>

  <sect1 id="install_short_version">
	<title>Short Version</title>
	<para>To compile assuming you have all the dependencies in your search path:</para>
	<programlisting>tar xvfz postgis-&last_release_version;.tar.gz
cd postgis-&last_release_version;
./configure
make
make install</programlisting>
	<para>Once postgis is installed, it needs to be enabled in each individual database you want to use it in.</para>
	<note><para>The raster support is currently optional, but installed by default. For enabling using the PostgreSQL 9.1+ extensions model raster is required. Using the extension enable process is preferred and more user-friendly. To spatially enable your database:</para></note>
	<programlisting>psql -d yourdatabase -c "CREATE EXTENSION postgis;"
psql -d yourdatabase -c "CREATE EXTENSION postgis_topology;"
psql -d yourdatabase -c "CREATE EXTENSION postgis_tiger_geocoder;"</programlisting>
	
	
	<para>Please refer to <xref linkend="make_install_postgis_extensions" /> for more details about querying installed/available extensions and upgrading extensions, or switching from a non-extension install to an extension install.</para>
	
	<para>For those running PostgreSQL 9.0 or who decided for some reason not to compile with raster support, or just are old-fashioned, here are longer more painful instructions for you:</para>
	<para>All the .sql files once installed will be installed in share/contrib/postgis-&last_minor_version; folder
		of your PostgreSQL install</para>

	<programlisting>createdb yourdatabase
createlang plpgsql yourdatabase
psql -d yourdatabase -f postgis.sql
psql -d yourdatabase -f postgis_comments.sql
psql -d yourdatabase -f spatial_ref_sys.sql
psql -d yourdatabase -f rtpostgis.sql
psql -d yourdatabase -f raster_comments.sql
psql -d yourdatabase -f topology.sql
psql -d yourdatabase -f topology_comments.sql</programlisting>

	<para>
	  The rest of this chapter goes into detail each of the above installation
	  steps.
	</para>
	<para>As of PostGIS 2.1.3, out-of-db rasters and all raster drivers are disabled by default. In order to re-enable these, you need to set the following environment variables:
	<varname>POSTGIS_GDAL_ENABLED_DRIVERS</varname> and <varname>POSTGIS_ENABLE_OUTDB_RASTERS</varname> in the server environment.</para>
	
	<para>If you want to enable offline raster:</para>
	<programlisting>POSTGIS_ENABLE_OUTDB_RASTERS=1</programlisting>
	<para>Any other setting or no setting at all will disable out of db rasters.</para>
	<para>In order to enable all GDAL drivers available in your GDAL install, set this environment variable as follows</para>
	<programlisting>POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL</programlisting>
	<para>If you want to only enable specific drivers, set your environment variable as follows:</para>
	<programlisting>POSTGIS_GDAL_ENABLED_DRIVERS="GTiff PNG JPEG GIF XYZ"</programlisting>
	
	<note><para>If you are on windows, do not quote the driver list</para></note>
	
	<para>Setting environment variables varies depending on OS.  For PostgreSQL installed on Ubuntu or Debian via apt-postgresql, the preferred way is to
	edit <filename>/etc/postgresql/<replaceable>9.3</replaceable>/<replaceable>main</replaceable>/environment</filename> where 9.3 refers to version of PostgreSQL and main refers to the cluster.</para>
	
	<para>On windows, if you are running as a service, you can set via System variables which for Windows 7 you can get to by right-clicking on Computer-&gt;Properties Advanced System Settings or in explorer navigating to <varname>Control Panel\All Control Panel Items\System</varname>. 
	Then clicking <emphasis>Advanced System Settings -&gt;Advanced->Environment Variables</emphasis> and adding new system variables.</para>
	<para>After you set the environment variables, you'll need to restart your PostgreSQL service for the changes to take effect.</para>
  </sect1>

  <sect1 id="install_requirements">
	<title>Install Requirements</title>

	<para>
	  PostGIS has the following requirements for building and usage:
	</para>

	<para>
	  <emphasis role="bold">Required</emphasis>
	</para>

	<itemizedlist>
	  <listitem>
		<para>
		  PostgreSQL &min_postgres_version; or higher. A complete installation
		  of PostgreSQL (including server headers) is required. PostgreSQL
		  is available from
		  <ulink url="http://www.postgresql.org">
			http://www.postgresql.org
		  </ulink>
		  .
		</para>
		<para>For a full PostgreSQL / PostGIS support matrix and PostGIS/GEOS support matrix refer to 
			<ulink url="http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS">http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS</ulink>
		</para>
	  </listitem>

	  <listitem>
		<para>
		  GNU C compiler (<filename>gcc</filename>). Some other ANSI C compilers
		  can be used to compile PostGIS, but we find far fewer problems when
		  compiling with <filename>gcc</filename>.
		</para>
	  </listitem>

	  <listitem>
		<para>
		  GNU Make (<filename>gmake</filename> or <filename>make</filename>).
		  For many systems, GNU <filename>make</filename> is the default version
		  of make. Check the version by invoking <filename>make -v</filename>.
		  Other versions of <filename>make</filename> may not process the
		  PostGIS <filename>Makefile</filename> properly.
		</para>
	  </listitem>

	  <listitem>
		<para>
		  Proj4 reprojection library, version 4.6.0 or greater. The Proj4
		  library is used to provide coordinate reprojection support within
		  PostGIS. Proj4 is available for download from
		  <ulink url="http://trac.osgeo.org/proj/">
			http://trac.osgeo.org/proj/
		  </ulink>
		  .
		</para>
	  </listitem>

	  <listitem>
		<para>
		  GEOS geometry library, version 3.3 or greater, but GEOS 3.4+ is recommended to take full advantage of all the new functions and features.  Without GEOS 3.4,
			you will be missing some major enhancements such as ST_Triangles and long-running function interruption, and improvements to geometry validation and
			making geometries valid such as ST_ValidDetail and ST_MakeValid.  GEOS 3.3.2+ is also required for topology support.  GEOS is available for download from
		  <ulink url="http://trac.osgeo.org/geos/">
			http://trac.osgeo.org/geos/
		  </ulink> and 3.4+ is backward-compatible with older versions so fairly safe to upgrade.
		</para>
	  </listitem>
	  <listitem>
		<para>
		  LibXML2, version 2.5.x or higher. LibXML2 is currently used in some imports
		  functions (ST_GeomFromGML and ST_GeomFromKML). LibXML2 is available for download from 
		  <ulink url="http://xmlsoft.org/downloads.html">http://xmlsoft.org/downloads.html</ulink>.
		</para>
	  </listitem>
	  <listitem>
		<para>
		  JSON-C, version 0.9 or higher. JSON-C is currently used to import GeoJSON via the
		  function ST_GeomFromGeoJson. JSON-C is available for download from
		  <ulink url="https://github.com/json-c/json-c/releases">https://github.com/json-c/json-c/releases</ulink>.
		</para>
	  </listitem>
	  
	  <listitem>
		<para>
		  GDAL, version 1.8 or higher (1.9 or higher is strongly recommended since some things will not work well or behavior differently with lower versions).  This is required for raster support and to be able to install with <code>CREATE EXTENSION postgis</code> so highly recommended for those running 9.1+.
		  <ulink url="http://trac.osgeo.org/gdal/wiki/DownloadSource">http://trac.osgeo.org/gdal/wiki/DownloadSource</ulink>.
		</para>
	  </listitem>
	</itemizedlist>

	<para>
	  <emphasis role="bold">Optional</emphasis>
	</para>

	<itemizedlist>
	  <listitem>
		<para>
		  GDAL (pseudo optional) only if you don't want raster and don't care about installing with <code>CREATE EXTENSION postgis</code> can you leave it out.
		  Keep in mind other extensions may have a requires postgis extension which will prevent you from installing them unless you install postgis as an extension. So it is highly recommended you compile with GDAL support.
		</para>
	  </listitem>	
	  <listitem>
		<para>
		  GTK (requires GTK+2.0, 2.8+) to compile the shp2pgsql-gui shape file loader.
		  <ulink url="http://www.gtk.org/">
			http://www.gtk.org/
		  </ulink>
		  .
		</para>
	  </listitem>
	  
	  <listitem>
		<para>
                  SFCGAL, version 0.2 (or higher) could be used to provide additional 2D and 3D advanced analysis functions to PostGIS cf <xref linkend="reference_sfcgal" />. And also allow to use SFCGAL rather than GEOS for some 2D functions provided by both backends (like ST_Intersection or ST_Area, for instance). A PostgreSQL configuration variable <code>postgis.backend</code> allow end user to control which backend he want to use if SFCGAL is installed (GEOS by default). Nota: SFCGAL 0.2 require at least CGAL 4.1.

		  <ulink url="https://github.com/Oslandia/SFCGAL">https://github.com/Oslandia/SFCGAL</ulink>.
		</para>
	  </listitem>

	  <listitem>
		<para>
		 CUnit (<filename>CUnit</filename>). This is needed for regression testing. <ulink url="http://cunit.sourceforge.net/">http://cunit.sourceforge.net/</ulink>
		</para>
	  </listitem>
	  
	  <listitem>
		<para>
		  Apache Ant (<filename>ant</filename>) is required for building any of
		  the drivers under the <filename>java</filename> directory. Ant is
		  available from
		  <ulink url="http://ant.apache.org">
			http://ant.apache.org
		  </ulink>
		  .
		</para>
	  </listitem>

	  <listitem>
		<para>
		  DocBook (<filename>xsltproc</filename>) is required for building the
		  documentation. Docbook is available from
		  <ulink url="http://www.docbook.org/">
			http://www.docbook.org/
		  </ulink>
		  .
		</para>
	  </listitem>

	  <listitem>
		<para>
		  DBLatex (<filename>dblatex</filename>) is required for building the
		  documentation in PDF format. DBLatex is available from
		  <ulink url="http://dblatex.sourceforge.net/">
			http://dblatex.sourceforge.net/
		  </ulink>
		  .
		</para>
	  </listitem>

	  <listitem>
		<para>
		  ImageMagick (<filename>convert</filename>) is required to generate the
		  images used in the documentation. ImageMagick is available from
		  <ulink url="http://www.imagemagick.org/">
			http://www.imagemagick.org/
		  </ulink>
		  .
		</para>
	  </listitem>
	</itemizedlist>
  </sect1>

  <sect1 id="install_getting_source">
	<title>Getting the Source</title>

	<para>
	  Retrieve the PostGIS source archive from the downloads website
	  <ulink url="&postgis_download_url;">
		&postgis_download_url;
	  </ulink>
	</para>

	<programlisting>wget &postgis_download_url;
tar -xvzf postgis-&last_release_version;.tar.gz</programlisting>

	<para>
	  This will create a directory called
	  <varname>postgis-&last_release_version;</varname> in the current working
	  directory.
	</para>

	<para>
	  Alternatively, checkout the source from the
	  <ulink url="http://subversion.apache.org/">
		svn
	  </ulink>
	  repository
	  <ulink url="http://svn.osgeo.org/postgis/trunk/">
		http://svn.osgeo.org/postgis/trunk/
	  </ulink>
	  .
	</para>

	<programlisting>svn checkout http://svn.osgeo.org/postgis/trunk/ postgis-&last_release_version;</programlisting>

	<para>
	  Change into the newly created
	  <varname>postgis-&last_release_version;</varname> directory to continue
	  the installation.
	</para>
  </sect1>

  <sect1 id="PGInstall">
	<title>Compiling and Install from Source: Detailed</title>

	<note>
	  <para>
		Many OS systems now include pre-built packages for PostgreSQL/PostGIS.
		In many cases compilation is only necessary if you want the most
		bleeding edge versions or you are a package maintainer.
	  </para>
	  <para>This section includes general compilation instructions, if you are compiling for Windows etc
	  	or another OS, you may find additional more detailed help at <ulink url="http://trac.osgeo.org/postgis/wiki/UsersWikiInstall">PostGIS User contributed compile guides</ulink> and <ulink url="http://trac.osgeo.org/postgis/wiki/DevWikiMain">PostGIS Dev Wiki</ulink>.</para>
	  <para>Pre-Built Packages for various OS are listed in <ulink url="http://trac.osgeo.org/postgis/wiki/UsersWikiPackages">PostGIS Pre-built Packages</ulink></para>
	  <para>If you are a windows user, you can get stable builds via Stackbuilder or <ulink url="http://www.postgis.org/download/windows/">PostGIS Windows download site</ulink>
	  We also have <ulink url="http://www.postgis.org/download/windows/experimental.php">very bleeding-edge windows experimental builds</ulink> that are built usually once or twice a week or whenever anything exciting happens.  You can
	  use these to experiment with the in progress releases of PostGIS</para>
	</note>

	<para>
	  The PostGIS module is an extension to the PostgreSQL backend server. As
	  such, PostGIS &last_release_version; <emphasis>requires</emphasis> full
	  PostgreSQL server headers access in order to compile. It can be built
	  against PostgreSQL versions &min_postgres_version; or higher. Earlier
	  versions of PostgreSQL are <emphasis>not</emphasis> supported.
	</para>

	<para>
	  Refer to the PostgreSQL installation guides if you haven't already
	  installed PostgreSQL.
	  <ulink url="http://www.postgresql.org">
		http://www.postgresql.org
	  </ulink>
	  .
	</para>

	<note>
	  <para>
		For GEOS functionality, when you install PostgresSQL you may need to
		explicitly link PostgreSQL against the standard C++ library:
	  </para>

	  <programlisting>LDFLAGS=-lstdc++ ./configure [YOUR OPTIONS HERE]</programlisting>

	  <para>
		This is a workaround for bogus C++ exceptions interaction with older
		development tools. If you experience weird problems (backend
		unexpectedly closed or similar things) try this trick. This will require
		recompiling your PostgreSQL from scratch, of course.
	  </para>
	</note>

	<para>
	  The following steps outline the configuration and compilation of the
	  PostGIS source. They are written for Linux users and will not work on
	  Windows or Mac.
	</para>

	<sect2 id="installation_configuration">
	  <title>Configuration</title>

	  <para>
		As with most linux installations, the first step is to generate the
		Makefile that will be used to build the source code. This is done by
		running the shell script
	  </para>

	  <para>
		<command>./configure</command>
	  </para>

	  <para>
		With no additional parameters, this command will attempt to
		automatically locate the required components and libraries needed to
		build the PostGIS source code on your system. Although this is the most
		common usage of <command>./configure</command>, the script accepts
		several parameters for those who have the required libraries and
		programs in non-standard locations.
	  </para>

	  <para>
		The following list shows only the most commonly used parameters. For a
		complete list, use the <command>--help</command> or
		<command>--help=short</command> parameters.
	  </para>

	  <variablelist>
		<varlistentry>
		  <term><command>--prefix=PREFIX</command></term>
		  <listitem>
			<para>
			  This is the location the PostGIS libraries and SQL scripts will be
			  installed to. By default, this location is the same as the
			  detected PostgreSQL installation.
			</para>

			<caution>
			  <para>
				This parameter is currently broken, as the package will only
				install into the PostgreSQL installation directory. Visit
				<ulink url="http://trac.osgeo.org/postgis/ticket/635">
				  http://trac.osgeo.org/postgis/ticket/635
				</ulink>
				to track this bug.
			  </para>
			</caution>
		  </listitem>
		</varlistentry>

		<varlistentry>
		  <term><command>--with-pgconfig=FILE</command></term>
		  <listitem>
			<para>
			  PostgreSQL provides a utility called <command>pg_config</command>
			  to enable extensions like PostGIS to locate the PostgreSQL
			  installation directory. Use this parameter
			  (<command>--with-pgconfig=/path/to/pg_config</command>) to
			  manually specify a particular PostgreSQL installation that PostGIS
			  will build against.
			</para>
		  </listitem>
		</varlistentry>
		
		<varlistentry>
		  <term><command>--with-gdalconfig=FILE</command></term>
		  <listitem>
			<para>
			  GDAL, a required library, provides functionality needed for raster support
			  <command>gdal-config</command> to enable software installations to
			  locate the GDAL installation directory. Use this parameter
			  (<command>--with-gdalconfig=/path/to/gdal-config</command>) to
			  manually specify a particular GDAL installation that PostGIS will
			  build against.			  
			</para>
		  </listitem>
		</varlistentry>

		<varlistentry>
		  <term><command>--with-geosconfig=FILE</command></term>
		  <listitem>
			<para>
			  GEOS, a required geometry library, provides a utility called
			  <command>geos-config</command> to enable software installations to
			  locate the GEOS installation directory. Use this parameter
			  (<command>--with-geosconfig=/path/to/geos-config</command>) to
			  manually specify a particular GEOS installation that PostGIS will
			  build against.
			</para>
		  </listitem>
		</varlistentry>
		
		<varlistentry>
		  <term><command>--with-xml2config=FILE</command></term>
		  <listitem>
			<para>
			  LibXML is the library required for doing GeomFromKML/GML processes.
			  It normally is found if you have libxml installed, but if not or you want
			  a specific version used, you'll need to point PostGIS at a specific 
			  <filename>xml2-config</filename> confi file to enable software installations to
			  locate the LibXML installation directory. Use this parameter
			  (<command>>--with-xml2config=/path/to/xml2-config</command>) to
			  manually specify a particular LibXML installation that PostGIS will
			  build against.
			</para>
		  </listitem>
		</varlistentry>
		 
		

		<varlistentry>
		  <term><command>--with-projdir=DIR</command></term>
		  <listitem>
			<para>
			  Proj4 is a reprojection library required by PostGIS. Use this
			  parameter (<command>--with-projdir=/path/to/projdir</command>) to
			  manually specify a particular Proj4 installation directory that
			  PostGIS will build against.
			</para>
		  </listitem>
		</varlistentry>
		
		<varlistentry>
		  <term><command>--with-libiconv=DIR</command></term>
		  <listitem>
			<para>
			  Directory where iconv is installed.
			</para>
		  </listitem>
		</varlistentry>
		
		<varlistentry>
		  <term><command>--with-jsondir=DIR</command></term>
		  <listitem>
			<para>
			  <ulink url="http://oss.metaparadigm.com/json-c/">JSON-C</ulink> is an MIT-licensed JSON library required by PostGIS ST_GeomFromJSON support. Use this
			  parameter (<command>--with-jsondir=/path/to/jsondir</command>) to
			  manually specify a particular JSON-C installation directory that
			  PostGIS will build against.
			</para>
		  </listitem>
		</varlistentry>

		<varlistentry>
		  <term><command>--with-gui</command></term>
		  <listitem>
			<para>
			  Compile the data import GUI (requires GTK+2.0).  This will create shp2pgsql-gui graphical interface
			  to shp2pgsql.
			</para>
		  </listitem>
		</varlistentry>
		<varlistentry>
		  <term><command>--with-raster</command></term>
		  <listitem>
			<para>
			  Compile with raster support.  This will build rtpostgis-&last_release_version; library and rtpostgis.sql file.  This may not
			  be required in final release as plan is to build in raster support by default. 
			</para>
		  </listitem>
		</varlistentry>
		<varlistentry>
		  <term><command>--with-topology</command></term>
		  <listitem>
			<para>
			  Compile with topology support.  This will build the topology.sql file.  There is no corresponding library
			  as all logic needed for topology is in postgis-&last_release_version; library.
			</para>
		  </listitem>
		</varlistentry>
		<varlistentry>
		  <term><command>--with-gettext=no</command></term>
		  <listitem>
			<para>
			  By default PostGIS will try to detect gettext support and compile with it, however if you run into incompatibility issues that
			  cause breakage of loader, you can disable it entirely with this command.  Refer to ticket <ulink url="http://trac.osgeo.org/postgis/ticket/748">http://trac.osgeo.org/postgis/ticket/748</ulink> for an example issue solved by configuring with this.
			  NOTE: that you aren't missing much by turning this off.  This is used for international help/label support for the GUI loader which is not yet documented
			  and still experimental.
			</para>
		  </listitem>
		</varlistentry>
		<varlistentry>
		  <term><command>--with-sfcgal=PATH</command></term>
		  <listitem>
			<para>
			  By default PostGIS will not install with sfcgal support without this switch. 
			  <varname>PATH</varname> is an optional argument that allows to specify an alternate PATH to sfcgal-config.
			</para>
		  </listitem>
		</varlistentry>
	  </variablelist>
	  <note>
		<para>
		  If you obtained PostGIS from the SVN
		  <ulink url="http://svn.osgeo.org/postgis/trunk/">
			repository
		  </ulink>
		  , the first step is really to run the script
		</para>

		<para>
		  <command>./autogen.sh</command>
		</para>

		<para>
		  This script will generate the <command>configure</command> script that
		  in turn is used to customize the installation of PostGIS.
		</para>

		<para>
		  If you instead obtained PostGIS as a tarball, running
		  <command>./autogen.sh</command> is not necessary as
		  <command>configure</command> has already been generated.
		</para>
	  </note>
	</sect2>

	<sect2>
	  <title>Building</title>

	  <para>
		Once the Makefile has been generated, building PostGIS is as simple as
		running
	  </para>

	  <para>
		<command>make</command>
	  </para>

	  <para>
		The last line of the output should be "<code>PostGIS was built
		successfully. Ready to install.</code>"
	  </para>

	  <para>
		As of PostGIS v1.4.0, all the functions have comments generated from the
		documentation. If you wish to install these comments into your spatial
		databases later, run the command which requires docbook.  The postgis_comments.sql and other
		package comments files raster_comments.sql, topology_comments.sql are
			also packaged in the tar.gz distribution in the doc folder so no need to make comments
			if installing from the tar ball.
	  </para>

	  <para>
		<command>make comments</command>
	  </para>
	  
	  <para>
		Introduced in PostGIS 2.0. This generates html cheat sheets suitable for quick reference or for student handouts.
		This requires xsltproc to build and will generate 4 files in doc folder <filename>topology_cheatsheet.html</filename>, <filename>tiger_geocoder_cheatsheet.html</filename>, 
			<filename>raster_cheatsheet.html</filename>, <filename>postgis_cheatsheet.html</filename>
	  </para>
	  <para>You can download some pre-built ones available in html and pdf from <ulink url="http://www.postgis.us/study_guides">PostGIS / PostgreSQL Study Guides</ulink></para>

	  <para>
		<command>make cheatsheets</command>
	  </para>
	</sect2>
	
	<sect2 id="make_install_postgis_extensions">
	  <title>Building PostGIS Extensions and Deploying them</title>

	  <para>
		The PostGIS extensions are built and installed automatically if you are using PostgreSQL 9.1+. 
	  </para>
	  <para>If you are building from source repository, you need to build the function descriptions first. These get built if you have docbook installed. You can also manually build with the statement:
    </para>
	  <para>
	  <command>make comments</command>
    </para>
	  <para>Building the comments is not necessary if you are building from a release tar ball since these are packaged pre-built with the tar ball already.</para>
	  <para>If you are building against PostgreSQL 9.1, the extensions should automatically build as part of the make install process.  You can if needed build from the extensions
	  folders or copy files if you need them on a different server. </para>
	  <programlisting>cd extensions
cd postgis
make clean
make 
make install
cd ..
cd postgis_topology
make clean
make 
make install
	  </programlisting>
	  <para>The extension files will always be the same for the same version of PostGIS regardless of OS, so it is fine to copy over the extension files from one OS to another as long as you
	  have the PostGIS binaries already installed on your servers. </para>
		<para>If you want to install the extensions manually on a separate server different from your development,
		You need to copy the following files from the extensions folder into the <filename>PostgreSQL / share / extension</filename> folder
		of your PostgreSQL install as well as the needed binaries for regular PostGIS if you don't have them already on the server.
	  </para>

	  <itemizedlist>
		<listitem>
		  <para>
			These are the control files that denote information such as the version of the extension to install if not specified.
			<filename>postgis.control, postgis_topology.control</filename>.
		  </para>
		</listitem>
		<listitem>
		  <para>
			All the files in the /sql folder of each extension.  Note that these need to be copied to the root of the PostgreSQL share/extension folder
			<filename>extensions/postgis/sql/*.sql</filename>, <filename>extensions/postgis_topology/sql/*.sql</filename>
		  </para>
		</listitem>
	 </itemizedlist>
	 <para>Once you do that, you should see <varname>postgis</varname>, <varname>postgis_topology</varname> as available extensions in PgAdmin -> extensions.</para>
	 <para>If you are using psql, you can verify that the extensions are installed by running this query:</para>
	 <programlisting>SELECT name, default_version,installed_version 
FROM pg_available_extensions WHERE name LIKE 'postgis%' ;
      name       | default_version | installed_version
-----------------+-----------------+-------------------
postgis          | &last_release_version;     | &last_release_version;
postgis_topology | &last_release_version;      | </programlisting>

<para>If you have the extension installed in the database you are querying, you'll see mention in the <varname>installed_version</varname> column.  
If you get no records back, it means you don't have postgis extensions installed on the server at all.  PgAdmin III 1.14+ will also provide this information
in the <varname>extensions</varname> section of the database browser tree and will even allow upgrade or uninstall by right-clicking.</para>

<para>If you have the extensions available, you can install postgis extension in your database of choice by either using pgAdmin extension interface or running these sql commands:</para>
<programlisting>CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION postgis_tiger_geocoder;</programlisting>

<para>In psql you can use to see what versions you have installed and also what schema they are installed. </para>
<programlisting>\connect mygisdb
\x 
\dx postgis*</programlisting>

<screen>List of installed extensions
-[ RECORD 1 ]-------------------------------------------------
-
Name        | postgis
Version     | &last_release_version;
Schema      | public
Description | PostGIS geometry, geography, and raster spat..
-[ RECORD 2 ]-------------------------------------------------
-
Name        | postgis_tiger_geocoder
Version     | &last_release_version;
Schema      | tiger
Description | PostGIS tiger geocoder and reverse geocoder
-[ RECORD 3 ]-------------------------------------------------
-
Name        | postgis_topology
Version     | &last_release_version;
Schema      | topology
Description | PostGIS topology spatial types and functions</screen>

<warning><para>Extension tables <varname>spatial_ref_sys</varname>, <varname>layer</varname>, <varname>topology</varname> can not be explicitly backed up.  They can only 
be backed up when the respective <varname>postgis</varname> or <varname>postgis_topology</varname> extension is backed up, which only seems to happen when you backup the whole database. 
As of PostGIS 2.0.1, only srid records not packaged with PostGIS are backed up when the database is backed up so don't go around changing srids we package and expect your changes to be there. Put in a ticket if you find an issue.  The structures of extension tables are never backed up since they are created with <code>CREATE EXTENSION</code>
and assumed to be the same for a given version of an extension. These behaviors are built into the current PostgreSQL extension model, so nothing we can do about it.</para></warning>

<para>If you installed &last_release_version;, without using our wonderful extension system, you can change it to be extension based by first upgrading to the latest micro version running the upgrade scripts: <filename>postgis_upgrade_21_minor.sql</filename>,<filename>raster_upgrade_21_minor.sql</filename>,<filename>topology_upgrade_21_minor.sql</filename>.</para>
<para>If you installed postgis without raster support, you'll need to install raster support first (using the full <filename>rtpostgis.sql</filename></para>
<para>Then you can run the below commands to package the functions in their respective extension.</para>
<programlisting>CREATE EXTENSION postgis FROM unpackaged;
CREATE EXTENSION postgis_topology FROM unpackaged;
CREATE EXTENSION postgis_tiger_geocoder FROM unpackaged;</programlisting>

	</sect2>


	<sect2>
	  <title>Testing</title>

	  <para>
		If you wish to test the PostGIS build, run
	  </para>

	  <para>
		<command>make check</command>
	  </para>

	  <para>
		The above command will run through various checks and regression tests
		using the generated library against an actual PostgreSQL database.
	  </para>

	  <note>
		<para>
		  If you configured PostGIS using non-standard PostgreSQL, GEOS, or
		  Proj4 locations, you may need to add their library locations to the
		  LD_LIBRARY_PATH environment variable.
		</para>
	  </note>

	  <caution>
		<para>
		  Currently, the <command>make check</command> relies on the
		  <code>PATH</code> and <code>PGPORT</code> environment variables when
		  performing the checks - it does <emphasis>not</emphasis> use the
		  PostgreSQL version that may have been specified using the
		  configuration parameter <command>--with-pgconfig</command>. So make
		  sure to modify your PATH to match the detected PostgreSQL installation
		  during configuration or be prepared to deal with the impending
		  headaches.
		</para>
	  </caution>

	  <para>
		If successful, the output of the test should be similar to the
		following:
	  </para>

	  <programlisting>
     CUnit - A Unit testing framework for C - Version 2.1-0
     http://cunit.sourceforge.net/


Suite: print_suite
  Test: test_lwprint_default_format ... passed
  Test: test_lwprint_format_orders ... passed
  Test: test_lwprint_optional_format ... passed
  Test: test_lwprint_oddball_formats ... passed
  Test: test_lwprint_bad_formats ... passed
Suite: misc
  Test: test_misc_force_2d ... passed
  Test: test_misc_simplify ... passed
  Test: test_misc_count_vertices ... passed
  Test: test_misc_area ... passed
  Test: test_misc_wkb ... passed
Suite: ptarray
  Test: test_ptarray_append_point ... passed
  Test: test_ptarray_append_ptarray ... passed
  Test: test_ptarray_locate_point ... passed
  Test: test_ptarray_isccw ... passed
  Test: test_ptarray_signed_area ... passed
  Test: test_ptarray_desegmentize ... passed
  Test: test_ptarray_insert_point ... passed
  Test: test_ptarray_contains_point ... passed
  Test: test_ptarrayarc_contains_point ... passed
Suite: PostGIS Computational Geometry Suite
  Test: test_lw_segment_side ... passed
  Test: test_lw_segment_intersects ... passed
  Test: test_lwline_crossing_short_lines ... passed
  Test: test_lwline_crossing_long_lines ... passed
  Test: test_lwline_crossing_bugs ... passed
  Test: test_lwpoint_set_ordinate ... passed
  Test: test_lwpoint_get_ordinate ... passed
  Test: test_point_interpolate ... passed
  Test: test_lwline_clip ... passed
  Test: test_lwline_clip_big ... passed
  Test: test_lwmline_clip ... passed
  Test: test_geohash_point ... passed
  Test: test_geohash_precision ... passed
  Test: test_geohash ... passed
  Test: test_geohash_point_as_int ... passed
  Test: test_isclosed ... passed
Suite: buildarea
  Test: buildarea1 ... passed
  Test: buildarea2 ... passed
  Test: buildarea3 ... passed
  Test: buildarea4 ... passed
  Test: buildarea4b ... passed
  Test: buildarea5 ... passed
  Test: buildarea6 ... passed
  Test: buildarea7 ... passed
Suite: clean
  Test: test_lwgeom_make_valid ... passed
Suite: PostGIS Measures Suite
  Test: test_mindistance2d_tolerance ... passed
  Test: test_rect_tree_contains_point ... passed
  Test: test_rect_tree_intersects_tree ... passed
  Test: test_lwgeom_segmentize2d ... passed
  Test: test_lwgeom_locate_along ... passed
  Test: test_lw_dist2d_pt_arc ... passed
  Test: test_lw_dist2d_seg_arc ... passed
  Test: test_lw_dist2d_arc_arc ... passed
  Test: test_lw_arc_length ... passed
  Test: test_lw_dist2d_pt_ptarrayarc ... passed
  Test: test_lw_dist2d_ptarray_ptarrayarc ... passed
Suite: node
  Test: test_lwgeom_node ... passed
Suite: WKT Out Suite
  Test: test_wkt_out_point ... passed
  Test: test_wkt_out_linestring ... passed
  Test: test_wkt_out_polygon ... passed
  Test: test_wkt_out_multipoint ... passed
  Test: test_wkt_out_multilinestring ... passed
  Test: test_wkt_out_multipolygon ... passed
  Test: test_wkt_out_collection ... passed
  Test: test_wkt_out_circularstring ... passed
  Test: test_wkt_out_compoundcurve ... passed
  Test: test_wkt_out_curvpolygon ... passed
  Test: test_wkt_out_multicurve ... passed
  Test: test_wkt_out_multisurface ... passed
Suite: WKT In Suite
  Test: test_wkt_in_point ... passed
  Test: test_wkt_in_linestring ... passed
  Test: test_wkt_in_polygon ... passed
  Test: test_wkt_in_multipoint ... passed
  Test: test_wkt_in_multilinestring ... passed
  Test: test_wkt_in_multipolygon ... passed
  Test: test_wkt_in_collection ... passed
  Test: test_wkt_in_circularstring ... passed
  Test: test_wkt_in_compoundcurve ... passed
  Test: test_wkt_in_curvpolygon ... passed
  Test: test_wkt_in_multicurve ... passed
  Test: test_wkt_in_multisurface ... passed
  Test: test_wkt_in_tin ... passed
  Test: test_wkt_in_polyhedralsurface ... passed
  Test: test_wkt_in_errlocation ... passed
Suite: WKB Out Suite
  Test: test_wkb_out_point ... passed
  Test: test_wkb_out_linestring ... passed
  Test: test_wkb_out_polygon ... passed
  Test: test_wkb_out_multipoint ... passed
  Test: test_wkb_out_multilinestring ... passed
  Test: test_wkb_out_multipolygon ... passed
  Test: test_wkb_out_collection ... passed
  Test: test_wkb_out_circularstring ... passed
  Test: test_wkb_out_compoundcurve ... passed
  Test: test_wkb_out_curvpolygon ... passed
  Test: test_wkb_out_multicurve ... passed
  Test: test_wkb_out_multisurface ... passed
  Test: test_wkb_out_polyhedralsurface ... passed
:
Suite: Geodetic Suite
  Test: test_sphere_direction ... passed
  Test: test_sphere_project ... passed
  Test: test_lwgeom_area_sphere ... passed
  Test: test_signum ... passed
  Test: test_gbox_from_spherical_coordinates ... passed
:
  Test: test_geos_noop ... passed
Suite: Internal Spatial Trees
  Test: test_tree_circ_create ... passed
  Test: test_tree_circ_pip ... passed
  Test: test_tree_circ_pip2 ... passed
  Test: test_tree_circ_distance ... passed
Suite: triangulate
  Test: test_lwgeom_delaunay_triangulation ... passed
Suite: stringbuffer
  Test: test_stringbuffer_append ... passed
  Test: test_stringbuffer_aprintf ... passed
Suite: surface
  Test: triangle_parse ... passed
  Test: tin_parse ... passed
  Test: polyhedralsurface_parse ... passed
  Test: surface_dimension ... passed
Suite: homogenize
  Test: test_coll_point ... passed
  Test: test_coll_line ... passed
  Test: test_coll_poly ... passed
  Test: test_coll_coll ... passed
  Test: test_geom ... passed
  Test: test_coll_curve ... passed
Suite: force_sfs
  Test: test_sfs_11 ... passed
  Test: test_sfs_12 ... passed
  Test: test_sqlmm ... passed
Suite: out_gml
  Test: out_gml_test_precision ... passed
  Test: out_gml_test_srid ... passed
  Test: out_gml_test_dims ... passed
  Test: out_gml_test_geodetic ... passed
  Test: out_gml_test_geoms ... passed
  Test: out_gml_test_geoms_prefix ... passed
  Test: out_gml_test_geoms_nodims ... passed
  Test: out_gml2_extent ... passed
  Test: out_gml3_extent ... passed
Suite: KML Out Suite
  Test: out_kml_test_precision ... passed
  Test: out_kml_test_dims ... passed
  Test: out_kml_test_geoms ... passed
  Test: out_kml_test_prefix ... passed
Suite: GeoJson Out Suite
  Test: out_geojson_test_precision ... passed
  Test: out_geojson_test_dims ... passed
  Test: out_geojson_test_srid ... passed
  Test: out_geojson_test_bbox ... passed
  Test: out_geojson_test_geoms ... passed
Suite: SVG Out Suite
  Test: out_svg_test_precision ... passed
  Test: out_svg_test_dims ... passed
  Test: out_svg_test_relative ... passed
  Test: out_svg_test_geoms ... passed
  Test: out_svg_test_srid ... passed
Suite: X3D Out Suite
  Test: out_x3d3_test_precision ... passed
  Test: out_x3d3_test_geoms ... passed

--Run Summary: Type      Total     Ran  Passed  Failed
               suites       27      27     n/a       0
               tests       198     198     198       0
               asserts    1728    1728    1728       0

Creating database 'postgis_reg' 
Loading PostGIS into 'postgis_reg' 
PostgreSQL 9.3beta1 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.4.5-8) 4.4.5, 64-bit
  Postgis 2.1.0SVN - r11415 - 2013-05-11 02:48:21
  GEOS: 3.4.0dev-CAPI-1.8.0 r3797
  PROJ: Rel. 4.7.1, 23 September 2009

Running tests

 loader/Point .............. ok 
 loader/PointM .............. ok 
 loader/PointZ .............. ok 
 loader/MultiPoint .............. ok 
 loader/MultiPointM .............. ok 
 loader/MultiPointZ .............. ok 
 loader/Arc .............. ok 
 loader/ArcM .............. ok 
 loader/ArcZ .............. ok 
 loader/Polygon .............. ok 
 loader/PolygonM .............. ok 
 loader/PolygonZ .............. ok 
 loader/TSTPolygon ......... ok 
 loader/TSIPolygon ......... ok 
 loader/TSTIPolygon ......... ok 
 loader/PointWithSchema ..... ok 
 loader/NoTransPoint ......... ok 
 loader/NotReallyMultiPoint ......... ok 
 loader/MultiToSinglePoint ......... ok 
 loader/ReprojectPts ........ ok 
 loader/ReprojectPtsGeog ........ ok 
 loader/Latin1 .... ok 
 binary .. ok 
 regress .. ok 
 regress_index .. ok 
 regress_index_nulls .. ok 
 regress_selectivity .. ok 
 lwgeom_regress .. ok 
 regress_lrs .. ok 
 removepoint .. ok 
 setpoint .. ok 
 simplify .. ok 
 snaptogrid .. ok 
 summary .. ok 
 affine .. ok 
 empty .. ok 
 measures .. ok 
 legacy .. ok 
 long_xact .. ok 
 ctors .. ok 
 sql-mm-serialize .. ok 
 sql-mm-circularstring .. ok 
 sql-mm-compoundcurve .. ok 
 sql-mm-curvepoly .. ok 
 sql-mm-general .. ok 
 sql-mm-multicurve .. ok 
 sql-mm-multisurface .. ok 
 polyhedralsurface .. ok 
 polygonize .. ok 
 postgis_type_name .. ok 
 geography .. ok 
 out_geometry .. ok 
 out_geography .. ok 
 in_geohash .. ok 
 in_gml .. ok 
 in_kml .. ok 
 iscollection .. ok 
 regress_ogc .. ok 
 regress_ogc_cover .. ok 
 regress_ogc_prep .. ok 
 regress_bdpoly .. ok 
 regress_proj .. ok 
 regress_management .. ok 
 dump .. ok 
 dumppoints .. ok 
 boundary .. ok 
 wmsservers .. ok 
 wkt .. ok 
 wkb .. ok 
 tickets .. ok 
 typmod .. ok 
 remove_repeated_points .. ok 
 split .. ok 
 relate .. ok 
 bestsrid .. ok 
 concave_hull .. ok 
 hausdorff .. ok 
 regress_buffer_params .. ok 
 offsetcurve .. ok 
 relatematch .. ok 
 isvaliddetail .. ok 
 sharedpaths .. ok 
 snap .. ok 
 node .. ok 
 unaryunion .. ok 
 clean .. ok 
 relate_bnr .. ok 
 delaunaytriangles .. ok 
 in_geojson .. ok 
 uninstall .. ok (4112)

Run tests: 90</programlisting>
	</sect2>

	<sect2>
	  <title>Installation</title>

	  <para>
		To install PostGIS, type
	  </para>

	  <para>
		<command>make install</command>
	  </para>

	  <para>
		This will copy the PostGIS installation files into their appropriate
		subdirectory specified by the <command>--prefix</command> configuration
		parameter. In particular:
	  </para>

	  <itemizedlist>
		<listitem>
		  <para>
			The loader and dumper binaries are installed in
			<filename>[prefix]/bin</filename>.
		  </para>
		</listitem>

		<listitem>
		  <para>
			The SQL files, such as <filename>postgis.sql</filename>, are
			installed in <filename>[prefix]/share/contrib</filename>.
		  </para>
		</listitem>

		<listitem>
		  <para>
			The PostGIS libraries are installed in
			<filename>[prefix]/lib</filename>.
		  </para>
		</listitem>
	  </itemizedlist>

	  <para>
		If you previously ran the <command>make comments</command> command to
		generate the <filename>postgis_comments.sql</filename>, <filename>raster_comments.sql</filename> file, install the
		sql file by running
	  </para>

	  <para>
		<command>make comments-install</command>
	  </para>

	  <note>
		<para>
		  <filename>postgis_comments.sql</filename>, <filename>raster_comments.sql</filename>, <filename>topology_comments.sql</filename> was separated from the
		  typical build and installation targets since with it comes the extra
		  dependency of <command>xsltproc</command>.
		</para>
	  </note>
	</sect2>
  </sect1>

  <sect1 id="create_new_db">
	<title>Create a spatially-enabled database on PostgreSQL lower than 9.1</title>

	<para>
	  The first step in creating a PostGIS database is to create a simple
	  PostgreSQL database.
	</para>

	<para>
	  <command>createdb [yourdatabase]</command>
	</para>

	<para>
	  Many of the PostGIS functions are written in the PL/pgSQL procedural
	  language. As such, the next step to create a PostGIS database is to enable
	  the PL/pgSQL language in your new database. This is accomplish by the
	  command below command.  For PostgreSQL 8.4+, this is generally already installed
	</para>

	<para>
	  <command>createlang plpgsql [yourdatabase]</command>
	</para>

	<para>
	  Now load the PostGIS object and function definitions into your database by
	  loading the <filename>postgis.sql</filename> definitions file (located in
	  <filename>[prefix]/share/contrib</filename> as specified during the
	  configuration step).
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f postgis.sql</command>
	</para>

	<para>
	  For a complete set of EPSG coordinate system definition identifiers, you
	  can also load the <filename>spatial_ref_sys.sql</filename> definitions
	  file and populate the <varname>spatial_ref_sys</varname> table. This will
	  permit you to perform ST_Transform() operations on geometries.
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f spatial_ref_sys.sql</command>
	</para>

	<para>
	  If you wish to add comments to the PostGIS functions, the final step is to
	  load the <filename>postgis_comments.sql</filename> into your spatial
	  database. The comments can be viewed by simply typing <command>\dd
	  [function_name]</command> from a <command>psql</command> terminal window.
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f postgis_comments.sql</command>
	</para>
	
	<para>
	  Install raster support
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f rtpostgis.sql</command>
	</para>
	
	<para>
	  Install raster support comments.  This will provide quick help info for each raster function
	  using psql or PgAdmin or any other PostgreSQL tool that can show function comments
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f raster_comments.sql</command>
	</para>
	<para>
	  Install topology support
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f topology/topology.sql</command>
	</para>
	
	<para>
	  Install topology support comments.  This will provide quick help info for each topology function / type
	  using psql or PgAdmin or any other PostgreSQL tool that can show function comments
	</para>

	<para>
	  <command>psql -d [yourdatabase] -f topology/topology_comments.sql</command>
	</para>
	
	<para>If you plan to restore an old backup from prior versions in this new db, run:</para>
	<para><command>psql -d [yourdatabase] -f legacy.sql</command></para>
	<note><para>There is an alternative <filename>legacy_minimal.sql</filename> you can run instead which will install barebones needed to recover tables and work with apps like MapServer
	and GeoServer. If you have views that use things like distance / length etc, you'll need the full blown <filename>legacy.sql</filename></para></note>
	
	<para>You can later run <filename>uninstall_legacy.sql</filename> to get rid of the deprecated functions after you are done with restoring and cleanup.</para>
  </sect1>
  
  <sect1 id="create_new_db_extensions">
	<title>Creating a spatial database using EXTENSIONS</title>

	<para>
	 If you are using PostgreSQL 9.1+ and have compiled and installed the extensions/ postgis modules, you 
	 can create a spatial database the new way.
	</para>

	<para>
	  <command>createdb [yourdatabase]</command>
	</para>

	<para>
	  The core postgis extension installs PostGIS geometry, geography, raster, spatial_ref_sys and all the functions and comments with a simple:
	  <programlisting>CREATE EXTENSION postgis;</programlisting> command.
	</para>

	<para>
	  <command>psql -d [yourdatabase] -c "CREATE EXTENSION postgis;"</command>
	</para>

	<para>
	  Topology is packaged as a separate extension and installable with command:
	</para>

	<para>
	  <command>psql -d [yourdatabase] -c "CREATE EXTENSION postgis_topology;"</command>
	</para>
	
	<para>If you plan to restore an old backup from prior versions in this new db, run:</para>
	<para><command>psql -d [yourdatabase] -f legacy.sql</command></para>
	
	<para>You can later run <filename>uninstall_legacy.sql</filename> to get rid of the deprecated functions after you are done with restoring and cleanup.</para>
  </sect1>
  
  <sect1 id="loading_extras_tiger_geocoder">
  	<title>Installing, Upgrading Tiger Geocoder and loading data</title>
  	
	<para>Extras like Tiger geocoder may not be packaged in your PostGIS distribution, but will always be available in the postgis-&last_release_version;.tar.gz file. The instructions provided here are also available in the <filename>extras/tiger_geocoder/tiger_2011/README</filename> </para>
	<para>If you are on Windows and you don't have tar installed, you can use <ulink url="http://www.7-zip.org/">http://www.7-zip.org/</ulink> to unzip the PostGIS tarball.</para>
	<sect2 id="install_tiger_geocoder_extension">
		<title>Tiger Geocoder Enabling your PostGIS database: Using Extension</title>	
		<para>If you are using PostgreSQL 9.1+ and PostGIS 2.1.0+, you can take advantage of the new extension model for installing tiger geocoder. To do so:</para>
		<orderedlist>
			<listitem><para>First get binaries for PostGIS 2.1.0 or compile and install as usual.  This should install the necessary extension files as well for tiger geocoder.</para></listitem>
			<listitem><para>Connect to your database via psql or pgAdmin or some other tool and run the following SQL commands.  Note that if you are installing in a database that already has postgis, you don't need to do the first step.  If you have <varname>fuzzystrmatch</varname> extension already installed, you don't need to do the second step either.</para>
			<para><programlisting>CREATE EXTENSION postgis;		
CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION postgis_tiger_geocoder;</programlisting></para></listitem>
			<listitem><para>To confirm your install is working correctly, run this sql in your database:</para>
				<programlisting>SELECT na.address, na.streetname,na.streettypeabbrev, na.zip
	FROM normalize_address('1 Devonshire Place, Boston, MA 02109') AS na;</programlisting>
				<para>Which should output</para>
				<para><screen> address | streetname | streettypeabbrev |  zip
---------+------------+------------------+-------
	   1 | Devonshire | Pl               | 02109</screen></para>
			</listitem>
			<listitem><para>Create a new record in <varname>tiger.loader_platform</varname> table with the paths of your executables and server. </para>  
				<para>So for example to create a profile called debbie that follows <code>sh</code> convention. You would do:</para>
				<programlisting>INSERT INTO tiger.loader_platform(os, declare_sect, pgbin, wget, unzip_command, psql, path_sep, 
		   loader, environ_set_command, county_process_command)
SELECT 'debbie', declare_sect, pgbin, wget, unzip_command, psql, path_sep, 
	   loader, environ_set_command, county_process_command
  FROM tiger.loader_platform
  WHERE os = 'sh';</programlisting>
				<para>And then edit the paths in the <emphasis>declare_sect</emphasis> column to those that fit Debbie's pg, unzip,shp2pgsql, psql, etc path locations.</para>
			
				<para>If you don't edit this  <varname>loader_platform</varname> table, it will just contain common case locations of items and you'll have to edit the generated script after the script is generated.</para>
			</listitem>
			<listitem><para>Then run the  <xref linkend="Loader_Generate_Nation_Script" /> and <xref linkend="Loader_Generate_Script" />  SQL functions make sure to use the name of your custom profile.  So for example to do the nation load using our new profile we would:</para>
					<programlisting>SELECT Loader_Generate_Nation_Script('debbie');</programlisting>
			</listitem>
		</orderedlist>
		<sect3 id="convert_tiger_geocoder_extension"><title>Converting a Tiger Geocoder Regular Install to Extension Model</title>
			<para>If you installed the tiger geocoder without using the extension model, you can convert to the extension model as follows:</para>
			<orderedlist>
				<listitem><para>Follow instructions in <xref linkend="upgrade_tiger_geocoder" /> for the non-extension model upgrade.</para></listitem>
				<listitem><para>Connect to your database with psql or pgAdmin and run the following command:</para>
					<programlisting>CREATE EXTENSION postgis_tiger_geocoder FROM unpackaged;</programlisting>
				</listitem>
			</orderedlist>
		</sect3>
		
		<sect3 id="installing_pagc_address_standardizer"><title>Using PAGC address standardizer</title>
			<para>One of the many complaints of folks is the address normalizer function <xref linkend="Normalize_Address" /> function that normalizes an address for prepping before geocoding.  The normalizer is far from perfect and trying to patch its imperfectness takes a vast amount of resources.  As such we have integrated with another
			project that has a much better address standardizer engine.  This is currently a separate project, which is a subproject of PAGC.  The source code for this PostgreSQL standardizer extension can be downloaded from <ulink url="http://sourceforge.net/p/pagc/code/360/tree/branches/sew-refactor/postgresql">PAGC PostgreSQL Address Standardizer</ulink>.  To use this new normalizer, you compile the pagc extension and install as an extension in your database.</para>
			<para>The PAGC project and standardizer portion in particular, relies on PCRE which is usually already installed on most Nix systems, 
but you can download the latest at: <ulink url="http://www.pcre.org">http://www.pcre.org</ulink>. It also requires Perl with the <code>Regexp::Assemble</code> installed </para>
			<para>For Windows users, the PostGIS 2.1+ bundle will come packaged with the address_standardizer already so no need to compile and can move straight to <code>CREATE EXTENSION</code> step.</para>
			<para>Installing Regex::Assemble</para>
			<programlisting>cpan Regexp::Assemble</programlisting>
			<para>or if you are on Ubuntu / Debian you might need to do</para>
			<programlisting>sudo perl -MCPAN -e "install Regexp::Assemble"</programlisting>
			<para>Compiling</para>
			<programlisting>svn co svn://svn.code.sf.net/p/pagc/code/branches/sew-refactor/postgresql address_standardizer
cd address_standardizer
make
#if you have in non-standard location pcre try
# make SHLIB_LINK="-L/path/pcre/lib -lpostgres -lpgport -lpcre" CPPFLAGS="-I.  -I/path/pcre/include" 
make install</programlisting>

      <para>Once you have installed, you can connect to your database and run the SQL:</para>
			<programlisting>CREATE EXTENSION address_standardizer;</programlisting>
			
			<para>Once you install this extension in the same database as you have installed <code>postgis_tiger_geocoder</code>, then the <xref linkend="Pagc_Normalize_Address" /> can be used instead of <xref linkend="Normalize_Address" />. The other nice thing about this extension is that its tiger agnostic, so can be used with other data sources such as international addresses.</para>

		</sect3>
	</sect2>
	<sect2 id="install_tiger_geocoder">
		<title>Tiger Geocoder Enabling your PostGIS database: Not Using Extensions</title>
		<para>
		  First install PostGIS using the prior instructions.
		</para>
	
		<para>
		  If you don't have an extras folder, download <ulink url="&postgis_download_url;">&postgis_download_url;</ulink>
		</para>
	
		<para>
		  <command>tar xvfz postgis-&last_release_version;.tar.gz</command>
		</para>
	
		<para>
		  <command>cd postgis-&last_release_version;/extras/tiger_geocoder/tiger_2011</command>
		</para>
	
		<para>Edit the <filename>tiger_loader_2012.sql</filename> to the paths of your executables server etc or alternatively you can update the <varname>loader_platform</varname> table once installed. If you don't edit this file or the <varname>loader_platform</varname> table, it will just contain common case locations of items and you'll have to edit the generated script after the fact when you run the  <xref linkend="Loader_Generate_Nation_Script" /> and <xref linkend="Loader_Generate_Script" />  SQL functions.
		 </para>
		<para>If you are installing Tiger geocoder for the first time edit either the <filename>create_geocode.bat</filename> script If you are on windows
			or the <filename>create_geocode.sh</filename> if you are on Linux/Unix/Mac OSX with your PostgreSQL specific settings and run the corresponding script from the commandline. </para>
			
		
		<para>Verify that you now have a <varname>tiger</varname> schema in your database and that it is part of your database search_path.  If it is not, add it with a command something along the line of: <programlisting>ALTER DATABASE geocoder SET search_path=public, tiger;</programlisting></para>
		<para>The normalizing address functionality works more or less without any data except for tricky addresses.  Run this test and verify things look like this: 
			<programlisting>SELECT pprint_addy(normalize_address('202 East Fremont Street, Las Vegas, Nevada 89101')) As pretty_address;
pretty_address
---------------------------------------
202 E Fremont St, Las Vegas, NV 89101
			</programlisting>
		</para>
	</sect2>
	<sect2 id="tiger_geocoder_loading_data">
		<title>Loading Tiger Data</title>
		<para>The instructions for loading data are available in a more detailed form  in the <filename>extras/tiger_geocoder/tiger_2011/README</filename>.  This just includes the general steps.</para>	
		<para>The load process downloads data from the census website for the respective nation files, states requested, extracts the files, and then loads each state into its own separate
		set of state tables.  Each state table inherits from the tables defined in <varname>tiger</varname> schema so that its sufficient to just query those tables to access all the data and drop a set of state tables at any time using the <xref linkend="Drop_State_Tables_Generate_Script" /> if you need to reload a state or just don't need a state anymore.</para>
		<para>In order to be able to load data you'll need the following tools:</para>
		<itemizedlist>
			<listitem><para>A tool to unzip the zip files from census website.</para>
			  <para>For Unix like systems: <varname>unzip</varname> executable which is usually already installed on most Unix like platforms.</para>
			  <para>For Windows, 7-zip which is a free compress/uncompress tool you can download from <ulink url="http://www.7-zip.org/">http://www.7-zip.org/</ulink> </para>
			</listitem>
			<listitem><para><filename>shp2pgsql</filename> commandline which is installed by default when you install PostGIS.</para></listitem>
			<listitem><para><filename>wget</filename> which is a web grabber tool usually installed on most Unix/Linux systems.</para>
				<para>If you are on windows, you can get pre-compiled binaries from <ulink url="http://gnuwin32.sourceforge.net/packages/wget.htm">http://gnuwin32.sourceforge.net/packages/wget.htm</ulink> </para>
			</listitem>
		</itemizedlist>
		<para>If you are upgrading from tiger_2010, you'll need to first generate and run <xref linkend="Drop_Nation_Tables_Generate_Script" />. Before you load any state data, you need to load the nation wide data which you do with  <xref linkend="Loader_Generate_Nation_Script" />. Which will
		generate a loader script for you.   <xref linkend="Loader_Generate_Nation_Script" /> is a one-time step that should be done for upgrading (from 2010) and for new installs.</para>
		<para>To load state data refer to <xref linkend="Loader_Generate_Script" /> to generate a data load script for your platform for the states you desire.  
			Note that you can install these piecemeal. You don't have to load all the states you want all at once.  You can load them as you need them.</para>
			
		<para>After the states you desire have been loaded, make sure to run the:
		<programlisting>SELECT install_missing_indexes();</programlisting> as described in  <xref linkend="Install_Missing_Indexes" />.</para>
		<para>To test that things are working as they should, try to run a geocode on an address in your state using <xref linkend="Geocode" /> </para>
	</sect2>
	<sect2 id="upgrade_tiger_geocoder">
		<title>Upgrading your Tiger Geocoder Install</title>
		<para>
		  If you have Tiger Geocoder packaged with 2.0+ already installed, you can upgrade the functions at any time even from an interim tar ball if there are fixes you badly need.  This will only work for Tiger geocoder not installed with extensions. 
		</para>
	
		<para>
		  If you don't have an extras folder, download <ulink url="&postgis_download_url;">&postgis_download_url;</ulink>
		</para>
	
		<para>
		  <command>tar xvfz postgis-&last_release_version;.tar.gz</command>
		</para>
	
		<para>
		  <command>cd postgis-&last_release_version;/extras/tiger_geocoder/tiger_2011</command>
		</para>
	
		<para>Locate the  <filename>upgrade_geocoder.bat</filename> script If you are on windows
			or the <filename>upgrade_geocoder.sh</filename> if you are on Linux/Unix/Mac OSX.  Edit the file to have your postgis database credentials.</para>
			
		<para>If you are upgrading from 2010 or 2011, make sure to unremark out the loader script line so you get the latest script for loading 2012 data.</para>
		<para>	
			Then run th corresponding script from the commandline.
		</para>
		
		<para>Next drop all nation tables and load up the new ones. Generate a drop script with this SQL statement as detailed in <xref linkend="Drop_Nation_Tables_Generate_Script" /></para>
			<programlisting>SELECT drop_nation_tables_generate_script();</programlisting>
		<para>Run the generated drop SQL statements.</para>
		<para>Generate a nation load script with this SELECT statement as detailed in <xref linkend="Loader_Generate_Nation_Script" /></para>
		<para><emphasis role="bold">For windows</emphasis></para>
		<programlisting>SELECT loader_generate_nation_script('windows'); </programlisting>
		<para><emphasis role="bold">For unix/linux</emphasis></para>
		<programlisting>SELECT loader_generate_nation_script('sh');</programlisting>
		<para>Refer to <xref linkend="tiger_geocoder_loading_data" /> for instructions on how to run the generate script. This only needs to be done once.</para>
		<note><para>You can have a mix of 2010/2011 state tables and can upgrade each state separately.  Before you upgrade a state to 2011, you first need to drop the 2010 tables for that state using <xref linkend="Drop_State_Tables_Generate_Script" />.</para></note>
	</sect2>
	
  </sect1>

  <sect1 id="templatepostgis">
	<title>Create a spatially-enabled database from a template</title>

	<para>
	  Some packaged distributions of PostGIS (in particular the Win32 installers
	  for PostGIS &gt;= 1.1.5) load the PostGIS functions into a template
	  database called <varname>template_postgis</varname>. If the
	  <varname>template_postgis</varname> database exists in your PostgreSQL
	  installation then it is possible for users and/or applications to create
	  spatially-enabled databases using a single command. Note that in both
	  cases, the database user must have been granted the privilege to create
	  new databases.
	</para>

	<para>
	  From the shell:
	</para>

	<programlisting># createdb -T template_postgis my_spatial_db</programlisting>

	<para>
	  From SQL:
	</para>

	<programlisting>postgres=# CREATE DATABASE my_spatial_db TEMPLATE=template_postgis</programlisting>
  </sect1>

  <sect1 id="upgrading">
	<title>Upgrading</title>

	<para>
	  Upgrading existing spatial databases can be tricky as it requires
	  replacement or introduction of new PostGIS object definitions.
	</para>

	<para>
	  Unfortunately not all definitions can be easily replaced in a live
	  database, so sometimes your best bet is a dump/reload process.
	</para>

	<para>
	  PostGIS provides a SOFT UPGRADE procedure for minor or bugfix releases,
	  and a HARD UPGRADE procedure for major releases.
	</para>

	<para>
	  Before attempting to upgrade PostGIS, it is always worth to backup your
	  data. If you use the -Fc flag to pg_dump you will always be able to
	  restore the dump with a HARD UPGRADE.
	</para>

	<sect2 id="soft_upgrade">
	  <title>Soft upgrade</title>

	  <para>If you installed your database using extensions, you'll need to upgrade using the extension model as well.  If you installed using the old sql script way,
	  then you should upgrade using the sql script way. Please refer to the appropriate.</para>
	  
	  <sect3 id="soft_upgrade_sql_script"><title>Soft Upgrade Pre 9.1+ or without extensions</title>
	  <para>This section applies only to those who installed PostGIS not using extensions.  If you have extensions and try to upgrade with this approach you'll get messages like:</para>
	  <programlisting>can't drop ... because postgis extension depends on it</programlisting>
	  <para>
		After compiling you should find several <filename>postgis_upgrade*.sql</filename> files.  Install the one
		for your version of PostGIS.  For example <filename>postgis_upgrade_20_to_21.sql</filename> should be used if you are upgrading 
		from PostGIS 2.0 to 2.1.  If you are moving from PostGIS 1.* to PostGIS 2.* or from PostGIS 2.* prior to r7409, you need to do a HARD UPGRADE.
	  </para>

	  <programlisting>psql -f postgis_upgrade_21_minor.sql -d your_spatial_database</programlisting>

	  <para>
		The same procedure applies to raster and
		topology extensions, with upgrade files named
		<filename>rtpostgis_upgrade*.sql</filename> and
		<filename>topology_upgrade*.sql</filename> respectively.
		If you need them:
	  </para>

	  <programlisting>psql -f rtpostgis_upgrade_21_minor.sql -d your_spatial_database</programlisting>
	  <programlisting>psql -f topology_upgrade_21_minor.sql -d your_spatial_database</programlisting>

	  <note>
		<para>
		  If you can't find the <filename>postgis_upgrade*.sql</filename> specific for upgrading your version you are using a version too early for
		  a soft upgrade and need to do a HARD UPGRADE.
		</para>
	  </note>

	  <para>
		The <xref linkend="PostGIS_Full_Version" /> function
		should inform you about the need to run this kind of
		upgrade using a "procs need upgrade" message.
	  </para>
	  </sect3>
	  
	<sect3 id="soft_upgrade_extensions"><title>Soft Upgrade 9.1+ using extensions</title>
		<para>If you originally installed PostGIS with extensions, then you need to upgrade using extensions as well.  Doing a minor upgrade with extensions, is fairly painless.</para>
		<programlisting>ALTER EXTENSION postgis UPDATE TO "&last_release_version;";
ALTER EXTENSION postgis_topology UPDATE TO "&last_release_version;";</programlisting>
		<para>If you get an error notice something like:</para>
			<programlisting>No migration path defined for ... to &last_release_version;</programlisting>
		<para>Then you'll need to backup your database, create a fresh one as described in <xref linkend="create_new_db_extensions" /> and then restore your backup ontop of this new database.</para>
    <para>If you get a notice message like:</para>
    <programlisting>Version "&last_release_version;" of extension "postgis" is already installed</programlisting>
    <para>
Then everything is already up to date and you can safely ignore it. <emphasis role="bold">UNLESS</emphasis>
you're attempting to upgrade from an SVN version to the next (which
doesn't get a new version number); in that case you can append "next" to the version
string, and next time you'll need to drop the "next" suffix again:
    </para>
		<programlisting>ALTER EXTENSION postgis UPDATE TO "&last_release_version;next";
ALTER EXTENSION postgis_topology UPDATE TO "&last_release_version;next";</programlisting>
		<note><para>If you installed PostGIS originally without a version specified, you can often skip the reinstallation of postgis extension before restoring since the backup just has <code>CREATE EXTENSION postgis</code> and thus
		picks up the newest latest version during restore.</para></note>
	</sect3>

	</sect2>

	<sect2 id="hard_upgrade">
	  <title>Hard upgrade</title>

	  <para>
		By HARD UPGRADE we mean full dump/reload of postgis-enabled databases.
		You need a HARD UPGRADE when PostGIS objects' internal storage changes
		or when SOFT UPGRADE is not possible. The
		<link linkend="release_notes">Release Notes</link>
		appendix reports for each version whether you need a dump/reload (HARD
		UPGRADE) to upgrade.
	  </para>

	  <para>
		The dump/reload process is assisted by the postgis_restore.pl
		script which takes care of skipping from the dump all
		definitions which belong to PostGIS (including old ones),
		allowing you to restore your schemas and data into a
		database with PostGIS installed without getting duplicate
		symbol errors or bringing forward deprecated objects.
	  </para>
	  
	 <para>Supplementary instructions for windows users are available at  <ulink url="http://trac.osgeo.org/postgis/wiki/UsersWikiWinUpgrade">Windows Hard upgrade</ulink>.</para>


	  <para>
		The Procedure is as follows:
	  </para>

	<orderedlist>

	<listitem>

	  <para>
		Create a "custom-format" dump of the database you want
		to upgrade (let's call it <varname>olddb</varname>)
		include binary blobs (-b) and verbose (-v) output.
		The user can be the owner of the db, need not be postgres
		super account.
	  </para>

	  <programlisting>pg_dump -h localhost -p 5432 -U postgres -Fc -b -v -f "/somepath/olddb.backup" olddb</programlisting>

	</listitem>

	<listitem>

	  <para>
		Do a fresh install of PostGIS in a new database -- we'll
		refer to this database as <varname>newdb</varname>.
		Please refer to <xref linkend="create_new_db" /> and <xref linkend="create_new_db_extensions" /> for
		instructions on how to do this.
	  </para>

	  <para>
		The spatial_ref_sys entries found in your dump will be
		restored, but they will not override existing ones in
		spatial_ref_sys.  This is to ensure that fixes in the
		official set will be properly propagated to restored
		databases. If for any reason you really want your own
		overrides of standard entries just don't load the
		spatial_ref_sys.sql file when creating the new db.
	  </para>

	  <para>
		If your database is really old or you know you've
		been using long deprecated functions in your
		views and functions, you might need to load
		<filename>legacy.sql</filename> for all your functions
		and views etc. to properly come back.
		Only do this if _really_ needed. Consider upgrading your
		views and functions before dumping instead, if possible.
		The deprecated functions can be later removed by loading
		<filename>uninstall_legacy.sql</filename>.
	  </para>

	</listitem>
	  
	<listitem>

	  <para>
		Restore your backup into your fresh
		<varname>newdb</varname> database using
		postgis_restore.pl.
		Unexpected errors, if any, will be printed to the standard
		error stream by psql. Keep a log of those.
	  </para>

	  <programlisting>perl utils/postgis_restore.pl "/somepath/olddb.backup" | psql -h localhost -p 5432 -U postgres newdb 2> errors.txt</programlisting>

	</listitem>

	</orderedlist>

	<para>
		Errors may arise in the following cases:
	</para>

	<orderedlist>
	<listitem>
	<para>
		Some of your views or functions make use of deprecated PostGIS objects.
		In order to fix this you may try loading <filename>legacy.sql</filename>
		script prior to restore or you'll have to restore to a
		version of PostGIS which still contains those objects
		and try a migration again after porting your code.
		If the <filename>legacy.sql</filename> way works for you, don't forget
		to fix your code to stop using deprecated functions and drop them
		loading <filename>uninstall_legacy.sql</filename>.
	</para>
	</listitem>
	<listitem>
	<para>
		Some custom records of spatial_ref_sys in dump file have
		an invalid SRID value. Valid SRID values are bigger than 0
		and smaller than 999000. Values in the 999000.999999 range
    are reserved for internal use while values > 999999 can't
    be used at all.
    All your custom records with invalid SRIDs will be retained,
    with those > 999999 moved into the reserved range, but the
    spatial_ref_sys table would loose a check constraint guarding
    for that invariant to hold and possibly also its primary key
    ( when multiple invalid SRIDS get converted to the same reserved
    SRID value ).
  </para>

  <para>
		In order to fix this you should copy your custom SRS to
		a SRID with a valid value (maybe in the 910000..910999
		range), convert all your tables to the new srid (see
		<xref linkend="UpdateGeometrySRID"/>), delete the invalid
		entry from spatial_ref_sys and re-construct the check(s) with:

		<programlisting>ALTER TABLE spatial_ref_sys ADD CONSTRAINT spatial_ref_sys_srid_check check (srid &gt; 0 AND srid &lt; 999000 );</programlisting>

		<programlisting>ALTER TABLE spatial_ref_sys ADD PRIMARY KEY(srid));</programlisting>
	
	</para>
	</listitem>
	</orderedlist>


	</sect2>
  </sect1>

  <sect1>
	<title>Common Problems during installation</title>
	<para>
	  There are several things to check when your installation or upgrade
	  doesn't go as you expected.
	</para>

	<orderedlist>
	  <listitem>
		<para>
		  Check that you have installed PostgreSQL &min_postgres_version;
		  or newer, and that you are compiling against the same version of the
		  PostgreSQL source as the version of PostgreSQL that is running.
		  Mix-ups can occur when your (Linux) distribution has already
		  installed PostgreSQL, or you have otherwise installed PostgreSQL
		  before and forgotten about it. PostGIS will only work with PostgreSQL
		  &min_postgres_version; or newer, and strange, unexpected
		  error messages will result if you use an older version. To check the
		  version of PostgreSQL which is running, connect to the database using
		  psql and run this query:
		</para>

		<programlisting>SELECT version();</programlisting>

		<para>
		  If you are running an RPM based distribution, you can check for the
		  existence of pre-installed packages using the <command>rpm</command>
		  command as follows: <command>rpm -qa | grep postgresql</command>
		</para>
	  </listitem>
	  
	  <listitem>
	  	<para>If your upgrade fails, make sure you are restoring into a database that already has PostGIS installed.</para>
	  	<programlisting>SELECT postgis_full_version();</programlisting>
	  </listitem>
	</orderedlist>

	<para>
	  Also check that configure has correctly detected the location and version
	  of PostgreSQL, the Proj4 library and the GEOS library.
	</para>

	<orderedlist>
	  <listitem>
		<para>
		  The output from configure is used to generate the
		  <filename>postgis_config.h</filename> file. Check that the
		  <varname>POSTGIS_PGSQL_VERSION</varname>,
		  <varname>POSTGIS_PROJ_VERSION</varname> and
		  <varname>POSTGIS_GEOS_VERSION</varname> variables have been set
		  correctly.
		</para>
	  </listitem>
	</orderedlist>
  </sect1>

  <sect1>
	<title>JDBC</title>

	<para>
	  The JDBC extensions provide Java objects corresponding to the internal
	  PostGIS types. These objects can be used to write Java clients which query
	  the PostGIS database and draw or do calculations on the GIS data in
	  PostGIS.
	</para>

	<orderedlist>
	  <listitem>
		<para>
		  Enter the <filename>java/jdbc</filename> sub-directory of the PostGIS
		  distribution.
		</para>
	  </listitem>

	  <listitem>
		<para>
		  Run the <filename>ant</filename> command. Copy the
		  <filename>postgis.jar</filename> file to wherever you keep your java
		  libraries.
		</para>
	  </listitem>
	</orderedlist>

	<para>
	  The JDBC extensions require a PostgreSQL JDBC driver to be present in the
	  current CLASSPATH during the build process. If the PostgreSQL JDBC driver
	  is located elsewhere, you may pass the location of the JDBC driver JAR
	  separately using the -D parameter like this:
	</para>

	<programlisting># ant -Dclasspath=/path/to/postgresql-jdbc.jar</programlisting>

	<para>
	  PostgreSQL JDBC drivers can be downloaded from
	  <ulink url="http://jdbc.postgresql.org">
		http://jdbc.postgresql.org
	  </ulink>
	  .
	</para>
  </sect1>

  <sect1>
	<title>Loader/Dumper</title>

	<para>
	  The data loader and dumper are built and installed automatically as part
	  of the PostGIS build. To build and install them manually:
	</para>

	<programlisting># cd postgis-&last_release_version;/loader
# make
# make install</programlisting>

	<para>
	  The loader is called <filename>shp2pgsql</filename> and converts ESRI
	  Shape files into SQL suitable for loading in PostGIS/PostgreSQL. The
	  dumper is called <filename>pgsql2shp</filename> and converts PostGIS
	  tables (or queries) into ESRI Shape files. For more verbose documentation,
	  see the online help, and the manual pages.
	</para>
  </sect1>
</chapter>