]> granicus.if.org Git - postgresql/blob - doc/src/FAQ/FAQ.html
Add index mention:
[postgresql] / doc / src / FAQ / FAQ.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML>
3   <HEAD>
4     <META name="generator" content="HTML Tidy, see www.w3.org">
5     <META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
6     <TITLE>PostgreSQL FAQ</TITLE>
7   </HEAD>
8
9   <BODY bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000"
10   alink="#0000ff">
11     <H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
12
13     <P>Last updated: Tue Aug 31 23:28:02 EDT 2004</P>
14
15     <P>Current maintainer: Bruce Momjian (<A href=
16     "mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
17     </P>
18
19     <P>The most recent version of this document can be viewed at <A href=
20     "http://www.PostgreSQL.org/docs/faqs/FAQ.html">http://www.PostgreSQL.org/docs/faqs/FAQ.html</A>.</P>
21
22     <P>Platform-specific questions are answered at <A href=
23     "http://www.PostgreSQL.org/docs/index.html">http://www.PostgreSQL.org/docs/index.html</A>.</P>
24     <HR>
25
26     <H2 align="center">General Questions</H2>
27     <A href="#1.1">1.1</A>) What is PostgreSQL? How is it pronounced?<BR>
28      <A href="#1.2">1.2</A>) What is the copyright on PostgreSQL?<BR>
29      <A href="#1.3">1.3</A>) What Unix platforms does PostgreSQL run
30     on?<BR>
31      <A href="#1.4">1.4</A>) What non-Unix ports are available?<BR>
32      <A href="#1.5">1.5</A>) Where can I get PostgreSQL?<BR>
33      <A href="#1.6">1.6</A>) Where can I get support?<BR>
34      <A href="#1.7">1.7</A>) What is the latest release?<BR>
35      <A href="#1.8">1.8</A>) What documentation is available?<BR>
36      <A href="#1.9">1.9</A>) How do I find out about known bugs or
37     missing features?<BR>
38      <A href="#1.10">1.10</A>) How can I learn <SMALL>SQL</SMALL>?<BR>
39      <A href="#1.11">1.11</A>) Is PostgreSQL Y2K compliant?<BR>
40      <A href="#1.12">1.12</A>) How do I join the development team?<BR>
41      <A href="#1.13">1.13</A>) How do I submit a bug report?<BR>
42      <A href="#1.14">1.14</A>) How does PostgreSQL compare to other
43     <SMALL>DBMS</SMALL>s?<BR>
44      <A href="#1.15">1.15</A>) How can I financially assist
45     PostgreSQL?<BR>
46      
47
48     <H2 align="center">User Client Questions</H2>
49     <A href="#2.1">2.1</A>) Are there <SMALL>ODBC</SMALL> drivers for
50     PostgreSQL?<BR>
51      <A href="#2.2">2.2</A>) What tools are available for using
52     PostgreSQL with Web pages?<BR>
53      <A href="#2.3">2.3</A>) Does PostgreSQL have a graphical user
54     interface?<BR>
55      <A href="#2.4">2.4</A>) What languages are available to
56     communicate with PostgreSQL?<BR>
57      
58
59     <H2 align="center">Administrative Questions</H2>
60     <A href="#3.1">3.1</A>) How do I install PostgreSQL somewhere other
61     than <I>/usr/local/pgsql</I>?<BR>
62      <A href="#3.2">3.2</A>) When I start <I>postmaster</I>, I get a
63     <I>Bad System Call</I> or core dumped message. Why?<BR>
64      <A href="#3.3">3.3</A>) When I try to start <I>postmaster</I>, I
65     get <I>IpcMemoryCreate</I> errors. Why?<BR>
66      <A href="#3.4">3.4</A>) When I try to start <I>postmaster</I>, I
67     get <I>IpcSemaphoreCreate</I> errors. Why?<BR>
68      <A href="#3.5">3.5</A>) How do I control connections from other
69     hosts?<BR>
70      <A href="#3.6">3.6</A>) How do I tune the database engine for
71     better performance?<BR>
72      <A href="#3.7">3.7</A>) What debugging features are available?<BR>
73      <A href="#3.8">3.8</A>) Why do I get <I>"Sorry, too many
74     clients"</I> when trying to connect?<BR>
75      <A href="#3.9">3.9</A>) What is in the  <I>pgsql_tmp</I>
76     directory?<BR>
77      <A href="#3.10">3.10</A>) Why do I need to do a dump and restore
78     to upgrade PostgreSQL releases?<BR>
79      <A href="#3.11">3.11</A>) What computer hardware should I use?<BR>
80
81
82     <H2 align="center">Operational Questions</H2>
83     <A href="#4.1">4.1</A>) What is the difference between binary
84     cursors and normal cursors?<BR>
85      <A href="#4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
86     first few rows of a query?  A random row?<BR>
87      <A href="#4.3">4.3</A>) How do I get a list of tables or other
88     things I can see in <I>psql</I>?<BR>
89      <A href="#4.4">4.4</A>) How do you remove a column from a
90     table, or change it's data type?<BR>
91      <A href="#4.5">4.5</A>) What is the maximum size for a row, a
92     table, and a database?<BR>
93      <A href="#4.6">4.6</A>) How much database disk space is required
94     to store data from a typical text file?<BR>
95      <A href="#4.7">4.7</A>) How do I find out what tables, indexes,
96     databases, and users are defined?<BR>
97      <A href="#4.8">4.8</A>) My queries are slow or don't make use of
98     the indexes. Why?<BR>
99      <A href="#4.9">4.9</A>) How do I see how the query optimizer is
100     evaluating my query?<BR>
101      <A href="#4.10">4.10</A>) What is an R-tree index?<BR>
102      <A href="#4.11">4.11</A>) What is the Genetic Query Optimizer?<BR>
103      <A href="#4.12">4.12</A>) How do I perform regular expression
104     searches and case-insensitive regular expression searches? How do I
105     use an index for case-insensitive searches?<BR>
106      <A href="#4.13">4.13</A>) In a query, how do I detect if a field
107     is <SMALL>NULL</SMALL>?<BR>
108      <A href="#4.14">4.14</A>) What is the difference between the
109     various character types?<BR>
110      <A href="#4.15.1">4.15.1</A>) How do I create a
111     serial/auto-incrementing field?<BR>
112      <A href="#4.15.2">4.15.2</A>) How do I get the value of a
113     <SMALL>SERIAL</SMALL> insert?<BR>
114      <A href="#4.15.3">4.15.3</A>) Don't <I>currval()</I> and
115     <I>nextval()</I> lead to a race condition with other users?<BR>
116      <A href="#4.15.4">4.15.4</A>) Why aren't my sequence numbers
117     reused on transaction abort? Why are there gaps in the numbering of
118     my sequence/SERIAL column?<BR>
119      <A href="#4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is a
120     <SMALL>TID</SMALL>?<BR>
121      <A href="#4.17">4.17</A>) What is the meaning of some of the terms
122     used in PostgreSQL?<BR>
123      <A href="#4.18">4.18</A>) Why do I get the error <I>"ERROR: Memory
124     exhausted in AllocSetAlloc()"</I>?<BR>
125      <A href="#4.19">4.19</A>) How do I tell what PostgreSQL version I
126     am running?<BR>
127      <A href="#4.20">4.20</A>) Why does my large-object operations get
128     <I>"invalid large obj descriptor"</I>?<BR>
129      <A href="#4.21">4.21</A>) How do I create a column that will
130     default to the current time?<BR>
131      <A href="#4.22">4.22</A>) Why are my subqueries using
132     <CODE><SMALL>IN</SMALL></CODE> so slow?<BR>
133      <A href="#4.23">4.23</A>) How do I perform an outer join?<BR>
134      <A href="#4.24">4.24</A>) How do I perform queries using multiple
135     databases?<BR>
136      <A href="#4.25">4.25</A>) How do I return multiple rows or columns
137     from a function?<BR>
138      <A href="#4.26">4.26</A>) Why can't I reliably create/drop
139     temporary tables in PL/PgSQL functions?<BR>
140      <A href="#4.27">4.27</A>) What replication options are available?<BR>
141      <A href="#4.28">4.28</A>) What encryption options are available?<BR>
142      
143
144     <H2 align="center">Extending PostgreSQL</H2>
145     <A href="#5.1">5.1</A>) I wrote a user-defined function. When I run
146     it in <I>psql</I>, why does it dump core?<BR>
147      <A href="#5.2">5.2</A>) How can I contribute some nifty new types
148     and functions to PostgreSQL?<BR>
149      <A href="#5.3">5.3</A>) How do I write a C function to return a
150     tuple?<BR>
151      <A href="#5.4">5.4</A>) I have changed a source file. Why does the
152     recompile not see the change?<BR>
153      
154     <HR>
155
156     <H2 align="center">General Questions</H2>
157
158     <H4><A name="1.1">1.1</A>) What is PostgreSQL? How is it pronounced?</H4>
159
160     <P>PostgreSQL is pronounced <I>Post-Gres-Q-L</I>.  An audio file is 
161        available at http://www.postgresql.org/postgresql.mp3 for those 
162        would like to hear the pronunciation. 
163     </P>
164
165     <P>PostgreSQL is an enhancement of the POSTGRES database management
166     system (and is still sometimes reffered to as simply "Postgres"), 
167     a next-generation <SMALL>DBMS</SMALL> research prototype.
168     While PostgreSQL retains the powerful data model and rich data
169     types of POSTGRES, it replaces the PostQuel query language with an
170     extended subset of <SMALL>SQL</SMALL>. PostgreSQL is free and the
171     complete source is available.</P>
172
173     <P>PostgreSQL development is performed by a team of
174     developers who all subscribe to the PostgreSQL development mailing
175     list. The current coordinator is Marc G. Fournier (<A href=
176     "mailto:scrappy@PostgreSQL.org">scrappy@PostgreSQL.org</A>). (See
177     section <a href="#1.6">1.6</a> on how to join). This team is now
178     responsible for all development of PostgreSQL.  It is a community
179     project and is not controlled by any company.  To get involved, see
180     the developer's FAQ at <A href=
181     "http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html">http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html</A>
182     </P>
183
184     <P>The authors of PostgreSQL 1.01 were Andrew Yu and Jolly Chen.
185     Many others have contributed to the porting, testing, debugging,
186     and enhancement of the code. The original Postgres code, from which
187     PostgreSQL is derived, was the effort of many graduate students,
188     undergraduate students, and staff programmers working under the
189     direction of Professor Michael Stonebraker at the University of
190     California, Berkeley.</P>
191
192     <P>The original name of the software at Berkeley was Postgres. When
193     <SMALL>SQL</SMALL> functionality was added in 1995, its name was
194     changed to Postgres95. The name was changed at the end of 1996 to
195     PostgreSQL.</P>
196
197     <H4><A name="1.2">1.2</A>) What is the copyright on
198     PostgreSQL?</H4>
199
200     <P>PostgreSQL is subject to the following COPYRIGHT:</P>
201
202     <P>PostgreSQL Data Base Management System</P>
203
204     <P>Portions copyright (c) 1996-2004, PostgreSQL Global Development
205     Group Portions Copyright (c) 1994-6 Regents of the University of
206     California</P>
207
208     <P>Permission to use, copy, modify, and distribute this software
209     and its documentation for any purpose, without fee, and without a
210     written agreement is hereby granted, provided that the above
211     copyright notice and this paragraph and the following two
212     paragraphs appear in all copies.</P>
213
214     <P>IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
215     PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
216     DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
217     SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
218     CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</P>
219
220     <P>THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
221     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
222     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
223     SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
224     UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
225     SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.</P>
226
227     <P>The above is the BSD license, the classic open-source license.
228     It has no restrictions on how the source code may be used. We like
229     it and have no intention of changing it.</P>
230
231     <H4><A name="1.3">1.3</A>) What Unix platforms does PostgreSQL run
232     on?</H4>
233
234     <P>In general, any modern Unix-compatible platform should be able to
235     run PostgreSQL. The platforms that had received explicit testing at
236     the time of release are listed in the installation
237     instructions.</P>
238
239     <H4><A name="1.4">1.4</A>) What non-Unix ports are available?</H4>
240
241     <P>Starting with version 8.0, PostgreSQL now runs natively on
242     Microsoft Windows NT-based operating systems like Win2000, WinXP,
243     and Win2003.  A prepackaged installer is available at <a href=
244     "http://pgfoundry.org/projects/pginstaller">
245     http://pgfoundry.org/projects/pginstaller</a>.
246
247     <p>There is also a Novell Netware 6 port at
248     <a href="http://forge.novell.com">http://forge.novell.com</a>.</p>
249
250     <H4><A name="1.5">1.5</A>) Where can I get PostgreSQL?</H4>
251
252     <P>The primary anonymous ftp site for PostgreSQL is <A href=
253     "ftp://ftp.PostgreSQL.org/pub">ftp://ftp.PostgreSQL.org/pub</A>.
254     For mirror sites, see our main web site.</P>
255
256     <H4><A name="1.6">1.6</A>) Where can I get support?</H4>
257
258     <P>The main mailing list is: <A href=
259     "mailto:pgsql-general@PostgreSQL.org">pgsql-general@PostgreSQL.org</A>.
260     It is available for discussion of matters pertaining to PostgreSQL.
261     To subscribe, send mail with the following lines in the body (not
262     the subject line):</P>
263 <PRE>
264     subscribe
265     end
266 </PRE>
267
268     <P>to <A href=
269     "mailto:pgsql-general-request@PostgreSQL.org">pgsql-general-request@PostgreSQL.org</A>.</P>
270
271     <P>There is also a digest list available. To subscribe to this
272     list, send email to: <A href=
273     "mailto:pgsql-general-digest-request@PostgreSQL.org">pgsql-general-digest-request@PostgreSQL.org</A>
274     with a body of:</P>
275 <PRE>
276     subscribe
277     end
278 </PRE>
279
280     Digests are sent out to members of this list whenever the main list
281     has received around 30k of messages. 
282
283     <P>The bugs mailing list is available. To subscribe to this list,
284     send email to <A href=
285     "mailto:pgsql-bugs-request@PostgreSQL.org">pgsql-bugs-request@PostgreSQL.org</A>
286     with a body of:</P>
287 <PRE>
288     subscribe
289     end
290 </PRE>
291
292     There is also a developers discussion mailing list available. To
293     subscribe to this list, send email to <A href=
294     "mailto:pgsql-hackers-request@PostgreSQL.org">pgsql-hackers-request@PostgreSQL.org</A>
295     with a body of: 
296 <PRE>
297     subscribe
298     end
299 </PRE>
300
301     <P>Additional mailing lists and information about PostgreSQL can be
302     found via the PostgreSQL WWW home page at:</P>
303
304     <BLOCKQUOTE>
305       <A href="http://www.PostgreSQL.org">http://www.PostgreSQL.org</A>
306     </BLOCKQUOTE>
307
308     <P>There is also an IRC channel on Freenode and EFNet,
309     channel <I>#PostgreSQL</I>. You can use the Unix command <CODE>irc -c
310     '#PostgreSQL' "$USER" irc.phoenix.net.</CODE> or <CODE>irc -c
311     '#PostgreSQL' "$USER" irc.freenode.net.</CODE></P>
312
313     <P>A list of commercial support companies is available at <A href=
314     "http://techdocs.postgresql.org/companies.php">http://techdocs.postgresql.org/companies.php</A>.</P>
315
316     <H4><A name="1.7">1.7</A>) What is the latest release?</H4>
317
318     <P>The latest release of PostgreSQL is version 7.4.5.</P>
319
320     <P>We plan to have major releases every six to eight months.</P>
321
322     <H4><A name="1.8">1.8</A>) What documentation is available?</H4>
323
324     <P>Several manuals, manual pages, and some small test examples are
325     included in the distribution. See the <I>/doc</I> directory. You
326     can also browse the manuals online at <A href=
327     "http://www.PostgreSQL.org/docs">http://www.PostgreSQL.org/docs</A>.</P>
328
329     <P>There are two PostgreSQL books available online at <A href=
330     "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
331     and <A href=
332     "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook/</A>.
333     There is a list of PostgreSQL books available for purchase at <A
334     href=
335     "http://techdocs.postgresql.org/techdocs/bookreviews.php">http://techdocs.PostgreSQL.org/techdocs/bookreviews.php</A>.
336     There is also a collection of PostgreSQL technical articles at <A
337     href=
338     "http://techdocs.PostgreSQL.org/">http://techdocs.PostgreSQL.org/</A>.</P>
339
340     <P><I>psql</I> has some nice \d commands to show information about
341     types, operators, functions, aggregates, etc.</P>
342
343     <P>Our web site contains even more documentation.</P>
344
345     <H4><A name="1.9">1.9</A>) How do I find out about known bugs or
346     missing features?</H4>
347
348     <P>PostgreSQL supports an extended subset of <SMALL>SQL</SMALL>-92.
349     See our <A href="http://developer.PostgreSQL.org/todo.php">TODO</A>
350     list for known bugs, missing features, and future plans.</P>
351
352     <H4><A name="1.10">1.10</A>) How can I learn
353     <SMALL>SQL</SMALL>?</H4>
354
355     <P>The PostgreSQL book at <A href=
356     "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
357     teaches <SMALL>SQL</SMALL>. There is another PostgreSQL book at <A
358     href=
359     "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook.</A>
360     There is a nice tutorial at <A href=
361     "http://www.intermedia.net/support/sql/sqltut.shtm">http://www.intermedia.net/support/sql/sqltut.shtm,</A>
362     at <A href=
363     "http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM">
364     http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM,</A>
365     and at <A href=
366     "http://sqlcourse.com/">http://sqlcourse.com.</A></P>
367
368     <P>Another one is "Teach Yourself SQL in 21 Days, Second Edition"
369     at <A href=
370     "http://members.tripod.com/er4ebus/sql/index.htm">http://members.tripod.com/er4ebus/sql/index.htm</A></P>
371
372     <P>Many of our users like <I>The Practical SQL Handbook</I>,
373     Bowman, Judith S., et al., Addison-Wesley. Others like <I>The
374     Complete Reference SQL</I>, Groff et al., McGraw-Hill.</P>
375
376     <H4><A name="1.11">1.11</A>) Is PostgreSQL Y2K compliant?</H4>
377
378     <P>Yes, we easily handle dates past the year 2000 AD, and before
379     2000 BC.</P>
380
381     <H4><A name="1.12">1.12</A>) How do I join the development
382     team?</H4>
383
384     <P>First, download the latest source and read the PostgreSQL
385     Developers documentation on our web site, or in the distribution.
386     Second, subscribe to the <I>pgsql-hackers</I> and
387     <I>pgsql-patches</I> mailing lists. Third, submit high quality
388     patches to pgsql-patches.</P>
389
390     <P>There are about a dozen people who have commit privileges to the
391     PostgreSQL <SMALL>CVS</SMALL> archive. They each have submitted so
392     many high-quality patches that it was impossible for the existing
393     committers to keep up, and we had confidence that patches they
394     committed were of high quality.</P>
395
396     <H4><A name="1.13">1.13</A>) How do I submit a bug report?</H4>
397
398     <P>Please visit the PostgreSQL BugTool page at <A href=
399     "http://www.PostgreSQL.org/bugs/bugs.php">http://www.PostgreSQL.org/bugs/bugs.php</A>,
400     which gives guidelines and directions on how to submit a
401     bug report.</P>
402
403     <P>Also check out our ftp site <A href=
404     "ftp://ftp.PostgreSQL.org/pub">ftp://ftp.PostgreSQL.org/pub</A> to
405     see if there is a more recent PostgreSQL version or patches.</P>
406
407     <H4><A name="1.14">1.14</A>) How does PostgreSQL compare to other
408     <SMALL>DBMS</SMALL>s?</H4>
409
410     <P>There are several ways of measuring software: features,
411     performance, reliability, support, and price.</P>
412
413     <DL>
414       <DT><B>Features</B></DT>
415
416       <DD>PostgreSQL has most features present in large commercial
417       <SMALL>DBMS</SMALL>s, like transactions, subselects, triggers,
418       views, foreign key referential integrity, and sophisticated
419       locking. We have some features they do not have, like
420       user-defined types, inheritance, rules, and multi-version
421       concurrency control to reduce lock contention.<BR>
422       <BR>
423       </DD>
424
425       <DT><B>Performance</B></DT>
426
427       <DD>PostgreSQL has performance similar to other commercial and
428       open source databases. it is faster for some things, slower for
429       others. In comparison to MySQL or leaner database systems, we are
430       faster for multiple users, complex queries, and a read/write query
431       load.  MySQL is faster for simple SELECT queries done by a few users.
432       Of course, MySQL does not have most of the features mentioned in the
433       <I>Features</I> section above. We are built for reliability and
434       features, and we continue to improve performance in every
435       release. There is an interesting Web page comparing PostgreSQL to
436       MySQL at <A href="http://openacs.org/philosophy/why-not-mysql.html">
437       http://openacs.org/philosophy/why-not-mysql.html</A>  Also, MySQL is
438       is a company that distributes its products via open source, and requires
439       a commercial license for close-source software, not an
440       open source development community like PostgreSQL.<BR>
441
442       <BR>
443       </DD>
444
445       <DT><B>Reliability</B></DT>
446
447       <DD>We realize that a <SMALL>DBMS</SMALL> must be reliable, or it
448       is worthless. We strive to release well-tested, stable code that
449       has a minimum of bugs. Each release has at least one month of
450       beta testing, and our release history shows that we can provide
451       stable, solid releases that are ready for production use. We
452       believe we compare favorably to other database software in this
453       area.<BR>
454       <BR>
455       </DD>
456
457       <DT><B>Support</B></DT>
458
459       <DD>Our mailing lists provide contact with a large group of developers
460       and users to help resolve any problems encountered. While we cannot
461       guarantee a fix, commercial <SMALL>DBMS</SMALL>s do not always
462       supply a fix either. Direct access to developers, the user
463       community, manuals, and the source code often make PostgreSQL
464       support superior to other <SMALL>DBMS</SMALL>s. There is
465       commercial per-incident support available for those who need it.
466       (See <A href="#1.6">FAQ section 1.6</A>.)<BR>
467       <BR>
468       </DD>
469
470       <DT><B>Price</B></DT>
471
472       <DD>We are free for all use, both commercial and non-commercial.
473       You can add our code to your product with no limitations, except
474       those outlined in our BSD-style license stated above.<BR>
475       <BR>
476       </DD>
477     </DL>
478
479     <H4><A name="1.15">1.15</A>) How can I financially assist
480     PostgreSQL?</H4>
481
482     <P>PostgreSQL has had a first-class infrastructure since we started
483     in 1996. This is all thanks to Marc Fournier, who has created
484     and managed this infrastructure over the years.</P>
485
486     <P>Quality infrastructure is very important to an open-source
487     project. It prevents disruptions that can greatly delay forward
488     movement of the project.</P>
489
490     <P>Of course, this infrastructure is not cheap. There are a variety
491     of monthly and one-time expenses that are required to keep it
492     going. If you or your company has money it can donate to help fund
493     this effort, please go to <A href="http://store.pgsql.com/shopping/">http://store.pgsql.com/shopping/</A>
494     and make a donation.</P>
495
496     <P>Although the web page mentions PostgreSQL, Inc, the
497     "contributions" item is solely to support the PostgreSQL project
498     and does not fund any specific company. If you prefer, you can also
499     send a check to the contact address.</P>
500     <HR>
501
502     <P>Also, if you have a success story about PostgreSQL, please submit
503     it to our advocacy site at <a href="http://advocacy.postgresql.org">
504     http://advocacy.postgresql.org</a>.</P>
505
506
507     <H2 align="center">User Client Questions</H2>
508
509     <H4><A name="2.1">2.1</A>) Are there <SMALL>ODBC</SMALL> drivers
510     for PostgreSQL?</H4>
511
512     <P>There are two <SMALL>ODBC</SMALL> drivers available, PsqlODBC
513     and OpenLink <SMALL>ODBC</SMALL>.</P>
514
515     <P>You can download PsqlODBC from <A href=
516     "http://gborg.postgresql.org/project/psqlodbc/projdisplay.php">
517     http://gborg.postgresql.org/project/psqlodbc/projdisplay.php</A>.</P>
518
519     <P>OpenLink <SMALL>ODBC</SMALL> can be gotten from <A href=
520     "http://www.openlinksw.com/">http://www.openlinksw.com</A>. It
521     works with their standard <SMALL>ODBC</SMALL> client software so
522     you'll have PostgreSQL <SMALL>ODBC</SMALL> available on every
523     client platform they support (Win, Mac, Unix, VMS).</P>
524
525     <P>They will probably be selling this product to people who need
526     commercial-quality support, but a freeware version will always be
527     available. Please send questions to <A href=
528     "mailto:postgres95@openlink.co.uk">postgres95@openlink.co.uk</A>.</P>
529
530     <H4><A name="2.2">2.2</A>) What tools are available for using
531     PostgreSQL with Web pages?</H4>
532
533     <P>A nice introduction to Database-backed Web pages can be seen at:
534     <A href="http://www.webreview.com">http://www.webreview.com</A></P>
535
536     <P>For Web integration, PHP is an excellent interface. It is at <A
537     href="http://www.php.net">http://www.php.net</A>.</P>
538
539     <P>For complex cases, many use the Perl interface and CGI.pm or mod_perl.</P>
540
541     <H4><A name="2.3">2.3</A>) Does PostgreSQL have a graphical user
542     interface?</H4>
543
544     <P>Yes, there are several graphical interfaces to PostgreSQL available.
545     These include PgAccess <a href="http://www.pgaccess.org">
546     http://www.pgaccess.org</a>), PgAdmin III (<a
547     href="http://www.pgadmin.org">http://www.pgadmin.org</a>, RHDB Admin (<a
548     href="http://sources.redhat.com/rhdb/">http://sources.redhat.com/rhdb/
549     </a>) and Rekall (<a href="http://www.thekompany.com/products/rekall/">
550     http://www.thekompany.com/products/rekall/</a>, proprietary). There is 
551     also PhpPgAdmin (<a href="http://phppgadmin.sourceforge.net/">
552     http://phppgadmin.sourceforge.net/ </a>), a web-based interface to 
553     PostgreSQL.</P>
554
555     <P>See <a href="http://techdocs.postgresql.org/guides/GUITools">http://techdocs.postgresql.org/guides/GUITools</a> for a more detailed list.</P>
556
557     <H4><A name="2.4">2.4</A>) What languages are able to communicate with 
558     PostgreSQL?</H4>
559
560     <P>Most popular programming languages contain an interface to
561     PostgreSQL. Check your programming language's list of extension
562     modules.</P>
563
564     <P>The following interfaces are included in the PostgreSQL
565     distribution:</P>
566
567     <UL>
568       <LI>C (libpq)</LI>
569
570       <LI>Embedded C (ecpg)</LI>
571
572       <LI>Java (jdbc)</LI>
573
574       <LI>Python (PyGreSQL)</LI>
575
576       <LI>TCL (libpgtcl)</LI>
577
578     </UL>
579     <P>Additional interfaces are available at 
580     <a href="http://gborg.postgresql.org">http://gborg.postgresql.org</A>
581     in the <I>Drivers/Interfaces</I> section.
582     </P>
583     <HR>
584
585     <H2 align="center">Administrative Questions</H2>
586
587     <H4><A name="3.1">3.1</A>) How do I install PostgreSQL somewhere
588     other than <I>/usr/local/pgsql</I>?</H4>
589
590     <P>Specify the <I>--prefix</I> option when running
591     <I>configure</I>.</P>
592
593     <H4><A name="3.2">3.2</A>) When I start <I>postmaster</I>, I get a
594     <I>Bad System Call</I> or core dumped message. Why?</H4>
595
596     <P>It could be a variety of problems, but first check to see that
597     you have System V extensions installed in your kernel. PostgreSQL
598     requires kernel support for shared memory and semaphores.</P>
599
600     <H4><A name="3.3">3.3</A>) When I try to start <I>postmaster</I>, I
601     get <I>IpcMemoryCreate</I> errors. Why?</H4>
602
603     <P>You either do not have shared memory configured properly in your
604     kernel or you need to enlarge the shared memory available in the
605     kernel. The exact amount you need depends on your architecture and
606     how many buffers and backend processes you configure for
607     <I>postmaster</I>. For most systems, with default numbers of
608     buffers and processes, you need a minimum of ~1 MB. See the <A
609     href=
610     "http://www.PostgreSQL.org/docs/view.php?version=current&amp;idoc=1&amp;file=kernel-resources.html">PostgreSQL
611     Administrator's Guide</A> for more detailed information about
612     shared memory and semaphores.</P>
613
614     <H4><A name="3.4">3.4</A>) When I try to start <I>postmaster</I>, I
615     get <I>IpcSemaphoreCreate</I> errors. Why?</H4>
616
617     <P>If the error message is <I>IpcSemaphoreCreate: semget failed (No
618     space left on device)</I> then your kernel is not configured with
619     enough semaphores. Postgres needs one semaphore per potential
620     backend process. A temporary solution is to start <I>postmaster</I>
621     with a smaller limit on the number of backend processes. Use
622     <I>-N</I> with a parameter less than the default of 32. A more
623     permanent solution is to increase your kernel's
624     <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI</SMALL> parameters.</P>
625
626     <P>Inoperative semaphores can also cause crashes during heavy
627     database access.</P>
628
629     <P>If the error message is something else, you might not have
630     semaphore support configured in your kernel at all. See the
631     PostgreSQL Administrator's Guide for more detailed information
632     about shared memory and semaphores.</P>
633
634     <H4><A name="3.5">3.5</A>) How do I control connections from other
635     hosts?</H4>
636
637     <P>By default, PostgreSQL only allows connections from the local
638     machine using Unix domain sockets or TCP/IP connections. Other
639     machines will not be able to connect unless you modify
640     listen_addresses in the postgresql.conf <B>and</B> enable
641     host-based authentication by modifying the file
642     <I>$PGDATA/pg_hba.conf</I> accordingly.</P>
643
644     <H4><A name="3.6">3.6</A>) How do I tune the database engine for
645     better performance?</H4>
646
647     <P>Certainly, indexes can speed up queries. The
648     <SMALL>EXPLAIN ANALYZE</SMALL> command allows you to see how PostgreSQL is
649     interpreting your query, and which indexes are being used.</P>
650
651     <P>If you are doing many <SMALL>INSERTs</SMALL>, consider doing
652     them in a large batch using the <SMALL>COPY</SMALL> command. This
653     is much faster than individual <SMALL>INSERTS</SMALL>. Second,
654     statements not in a <SMALL>BEGIN WORK/COMMIT</SMALL> transaction
655     block are considered to be in their own transaction. Consider
656     performing several statements in a single transaction block. This
657     reduces the transaction overhead. Also, consider dropping and
658     recreating indexes when making large data changes.</P>
659
660     <P>There are several tuning options. You can disable <I>fsync()</I>
661     by starting <I>postmaster</I> with a <I>-o -F</I> option. This will
662     prevent <I>fsync()</I>s from flushing to disk after every
663     transaction.</P>
664
665     <P>You can also use the <I>postmaster</I> <I>-B</I> option to
666     increase the number of shared memory buffers used by the backend
667     processes. If you make this parameter too high, the
668     <I>postmaster</I> may not start because you have exceeded your
669     kernel's limit on shared memory space. Each buffer is 8K and the
670     default is 64 buffers.</P>
671
672     <P>You can also use the backend <I>-S</I> option to increase the
673     maximum amount of memory used by the backend process for temporary
674     sorts. The <I>-S</I> value is measured in kilobytes, and the
675     default is 512 (i.e. 512K).</P>
676
677     <P>You can also use the <SMALL>CLUSTER</SMALL> command to group
678     data in tables to match an index. See the <SMALL>CLUSTER</SMALL>
679     manual page for more details.</P>
680
681     <H4><A name="3.7">3.7</A>) What debugging features are
682     available?</H4>
683
684     <P>PostgreSQL has several features that report status information
685     that can be valuable for debugging purposes.</P>
686
687     <P>First, by running <I>configure</I> with the --enable-cassert
688     option, many <I>assert()</I>s monitor the progress of the backend
689     and halt the program when something unexpected occurs.</P>
690
691     <P>Both <I>postmaster</I> and <I>postgres</I> have several debug
692     options available. First, whenever you start <I>postmaster</I>,
693     make sure you send the standard output and error to a log file,
694     like:</P>
695 <PRE>
696     cd /usr/local/pgsql
697     ./bin/postmaster &gt;server.log 2&gt;&amp;1 &amp;
698 </PRE>
699
700     <P>This will put a server.log file in the top-level PostgreSQL
701     directory. This file contains useful information about problems or
702     errors encountered by the server. <I>Postmaster</I> has a <I>-d</I>
703     option that allows even more detailed information to be reported.
704     The <I>-d</I> option takes a number that specifies the debug level.
705     Be warned that high debug level values generate large log
706     files.</P>
707
708     <P>If <I>postmaster</I> is not running, you can actually run the
709     <I>postgres</I> backend from the command line, and type your
710     <SMALL>SQL</SMALL> statement directly. This is recommended
711     <B>only</B> for debugging purposes. Note that a newline terminates
712     the query, not a semicolon. If you have compiled with debugging
713     symbols, you can use a debugger to see what is happening. Because
714     the backend was not started from <I>postmaster</I>, it is not
715     running in an identical environment and locking/backend interaction
716     problems may not be duplicated.</P>
717
718     <P>If <I>postmaster</I> is running, start <I>psql</I> in one
719     window, then find the <SMALL>PID</SMALL> of the <I>postgres</I>
720     process used by <I>psql</I>. Use a debugger to attach to the
721     <I>postgres</I> <SMALL>PID</SMALL>. You can set breakpoints in the
722     debugger and issue queries from <I>psql</I>. If you are debugging
723     <I>postgres</I> startup, you can set PGOPTIONS="-W n", then start
724     <I>psql</I>. This will cause startup to delay for <I>n</I> seconds
725     so you can attach to the process with the debugger, set any
726     breakpoints, and continue through the startup sequence.</P>
727
728     <P>The <I>postgres</I> program has <I>-s, -A</I>, and <I>-t</I>
729     options that can be very useful for debugging and performance
730     measurements.</P>
731
732     <P>You can also compile with profiling to see what functions are
733     taking execution time. The backend profile files will be deposited
734     in the <I>pgsql/data/base/dbname</I> directory. The client profile
735     file will be put in the client's current directory. Linux requires
736     a compile with <I>-DLINUX_PROFILE</I> for proper profiling.</P>
737
738     <H4><A name="3.8">3.8</A>) Why do I get <I>"Sorry, too many
739     clients"</I> when trying to connect?</H4>
740
741     <P>You need to increase <I>postmaster</I>'s limit on how many
742     concurrent backend processes it can start.</P>
743
744     <P>The default limit is 32 processes. You can increase it by
745     restarting <I>postmaster</I> with a suitable <I>-N</I> value or
746     modifying <I>postgresql.conf</I>.</P>
747
748     <P>Note that if you make <I>-N</I> larger than 32, you must also
749     increase <I>-B</I> beyond its default of 64; <I>-B</I> must be at
750     least twice <I>-N</I>, and probably should be more than that for
751     best performance. For large numbers of backend processes, you are
752     also likely to find that you need to increase various Unix kernel
753     configuration parameters. Things to check include the maximum size
754     of shared memory blocks, <SMALL>SHMMAX;</SMALL> the maximum number
755     of semaphores, <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI;</SMALL> the
756     maximum number of processes, <SMALL>NPROC;</SMALL> the maximum
757     number of processes per user, <SMALL>MAXUPRC;</SMALL> and the
758     maximum number of open files, <SMALL>NFILE</SMALL> and
759     <SMALL>NINODE</SMALL>. The reason that PostgreSQL has a limit on
760     the number of allowed backend processes is so your system won't run
761     out of resources.</P>
762
763     <H4><A name="3.9">3.9</A>) What is in the <I>pgsql_tmp</I> directory?</H4>
764
765     <P>This directory contains temporary files generated by the query 
766     executor. For example, if a sort needs to be done to satisfy an 
767     <SMALL>ORDER BY</SMALL> and the sort requires more space than the
768     backend's <I>-S</I> parameter allows, then temporary files are created
769     here to hold the extra data.</P>
770
771     <P>The temporary files are usually deleted automatically, but might
772     remain if a backend crashes during a sort. A stop and restart of the
773     <I>postmaster</I> will remove files from those directories.</P>
774
775     <H4><A name="3.10">3.10</A>) Why do I need to do a dump and restore
776     to upgrade between major PostgreSQL releases?</H4>
777
778     <P>The PostgreSQL team makes only small changes between minor releases,
779     so upgrading from 7.2 to 7.2.1 does not require a dump and restore.
780     However, major releases (e.g. from 7.2 to 7.3) often change the internal
781     format of system tables and data files. These changes are often complex,
782     so we don't maintain backward compatability for data files. A dump outputs
783     data in a generic format that can then be loaded in using the new internal
784     format.</P>
785
786     <P>In releases where the on-disk format does not change, the
787     <I>pg_upgrade</I> script can be used to upgrade without a dump/restore.
788     The release notes mention whether <I>pg_upgrade</I> is available for the
789     release.</P>
790
791     <H4><A name="3.11">3.11</A>) What computer hardware should I use?</H4>
792
793     <P>Because PC hardware is mostly compatible, people tend to believe that
794     all PC hardware is of equal quality.  It is not.  ECC RAM, SCSI, and
795     quality motherboards are more reliable and have better performance than
796     less expensive hardware.  PostgreSQL will run on almost any hardware,
797     but if reliability and performance are important it is wise to
798     research your hardware options thoroughly.  Our email lists can be used
799     to discuss hardware options and tradeoffs.</P>
800
801     <HR>
802
803     <H2 align="center">Operational Questions</H2>
804
805     <H4><A name="4.1">4.1</A>) What is the difference between binary
806     cursors and normal cursors?</H4>
807
808     <P>See the <SMALL>DECLARE</SMALL> manual page for a
809     description.</P>
810
811     <H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
812     first few rows of a query?  A random row?</H4>
813
814     <P>See the <SMALL>FETCH</SMALL> manual page, or use
815     <SMALL>SELECT</SMALL> ... <SMALL>LIMIT</SMALL>....</P>
816
817     <P>The entire query may have to be evaluated, even if you only want
818     the first few rows. Consider using a query that has an <SMALL>ORDER
819     BY</SMALL>. If there is an index that matches the <SMALL>ORDER
820     BY</SMALL>, PostgreSQL may be able to evaluate only the first few
821     records requested, or the entire query may have to be evaluated
822     until the desired rows have been generated.</P>
823
824     <P>To <SMALL>SELECT</SMALL> a random row, use:
825 <PRE>
826     SELECT col
827     FROM tab
828     ORDER BY random()
829     LIMIT 1;
830 </PRE>
831
832     <H4><A name="4.3">4.3</A>) How do I get a list of tables or other
833     things I can see in <I>psql</I>?</H4>
834
835     <P>Use the \dt command to see tables in <I>psql</I>. For a complete list of
836     commands inside psql you can use \?. Alternatively you can read the source 
837     code for <I>psql</I> in file <I>pgsql/src/bin/psql/describe.c</I>, it 
838     contains <SMALL>SQL</SMALL> commands that generate the output for 
839     <I>psql</I>'s backslash commands. You can also start <I>psql</I> with the
840     <I>-E</I> option so it will print out the queries it uses to execute the 
841     commands you give. PostgreSQL also provides an <SMALL>SQLi</SMALL> compliant
842     INFORMATION SCHEMA interface you can query to get information about the
843     database.</P>
844
845     <H4><A name="4.4">4.4</A>) How do you remove a column from a
846     table, or change its data type?</H4>
847
848     <P><SMALL>DROP COLUMN</SMALL> functionality was added in release 7.3 with
849     <SMALL>ALTER TABLE DROP COLUMN</SMALL>.  In earlier versions,
850     you can do this:</P>
851 <PRE>
852     BEGIN;
853     LOCK TABLE old_table;
854     SELECT ...  -- select all columns but the one you want to remove
855     INTO TABLE new_table
856     FROM old_table;
857     DROP TABLE old_table;
858     ALTER TABLE new_table RENAME TO old_table;
859     COMMIT;
860 </PRE>
861
862     <P>To change the data type of a column, do this:</P>
863 <PRE>
864     BEGIN;
865     ALTER TABLE tab ADD COLUMN new_col <i>new_data_type</i>;
866     UPDATE tab SET new_col = CAST(old_col AS <i>new_data_type</i>);
867     ALTER TABLE tab DROP COLUMN old_col;
868     COMMIT;
869 </PRE>
870     <P>You might then want to do <I>VACUUM FULL tab</I> to reclaim the
871     disk space used by the expired rows.</P>
872     
873     <H4><A name="4.5">4.5</A>) What is the maximum size for a row, a
874     table, and a database?</H4>
875
876     <P>These are the limits:</P>
877 <PRE>
878     Maximum size for a database?             unlimited (32 TB databases exist)
879     Maximum size for a table?                32 TB
880     Maximum size for a row?                  1.6TB
881     Maximum size for a field?                1 GB
882     Maximum number of rows in a table?       unlimited
883     Maximum number of columns in a table?    250-1600 depending on column types
884     Maximum number of indexes on a table?    unlimited
885 </PRE>
886
887     Of course, these are not actually unlimited, but limited to
888     available disk space and memory/swap space. Performance may suffer
889     when these values get unusually large. 
890
891     <P>The maximum table size of 32 TB does not require large file
892     support from the operating system. Large tables are stored as
893     multiple 1 GB files so file system size limits are not
894     important.</P>
895
896     <P>The maximum table size and maximum number of columns can be
897     quadrupled by increasing the default block size to 32k.</P>
898
899     <H4><A name="4.6">4.6</A>) How much database disk space is required
900     to store data from a typical text file?</H4>
901
902     <P>A PostgreSQL database may require up to five times the disk
903     space to store data from a text file.</P>
904
905     <P>As an example, consider a file of 100,000 lines with an integer
906     and text description on each line. Suppose the text string
907     avergages twenty bytes in length. The flat file would be 2.8 MB.
908     The size of the PostgreSQL database file containing this data can
909     be estimated as 6.4 MB:</P>
910 <PRE>
911     32 bytes: each row header (approximate)
912     24 bytes: one int field and one text field
913    + 4 bytes: pointer on page to tuple
914    ----------------------------------------
915     60 bytes per row
916
917    The data page size in PostgreSQL is 8192 bytes (8 KB), so:
918
919    8192 bytes per page
920    -------------------   =  136 rows per database page (rounded down)
921      60 bytes per row
922
923    100000 data rows
924    --------------------  =  735 database pages (rounded up)
925       128 rows per page
926
927 735 database pages * 8192 bytes per page  =  6,021,120 bytes (6 MB)
928 </PRE>
929
930     <P>Indexes do not require as much overhead, but do contain the data
931     that is being indexed, so they can be large also.</P>
932
933     <P><SMALL>NULL</SMALL>s are stored as bitmaps, so they
934     use very little space.</P>
935     
936     <H4><A name="4.7">4.7</A>) How do I find out what tables, indexes,
937     databases, and users are defined?</H4>
938
939     <P><I>psql</I> has a variety of backslash commands to show such
940     information. Use \? to see them. There are also system tables
941     beginning with <I>pg_</I> that describe these too. Also, <I>psql
942     -l</I> will list all databases.</P>
943
944     <P>Also try the file <I>pgsql/src/tutorial/syscat.source</I>. It
945     illustrates many of the <SMALL>SELECT</SMALL>s needed to get
946     information from the database system tables.</P>
947
948     <H4><A name="4.8">4.8</A>) My queries are slow or don't make use of
949     the indexes. Why?</H4>
950     Indexes are not automatically used by every query. Indexes are only
951     used if the table is larger than a minimum size, and the query
952     selects only a small percentage of the rows in the table. This is
953     because the random disk access caused by an index scan can be
954     slower than a straight read through the table, or sequential scan. 
955
956     <P>To determine if an index should be used, PostgreSQL must have
957     statistics about the table. These statistics are collected using
958     <SMALL>VACUUM ANALYZE</SMALL>, or simply <SMALL>ANALYZE</SMALL>.
959     Using statistics, the optimizer knows how many rows are in the
960     table, and can better determine if indexes should be used.
961     Statistics are also valuable in determining optimal join order and
962     join methods. Statistics collection should be performed
963     periodically as the contents of the table change.</P>
964
965     <P>Indexes are normally not used for <SMALL>ORDER BY</SMALL> or to
966     perform joins. A sequential scan followed by an explicit sort is
967     usually faster than an index scan of a large table.</P>
968     However, <SMALL>LIMIT</SMALL> combined with <SMALL>ORDER BY</SMALL>
969     often will use an index because only a small portion of the table
970     is returned.  In fact, though MAX() and MIN() don't use indexes,
971     it is possible to retrieve such values using an index with ORDER BY
972     and LIMIT:
973 <PRE>
974     SELECT col
975     FROM tab
976     ORDER BY col [ DESC ]
977     LIMIT 1;
978 </PRE>
979
980     <P>If you believe the optimizer is incorrect in choosing a
981     sequential scan, use <CODE>SET enable_seqscan TO 'off'</CODE> and
982     run tests to see if an index scan is indeed faster.</P>
983
984     <P>When using wild-card operators such as <SMALL>LIKE</SMALL> or
985     <I>~</I>, indexes can only be used in certain circumstances:</P>
986     <UL>
987     <LI>The beginning of the search string must be anchored to the start
988     of the string, i.e.
989     <UL>
990     <LI><SMALL>LIKE</SMALL> patterns must not start with <I>%</I>.</LI>
991     <LI><I>~</I> (regular expression) patterns must start with
992     <I>^</I>.</LI>
993     </UL></LI>
994     <LI>The search string can not start with a character class,
995     e.g. [a-e].</LI>
996     <LI>Case-insensitive searches such as <SMALL>ILIKE</SMALL> and
997     <I>~*</I> do not utilise indexes. Instead, use functional
998     indexes, which are described in section <a href="#4.12">4.12</a>.</LI>
999     <LI>The default <I>C</I> locale must be used during
1000     <i>initdb</i>.</LI>
1001     </UL>
1002     <P>
1003
1004     <P>In pre-8.0 releases, indexes often can not be used unless the data
1005     types exactly match the index's column types.  This is particularly
1006     true of int2, int8, and numeric column indexes.</P>
1007
1008     <H4><A name="4.9">4.9</A>) How do I see how the query optimizer is
1009     evaluating my query?</H4>
1010
1011     <P>See the <SMALL>EXPLAIN</SMALL> manual page.</P>
1012
1013     <H4><A name="4.10">4.10</A>) What is an R-tree index?</H4>
1014
1015     <P>An R-tree index is used for indexing spatial data. A hash index
1016     can't handle range searches. A B-tree index only handles range
1017     searches in a single dimension. R-trees can handle
1018     multi-dimensional data. For example, if an R-tree index can be
1019     built on an attribute of type <I>point</I>, the system can more
1020     efficiently answer queries such as "select all points within a
1021     bounding rectangle."</P>
1022
1023     <P>The canonical paper that describes the original R-tree design
1024     is:</P>
1025
1026     <P>Guttman, A. "R-trees: A Dynamic Index Structure for Spatial
1027     Searching." Proceedings of the 1984 ACM SIGMOD Int'l Conf on Mgmt
1028     of Data, 45-57.</P>
1029
1030     <P>You can also find this paper in Stonebraker's "Readings in
1031     Database Systems".</P>
1032
1033     <P>Built-in R-trees can handle polygons and boxes. In theory,
1034     R-trees can be extended to handle higher number of dimensions. In
1035     practice, extending R-trees requires a bit of work and we don't
1036     currently have any documentation on how to do it.</P>
1037
1038     <H4><A name="4.11">4.11</A>) What is the Genetic Query
1039     Optimizer?</H4>
1040
1041     <P>The <SMALL>GEQO</SMALL> module speeds query optimization when
1042     joining many tables by means of a Genetic Algorithm (GA). It allows
1043     the handling of large join queries through nonexhaustive
1044     search.</P>
1045
1046     <H4><A name="4.12">4.12</A>) How do I perform regular expression
1047     searches and case-insensitive regular expression searches? How do I
1048     use an index for case-insensitive searches?</H4>
1049
1050     <P>The <I>~</I> operator does regular expression matching, and
1051     <I>~*</I> does case-insensitive regular expression matching. The
1052     case-insensitive variant of <SMALL>LIKE</SMALL> is called
1053     <SMALL>ILIKE</SMALL>.</P>
1054
1055     <P>Case-insensitive equality comparisons are normally expressed
1056     as:</P>
1057 <PRE>
1058     SELECT *
1059     FROM tab
1060     WHERE lower(col) = 'abc';
1061 </PRE>
1062
1063     This will not use an standard index. However, if you create a
1064     functional index, it will be used: 
1065 <PRE>
1066     CREATE INDEX tabindex ON tab (lower(col));
1067 </PRE>
1068
1069     <H4><A name="4.13">4.13</A>) In a query, how do I detect if a field
1070     is <SMALL>NULL</SMALL>?</H4>
1071
1072     <P>You test the column with <SMALL>IS NULL</SMALL> and <SMALL>IS
1073     NOT NULL</SMALL>.</P>
1074
1075     <H4><A name="4.14">4.14</A>) What is the difference between the
1076     various character types?</H4>
1077 <PRE>
1078 Type            Internal Name   Notes
1079 --------------------------------------------------
1080 VARCHAR(n)      varchar         size specifies maximum length, no padding
1081 CHAR(n)         bpchar          blank padded to the specified fixed length
1082 TEXT            text            no specific upper limit on length
1083 BYTEA           bytea           variable-length byte array (null-byte safe)
1084 "char"          char            one character
1085 </PRE>
1086
1087     <P>You will see the internal name when examining system catalogs
1088     and in some error messages.</P>
1089
1090     <P>The first four types above are "varlena" types (i.e., the first
1091     four bytes on disk are the length, followed by the data). Thus the
1092     actual space used is slightly greater than the declared size.
1093     However, these data types are also subject to compression or being
1094     stored out-of-line by <SMALL>TOAST</SMALL>, so the space on disk
1095     might also be less than expected.</P>
1096
1097     <SMALL>VARCHAR(n)</SMALL> is best when storing variable-length
1098     strings and it limits how long a string can be. <SMALL>TEXT</SMALL>
1099     is for strings of unlimited length, with a maximum of one gigabyte.
1100     <P><SMALL>CHAR(n)</SMALL> is for storing strings that are all the
1101     same length. <SMALL>CHAR(n)</SMALL> pads with blanks to the specified
1102     length, while <SMALL>VARCHAR(n)</SMALL> only stores the characters
1103     supplied.  <SMALL>BYTEA</SMALL> is for storing binary data,
1104     particularly values that include <SMALL>NULL</SMALL> bytes. All the
1105     types described here have similar performance characteristics.</P>
1106
1107     <H4><A name="4.15.1">4.15.1</A>) How do I create a
1108     serial/auto-incrementing field?</H4>
1109
1110     <P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It
1111     auto-creates a sequence.  For example,
1112     this:</P>
1113 <PRE>
1114     CREATE TABLE person ( 
1115         id   SERIAL, 
1116         name TEXT 
1117     );
1118 </PRE>
1119
1120     is automatically translated into this: 
1121 <PRE>
1122     CREATE SEQUENCE person_id_seq;
1123     CREATE TABLE person ( 
1124         id   INT4 NOT NULL DEFAULT nextval('person_id_seq'),
1125         name TEXT 
1126     );
1127 </PRE>
1128
1129     See the <I>create_sequence</I> manual page for more information
1130     about sequences. You can also use each row's <I>OID</I> field as a
1131     unique value. However, if you need to dump and reload the database,
1132     you need to use <I>pg_dump</I>'s <I>-o</I> option or <SMALL>COPY
1133     WITH OIDS</SMALL> option to preserve the <SMALL>OID</SMALL>s. 
1134
1135     <H4><A name="4.15.2">4.15.2</A>) How do I get the value of a
1136     <SMALL>SERIAL</SMALL> insert?</H4>
1137
1138     <P>One approach is to retrieve the next <SMALL>SERIAL</SMALL> value
1139     from the sequence object with the <I>nextval()</I> function
1140     <I>before</I> inserting and then insert it explicitly. Using the
1141     example table in <A href="#4.15.1">4.15.1</A>, an example in a
1142     pseudo-language would look like this:</P>
1143 <PRE>
1144     new_id = execute("SELECT nextval('person_id_seq')");
1145     execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
1146 </PRE>
1147
1148     You would then also have the new value stored in
1149     <CODE>new_id</CODE> for use in other queries (e.g., as a foreign
1150     key to the <CODE>person</CODE> table). Note that the name of the
1151     automatically created <SMALL>SEQUENCE</SMALL> object will be named
1152     &lt;<I>table</I>&gt;_&lt;<I>serialcolumn</I>&gt;_<I>seq</I>, where
1153     <I>table</I> and <I>serialcolumn</I> are the names of your table
1154     and your <SMALL>SERIAL</SMALL> column, respectively.
1155
1156     <P>Alternatively, you could retrieve the assigned
1157     <SMALL>SERIAL</SMALL> value with the <I>currval()</I> function
1158     <I>after</I> it was inserted by default, e.g.,</P>
1159 <PRE>
1160     execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
1161     new_id = execute("SELECT currval('person_id_seq')");
1162 </PRE>
1163
1164     Finally, you could use the <A href="#4.16"><SMALL>OID</SMALL></A>
1165     returned from the <SMALL>INSERT</SMALL> statement to look up the
1166     default value, though this is probably the least portable approach,
1167     and the oid value will wrap around when it reaches 4 billion.
1168     In Perl, using DBI with Edmund Mergl's DBD::Pg module, the oid
1169     value is made available via <I>$sth-&gt;{pg_oid_status}</I> after
1170     <I>$sth-&gt;execute()</I>.
1171
1172     <H4><A name="4.15.3">4.15.3</A>) Don't <I>currval()</I> and
1173     <I>nextval()</I> lead to a race condition with other users?</H4>
1174
1175     <P>No. <I>currval()</I> returns the current value assigned by your
1176     backend, not by all users.</P>
1177
1178     <H4><A name="4.15.4">4.15.4</A>) Why aren't my sequence numbers
1179     reused on transaction abort? Why are there gaps in the numbering of
1180     my sequence/SERIAL column?</H4>
1181
1182     <P>To improve concurrency, sequence values are given out to running
1183     transactions as needed and are not locked until the transaction
1184     completes. This causes gaps in numbering from aborted
1185     transactions.</P>
1186
1187     <H4><A name="4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is
1188     a <SMALL>TID</SMALL>?</H4>
1189
1190     <P><SMALL>OID</SMALL>s are PostgreSQL's answer to unique row ids.
1191     Every row that is created in PostgreSQL gets a unique
1192     <SMALL>OID</SMALL>. All <SMALL>OID</SMALL>s generated during
1193     <I>initdb</I> are less than 16384 (from
1194     <I>include/access/transam.h</I>). All user-created
1195     <SMALL>OID</SMALL>s are equal to or greater than this. By default,
1196     all these <SMALL>OID</SMALL>s are unique not only within a table or
1197     database, but unique within the entire PostgreSQL installation.</P>
1198
1199     <P>PostgreSQL uses <SMALL>OID</SMALL>s in its internal system
1200     tables to link rows between tables. These <SMALL>OID</SMALL>s can
1201     be used to identify specific user rows and used in joins. It is
1202     recommended you use column type <SMALL>OID</SMALL> to store
1203     <SMALL>OID</SMALL> values. You can create an index on the
1204     <SMALL>OID</SMALL> field for faster access.</P>
1205
1206     <P>O<SMALL>ID</SMALL>s are assigned to all new rows from a central
1207     area that is used by all databases. If you want to change the
1208     <SMALL>OID</SMALL> to something else, or if you want to make a copy
1209     of the table, with the original <SMALL>OID</SMALL>s, there is no
1210     reason you can't do it:</P>
1211 <PRE>
1212         CREATE TABLE new_table(mycol int);
1213         SELECT oid AS old_oid, mycol INTO tmp_table FROM old_table;
1214         COPY tmp_table TO '/tmp/pgtable';
1215         COPY new_table WITH OIDS FROM '/tmp/pgtable';
1216         DROP TABLE tmp_table;
1217 </PRE>
1218     <P>O<SMALL>ID</SMALL>s are stored as 4-byte integers, and will
1219     overflow at 4 billion. No one has reported this ever happening, and
1220     we plan to have the limit removed before anyone does.</P>
1221
1222     <P>T<SMALL>ID</SMALL>s are used to identify specific physical rows
1223     with block and offset values. T<SMALL>ID</SMALL>s change after rows
1224     are modified or reloaded. They are used by index entries to point
1225     to physical rows.</P>
1226
1227     <H4><A name="4.17">4.17</A>) What is the meaning of some of the
1228     terms used in PostgreSQL?</H4>
1229
1230     <P>Some of the source code and older documentation use terms that
1231     have more common usage. Here are some:</P>
1232
1233     <UL>
1234       <LI>table, relation, class</LI>
1235
1236       <LI>row, record, tuple</LI>
1237
1238       <LI>column, field, attribute</LI>
1239
1240       <LI>retrieve, select</LI>
1241
1242       <LI>replace, update</LI>
1243
1244       <LI>append, insert</LI>
1245
1246       <LI><SMALL>OID</SMALL>, serial value</LI>
1247
1248       <LI>portal, cursor</LI>
1249
1250       <LI>range variable, table name, table alias</LI>
1251     </UL>
1252
1253     <P>A list of general database terms can be found at: <A href=
1254     "http://hea-www.harvard.edu/MST/simul/software/docs/pkgs/pgsql/glossary/glossary.html">http://hea-www.harvard.edu/MST/simul/software/docs/pkgs/pgsql/glossary/glossary.html</A></P>
1255
1256     <H4><A name="4.18">4.18</A>) Why do I get the error <I>"ERROR:
1257     Memory exhausted in AllocSetAlloc()"</I>?</H4>
1258
1259     <P>You probably have run out of virtual memory on your system,
1260     or your kernel has a low limit for certain resources. Try this
1261     before starting <I>postmaster</I>:</P>
1262 <PRE>
1263     ulimit -d 262144
1264     limit datasize 256m
1265 </PRE>
1266
1267     Depending on your shell, only one of these may succeed, but it will
1268     set your process data segment limit much higher and perhaps allow
1269     the query to complete. This command applies to the current process,
1270     and all subprocesses created after the command is run. If you are
1271     having a problem with the <SMALL>SQL</SMALL> client because the
1272     backend is returning too much data, try it before starting the
1273     client.
1274
1275     <H4><A name="4.19">4.19</A>) How do I tell what PostgreSQL version
1276     I am running?</H4>
1277
1278     <P>From <I>psql</I>, type <CODE>SELECT version();</CODE></P>
1279
1280     <H4><A name="4.20">4.20</A>) Why does my large-object operations
1281     get <I>"invalid large obj descriptor"</I>?</H4>
1282
1283     <P>You need to put <CODE>BEGIN WORK</CODE> and <CODE>COMMIT</CODE>
1284     around any use of a large object handle, that is, surrounding
1285     <CODE>lo_open</CODE> ... <CODE>lo_close.</CODE></P>
1286
1287     <P>Currently PostgreSQL enforces the rule by closing large object
1288     handles at transaction commit. So the first attempt to do anything
1289     with the handle will draw <I>invalid large obj descriptor</I>. So
1290     code that used to work (at least most of the time) will now
1291     generate that error message if you fail to use a transaction.</P>
1292
1293     <P>If you are using a client interface like <SMALL>ODBC</SMALL> you
1294     may need to set <CODE>auto-commit off.</CODE></P>
1295
1296     <H4><A name="4.21">4.21</A>) How do I create a column that will
1297     default to the current time?</H4>
1298
1299     <P>Use <I>CURRENT_TIMESTAMP</I>:</P>
1300 <PRE>
1301 <CODE>CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
1302 </CODE>
1303 </PRE>
1304
1305     <H4><A name="4.22">4.22</A>) Why are my subqueries using
1306     <CODE><SMALL>IN</SMALL></CODE> so slow?</H4>
1307
1308     <P>In versions prior to 7.4, subqueries were joined to outer queries
1309     by sequentially scanning the result of the subquery for each row of
1310     the outer query. If the subquery returns only a few rows and the outer
1311     query returns many rows, <CODE><SMALL>IN</SMALL></CODE> is fastest.  To
1312     speed up other queries, replace <CODE>IN</CODE> with
1313     <CODE>EXISTS</CODE>:</P>
1314 <PRE>    SELECT *
1315     FROM tab
1316     WHERE col IN (SELECT subcol FROM subtab);
1317 </PRE>
1318     to:
1319 <PRE>    SELECT *
1320     FROM tab
1321     WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col);
1322 </PRE>
1323
1324     For this to be fast, <CODE>subcol</CODE> should be an indexed column.
1325     <P>In version 7.4 and later,  <CODE>IN</CODE> actually uses the same
1326     sophisticated join techniques as normal queries, and is prefered
1327     to using <CODE>EXISTS</CODE>.
1328
1329     <H4><A name="4.23">4.23</A>) How do I perform an outer join?</H4>
1330
1331     <P>PostgreSQL supports outer joins using the SQL standard syntax.
1332     Here are two examples:</P>
1333 <PRE>
1334     SELECT *
1335     FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
1336 </PRE>
1337     or 
1338 <PRE>
1339     SELECT *
1340     FROM t1 LEFT OUTER JOIN t2 USING (col);
1341 </PRE>
1342
1343     <P>These identical queries join t1.col to t2.col, and also return
1344     any unjoined rows in t1 (those with no match in t2). A
1345     <SMALL>RIGHT</SMALL> join would add unjoined rows of t2. A
1346     <SMALL>FULL</SMALL> join would return the matched rows plus all
1347     unjoined rows from t1 and t2. The word <SMALL>OUTER</SMALL> is
1348     optional and is assumed in <SMALL>LEFT</SMALL>,
1349     <SMALL>RIGHT</SMALL>, and <SMALL>FULL</SMALL> joins. Ordinary joins
1350     are called <SMALL>INNER</SMALL> joins.</P>
1351
1352     <P>In previous releases, outer joins can be simulated using
1353     <SMALL>UNION</SMALL> and <SMALL>NOT IN</SMALL>. For example, when
1354     joining <I>tab1</I> and <I>tab2</I>, the following query does an
1355     <I>outer</I> join of the two tables:<BR>
1356     <BR>
1357     </P>
1358 <PRE>
1359     SELECT tab1.col1, tab2.col2
1360     FROM tab1, tab2
1361     WHERE tab1.col1 = tab2.col1
1362     UNION ALL
1363     SELECT tab1.col1, NULL
1364     FROM tab1
1365     WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
1366     ORDER BY col1
1367 </PRE>
1368
1369     <H4><A name="4.24">4.24</A>) How do I perform queries using
1370     multiple databases?</H4>
1371
1372     <P>There is no way to query a database other than the current one.
1373     Because PostgreSQL loads database-specific system catalogs, it is
1374     uncertain how a cross-database query should even behave.</P>
1375
1376     <P><I>contrib/dblink</I> allows cross-database queries using
1377     function calls. Of course, a client can make simultaneous
1378     connections to different databases and merge the results on the
1379     client side.</P>
1380
1381     <H4><A name="4.25">4.25</A>) How do I return multiple rows or
1382     columns from a function?</H4>
1383
1384     <P>In 7.3, you can easily return multiple rows or columns from a
1385     function,
1386     <a href="http://techdocs.postgresql.org/guides/SetReturningFunctions">
1387     http://techdocs.postgresql.org/guides/SetReturningFunctions</a>.
1388
1389     <H4><A name="4.26">4.26</A>) Why can't I reliably create/drop
1390     temporary tables in PL/PgSQL functions?</H4>
1391     <P>PL/PgSQL caches function contents, and an unfortunate side effect
1392     is that if a PL/PgSQL function accesses a temporary table, and that
1393     table is later dropped and recreated, and the function called
1394     again, the function will fail because the cached function contents
1395     still point to the old temporary table. The solution is to use
1396     <SMALL>EXECUTE</SMALL> for temporary table access in PL/PgSQL. This
1397     will cause the query to be reparsed every time.</P>
1398
1399     <H4><A name="4.27">4.27</A>) What replication options are available?
1400     </H4>
1401     <P>There are several master/slave replication options available.
1402     These allow only the master to make database changes and the slave
1403     can only do database reads. The bottom of <a
1404     href="http://gborg.PostgreSQL.org/genpage?replication_research">
1405     http://gborg.PostgreSQL.org/genpage?replication_research</a> lists
1406     them. A multi-master replication solution is being worked on at <a
1407     href="http://gborg.PostgreSQL.org/project/pgreplication/projdisplay.php">http://gborg.PostgreSQL.org/project/pgreplication/projdisplay.php</a>.</P>
1408
1409     <H4><A name="4.28">4.28</A>) What encryption options are available?
1410     </H4>
1411     <UL>
1412     <LI><I>contrib/pgcrypto</I> contains many encryption functions for
1413     use in <SMALL>SQL</SMALL> queries.</LI>
1414     <LI>To encrypt transmission from the client to the server, the server
1415     must have the <I>ssl</I> option set to <I>true</I> in <I>postgresql.conf,
1416     </I> and an applicable <I>host</I> or <I>hostssl</I> record must exist in
1417     <I>pg_hba.conf</I>, and the client <I>sslmode</I> must not be
1418     <I>disable.</I> (Note that it is also possible to use a third-party
1419     encrypted transport, such as stunnel or ssh, rather than PostgreSQL's
1420     native SSL connections.)
1421     <LI>Database user passwords are automatically encrypted when stored in
1422     version 7.3. In previous versions, you must enable the option
1423     <I>PASSWORD_ENCRYPTION</I> in <I>postgresql.conf</I>.</LI>
1424     <LI>The server can run using an encrypted file system.</LI>
1425     </UL>
1426
1427     <HR>
1428
1429     <H2 align="center">Extending PostgreSQL</H2>
1430
1431     <H4><A name="5.1">5.1</A>) I wrote a user-defined function. When I
1432     run it in <I>psql</I>, why does it dump core?</H4>
1433
1434     <P>The problem could be a number of things. Try testing your
1435     user-defined function in a stand-alone test program first.</P>
1436
1437     <H4><A name="5.2">5.2</A>) How can I contribute some nifty new
1438     types and functions to PostgreSQL?</H4>
1439
1440     <P>Send your extensions to the <I>pgsql-hackers</I> mailing list,
1441     and they will eventually end up in the <I>contrib/</I>
1442     subdirectory.</P>
1443
1444     <H4><A name="5.3">5.3</A>) How do I write a C function to return a
1445     tuple?</H4>
1446
1447     <P>In versions of PostgreSQL beginning with 7.3, table-returning
1448     functions are fully supported in C, PL/PgSQL, and SQL. See the
1449     Programmer's Guide for more information. An example of a
1450     table-returning function defined in C can be found in
1451     <I>contrib/tablefunc</I>.</P>
1452
1453     <H4><A name="5.4">5.4</A>) I have changed a source file. Why does
1454     the recompile not see the change?</H4>
1455
1456     <P>The <I>Makefiles</I> do not have the proper dependencies for
1457     include files. You have to do a <I>make clean</I> and then another
1458     <I>make</I>. If you are using <SMALL>GCC</SMALL> you can use the
1459     <I>--enable-depend</I> option of <I>configure</I> to have the
1460     compiler compute the dependencies automatically.</P>
1461   </BODY>
1462 </HTML>
1463