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