1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
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>
9 <BODY bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000"
11 <H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
13 <P>Last updated: Fri Feb 14 08:58:51 EST 2003</P>
15 <P>Current maintainer: Bruce Momjian (<A href=
16 "mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
19 <P>The most recent version of this document can be viewed at <A
21 "http://www.ca.PostgreSQL.org/docs/faq-english.html">http://www.ca.PostgreSQL.org/docs/faq-english.html</A>.</P>
23 <P>Platform-specific questions are answered at <A href=
24 "http://www.ca.PostgreSQL.org/users-lounge/docs/faq.html">http://www.ca.PostgreSQL.org/users-lounge/docs/faq.html</A>.</P>
27 <H2 align="center">General Questions</H2>
28 <A href="#1.1">1.1</A>) What is PostgreSQL? How is it pronounced?<BR>
29 <A href="#1.2">1.2</A>) What is the copyright on PostgreSQL?<BR>
30 <A href="#1.3">1.3</A>) What Unix platforms does PostgreSQL run
32 <A href="#1.4">1.4</A>) What non-Unix ports are available?<BR>
33 <A href="#1.5">1.5</A>) Where can I get PostgreSQL?<BR>
34 <A href="#1.6">1.6</A>) Where can I get support?<BR>
35 <A href="#1.7">1.7</A>) What is the latest release?<BR>
36 <A href="#1.8">1.8</A>) What documentation is available?<BR>
37 <A href="#1.9">1.9</A>) How do I find out about known bugs or
39 <A href="#1.10">1.10</A>) How can I learn <SMALL>SQL</SMALL>?<BR>
40 <A href="#1.11">1.11</A>) Is PostgreSQL Y2K compliant?<BR>
41 <A href="#1.12">1.12</A>) How do I join the development team?<BR>
42 <A href="#1.13">1.13</A>) How do I submit a bug report?<BR>
43 <A href="#1.14">1.14</A>) How does PostgreSQL compare to other
44 <SMALL>DBMS</SMALL>s?<BR>
45 <A href="#1.15">1.15</A>) How can I financially assist
49 <H2 align="center">User Client Questions</H2>
50 <A href="#2.1">2.1</A>) Are there <SMALL>ODBC</SMALL> drivers for
52 <A href="#2.2">2.2</A>) What tools are available for using
53 PostgreSQL with Web pages?<BR>
54 <A href="#2.3">2.3</A>) Does PostgreSQL have a graphical user
56 <A href="#2.4">2.4</A>) What languages are available to
57 communicate with PostgreSQL?<BR>
60 <H2 align="center">Administrative Questions</H2>
61 <A href="#3.1">3.1</A>) How do I install PostgreSQL somewhere other
62 than <I>/usr/local/pgsql</I>?<BR>
63 <A href="#3.2">3.2</A>) When I start <I>postmaster</I>, I get a
64 <I>Bad System Call</I> or core dumped message. Why?<BR>
65 <A href="#3.3">3.3</A>) When I try to start <I>postmaster</I>, I
66 get <I>IpcMemoryCreate</I> errors. Why?<BR>
67 <A href="#3.4">3.4</A>) When I try to start <I>postmaster</I>, I
68 get <I>IpcSemaphoreCreate</I> errors. Why?<BR>
69 <A href="#3.5">3.5</A>) How do I control connections from other
71 <A href="#3.6">3.6</A>) How do I tune the database engine for
72 better performance?<BR>
73 <A href="#3.7">3.7</A>) What debugging features are available?<BR>
74 <A href="#3.8">3.8</A>) Why do I get <I>"Sorry, too many
75 clients"</I> when trying to connect?<BR>
76 <A href="#3.9">3.9</A>) What is in the <I>pgsql_tmp</I>
78 <A href="#3.10">3.10</A>) Why do I need to do a dump and restore
79 to upgrade PostgreSQL releases?<BR>
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?<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
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
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
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
136 <A href="#4.25">4.25</A>) How do I return multiple rows or columns
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>
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
151 <A href="#5.4">5.4</A>) I have changed a source file. Why does the
152 recompile not see the change?<BR>
156 <H2 align="center">General Questions</H2>
158 <H4><A name="1.1">1.1</A>) What is PostgreSQL? How is it pronounced?</H4>
160 <P>PostgreSQL is pronounced <I>Post-Gres-Q-L</I>.</P>
162 <P>PostgreSQL is an enhancement of the POSTGRES database management
163 system, a next-generation <SMALL>DBMS</SMALL> research prototype.
164 While PostgreSQL retains the powerful data model and rich data
165 types of POSTGRES, it replaces the PostQuel query language with an
166 extended subset of <SMALL>SQL</SMALL>. PostgreSQL is free and the
167 complete source is available.</P>
169 <P>PostgreSQL development is performed by a team of
170 developers who all subscribe to the PostgreSQL development mailing
171 list. The current coordinator is Marc G. Fournier (<A href=
172 "mailto:scrappy@PostgreSQL.org">scrappy@PostgreSQL.org</A>). (See
173 section <a href="#1.6">1.6</a> on how to join). This team is now
174 responsible for all development of PostgreSQL.</P>
176 <P>The authors of PostgreSQL 1.01 were Andrew Yu and Jolly Chen.
177 Many others have contributed to the porting, testing, debugging,
178 and enhancement of the code. The original Postgres code, from which
179 PostgreSQL is derived, was the effort of many graduate students,
180 undergraduate students, and staff programmers working under the
181 direction of Professor Michael Stonebraker at the University of
182 California, Berkeley.</P>
184 <P>The original name of the software at Berkeley was Postgres. When
185 <SMALL>SQL</SMALL> functionality was added in 1995, its name was
186 changed to Postgres95. The name was changed at the end of 1996 to
189 <H4><A name="1.2">1.2</A>) What is the copyright on
192 <P>PostgreSQL is subject to the following COPYRIGHT:</P>
194 <P>PostgreSQL Data Base Management System</P>
196 <P>Portions copyright (c) 1996-2002, PostgreSQL Global Development
197 Group Portions Copyright (c) 1994-6 Regents of the University of
200 <P>Permission to use, copy, modify, and distribute this software
201 and its documentation for any purpose, without fee, and without a
202 written agreement is hereby granted, provided that the above
203 copyright notice and this paragraph and the following two
204 paragraphs appear in all copies.</P>
206 <P>IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
207 PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
208 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
209 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
210 CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</P>
212 <P>THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
213 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
214 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
215 SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
216 UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
217 SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.</P>
219 <P>The above is the BSD license, the classic open-source license.
220 It has no restrictions on how the source code may be used. We like
221 it and have no intention of changing it.</P>
223 <H4><A name="1.3">1.3</A>) What Unix platforms does PostgreSQL run
226 <P>In general, a modern Unix-compatible platform should be able to
227 run PostgreSQL. The platforms that had received explicit testing at
228 the time of release are listed in the installation
231 <H4><A name="1.4">1.4</A>) What non-Unix ports are available?</H4>
233 <P><STRONG>Client</STRONG></P>
235 <P>It is possible to compile the <I>libpq</I> C library, psql, and
236 other interfaces and client applications to run on MS Windows platforms.
237 In this case, the client is running on MS Windows, and communicates
238 via TCP/IP to a server running on one of our supported Unix
239 platforms. A file <I>win32.mak</I> is included in the distribution
240 for making a Win32 <I>libpq</I> library and <I>psql</I>. PostgreSQL
241 also communicates with <SMALL>ODBC</SMALL> clients.</P>
243 <P><STRONG>Server</STRONG></P>
245 <P>The database server can run on Windows NT and Win2k using
246 Cygwin, the Cygnus Unix/NT porting library. See
247 <I>pgsql/doc/FAQ_MSWIN</I> in the distribution or the MS Windows FAQ
248 at <A href="http://www.PostgreSQL.org/docs/faq-mswin.html">
249 http://www.PostgreSQL.org/docs/faq-mswin.html</A>.</P>
251 <p>A native port to MS Win NT/2000/XP is currently being worked
254 <H4><A name="1.5">1.5</A>) Where can I get PostgreSQL?</H4>
256 <P>The primary anonymous ftp site for PostgreSQL is <A href=
257 "ftp://ftp.PostgreSQL.org/pub">ftp://ftp.PostgreSQL.org/pub</A>.
258 For mirror sites, see our main web site.</P>
260 <H4><A name="1.6">1.6</A>) Where can I get support?</H4>
262 <P>The main mailing list is: <A href=
263 "mailto:pgsql-general@PostgreSQL.org">pgsql-general@PostgreSQL.org</A>.
264 It is available for discussion of matters pertaining to PostgreSQL.
265 To subscribe, send mail with the following lines in the body (not
266 the subject line):</P>
273 "mailto:pgsql-general-request@PostgreSQL.org">pgsql-general-request@PostgreSQL.org</A>.</P>
275 <P>There is also a digest list available. To subscribe to this
276 list, send email to: <A href=
277 "mailto:pgsql-general-digest-request@PostgreSQL.org">pgsql-general-digest-request@PostgreSQL.org</A>
284 Digests are sent out to members of this list whenever the main list
285 has received around 30k of messages.
287 <P>The bugs mailing list is available. To subscribe to this list,
288 send email to <A href=
289 "mailto:pgsql-bugs-request@PostgreSQL.org">pgsql-bugs-request@PostgreSQL.org</A>
296 There is also a developers discussion mailing list available. To
297 subscribe to this list, send email to <A href=
298 "mailto:pgsql-hackers-request@PostgreSQL.org">pgsql-hackers-request@PostgreSQL.org</A>
305 <P>Additional mailing lists and information about PostgreSQL can be
306 found via the PostgreSQL WWW home page at:</P>
309 <A href="http://www.PostgreSQL.org">http://www.PostgreSQL.org</A>
312 <P>There is also an IRC channel on EFNet, channel
313 <I>#PostgreSQL</I>. I use the Unix command <CODE>irc -c
314 '#PostgreSQL' "$USER" irc.phoenix.net.</CODE></P>
316 <P>A list of commercial support companies is available at <A href=
317 "http://www.ca.PostgreSQL.org/users-lounge/commercial-support.html">http://www.ca.PostgreSQL.org/users-lounge/commercial-support.html</A>.</P>
319 <H4><A name="1.7">1.7</A>) What is the latest release?</H4>
321 <P>The latest release of PostgreSQL is version 7.3.1.</P>
323 <P>We plan to have major releases every four months.</P>
325 <H4><A name="1.8">1.8</A>) What documentation is available?</H4>
327 <P>Several manuals, manual pages, and some small test examples are
328 included in the distribution. See the <I>/doc</I> directory. You
329 can also browse the manual online at <A href=
330 "http://www.ca.PostgreSQL.org/users-lounge/docs/">http://www.ca.PostgreSQL.org/users-lounge/docs/</A>.</P>
332 <P>There are two PostgreSQL books available online at <A href=
333 "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
335 "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook/</A>.
336 There is a list of PostgreSQL books available for purchase at <A
338 "http://www.ca.PostgreSQL.org/books/">http://www.ca.PostgreSQL.org/books/</A>.
339 There is also a collection of PostgreSQL technical articles at <A
341 "http://techdocs.PostgreSQL.org/">http://techdocs.PostgreSQL.org/</A>.</P>
343 <P><I>psql</I> has some nice \d commands to show information about
344 types, operators, functions, aggregates, etc.</P>
346 <P>Our web site contains even more documentation.</P>
348 <H4><A name="1.9">1.9</A>) How do I find out about known bugs or
349 missing features?</H4>
351 <P>PostgreSQL supports an extended subset of <SMALL>SQL</SMALL>-92.
352 See our <A href="http://developer.PostgreSQL.org/todo.php">TODO</A>
353 list for known bugs, missing features, and future plans.</P>
355 <H4><A name="1.10">1.10</A>) How can I learn
356 <SMALL>SQL</SMALL>?</H4>
358 <P>The PostgreSQL book at <A href=
359 "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
360 teaches <SMALL>SQL</SMALL>. There is another PostgreSQL book at <A
362 "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook.</A>
363 There is a nice tutorial at <A href=
364 "http://www.intermedia.net/support/sql/sqltut.shtm">http://www.intermedia.net/support/sql/sqltut.shtm,</A>
366 "http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM">
367 http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM,</A>
369 "http://sqlcourse.com/">http://sqlcourse.com.</A></P>
371 <P>Another one is "Teach Yourself SQL in 21 Days, Second Edition"
373 "http://members.tripod.com/er4ebus/sql/index.htm">http://members.tripod.com/er4ebus/sql/index.htm</A></P>
375 <P>Many of our users like <I>The Practical SQL Handbook</I>,
376 Bowman, Judith S., et al., Addison-Wesley. Others like <I>The
377 Complete Reference SQL</I>, Groff et al., McGraw-Hill.</P>
379 <H4><A name="1.11">1.11</A>) Is PostgreSQL Y2K compliant?</H4>
381 <P>Yes, we easily handle dates past the year 2000 AD, and before
384 <H4><A name="1.12">1.12</A>) How do I join the development
387 <P>First, download the latest source and read the PostgreSQL
388 Developers documentation on our web site, or in the distribution.
389 Second, subscribe to the <I>pgsql-hackers</I> and
390 <I>pgsql-patches</I> mailing lists. Third, submit high quality
391 patches to pgsql-patches.</P>
393 <P>There are about a dozen people who have commit privileges to the
394 PostgreSQL <SMALL>CVS</SMALL> archive. They each have submitted so
395 many high-quality patches that it was impossible for the existing
396 committers to keep up, and we had confidence that patches they
397 committed were of high quality.</P>
399 <H4><A name="1.13">1.13</A>) How do I submit a bug report?</H4>
401 <P>Please visit the PostgreSQL BugTool page at <A href=
402 "http://www.PostgreSQL.org/bugs/bugs.php">http://www.PostgreSQL.org/bugs/bugs.php</A>,
403 which gives guidelines and directions on how to submit a
406 <P>Also check out our ftp site <A href=
407 "ftp://ftp.PostgreSQL.org/pub">ftp://ftp.PostgreSQL.org/pub</A> to
408 see if there is a more recent PostgreSQL version or patches.</P>
410 <H4><A name="1.14">1.14</A>) How does PostgreSQL compare to other
411 <SMALL>DBMS</SMALL>s?</H4>
413 <P>There are several ways of measuring software: features,
414 performance, reliability, support, and price.</P>
417 <DT><B>Features</B></DT>
419 <DD>PostgreSQL has most features present in large commercial
420 <SMALL>DBMS</SMALL>s, like transactions, subselects, triggers,
421 views, foreign key referential integrity, and sophisticated
422 locking. We have some features they do not have, like
423 user-defined types, inheritance, rules, and multi-version
424 concurrency control to reduce lock contention.<BR>
428 <DT><B>Performance</B></DT>
430 <DD>PostgreSQL has performance similar to other commercial and
431 open source databases. it is faster for some things, slower for
432 others. In comparison to MySQL or leaner database systems, we are
433 slower on inserts/updates because of transaction overhead. Of
434 course, MySQL does not have any of the features mentioned in the
435 <I>Features</I> section above. We are built for reliability and
436 features, though we continue to improve performance in every
437 release. There is an interesting Web page comparing PostgreSQL to
438 MySQL at <A href="http://openacs.org/philosophy/why-not-mysql.html">
439 http://openacs.org/philosophy/why-not-mysql.html</A><BR>
444 <DT><B>Reliability</B></DT>
446 <DD>We realize that a <SMALL>DBMS</SMALL> must be reliable, or it
447 is worthless. We strive to release well-tested, stable code that
448 has a minimum of bugs. Each release has at least one month of
449 beta testing, and our release history shows that we can provide
450 stable, solid releases that are ready for production use. We
451 believe we compare favorably to other database software in this
456 <DT><B>Support</B></DT>
458 <DD>Our mailing lists provide contact with a large group of developers
459 and users to help resolve any problems encountered. While we cannot
460 guarantee a fix, commercial <SMALL>DBMS</SMALL>s do not always
461 supply a fix either. Direct access to developers, the user
462 community, manuals, and the source code often make PostgreSQL
463 support superior to other <SMALL>DBMS</SMALL>s. There is
464 commercial per-incident support available for those who need it.
465 (See <A href="#1.6">FAQ section 1.6</A>.)<BR>
469 <DT><B>Price</B></DT>
471 <DD>We are free for all use, both commercial and non-commercial.
472 You can add our code to your product with no limitations, except
473 those outlined in our BSD-style license stated above.<BR>
478 <H4><A name="1.15">1.15</A>) How can I financially assist
481 <P>PostgreSQL has had a first-class infrastructure since we started
482 in 1996. This is all thanks to Marc Fournier, who has created
483 and managed this infrastructure over the years.</P>
485 <P>Quality infrastructure is very important to an open-source
486 project. It prevents disruptions that can greatly delay forward
487 movement of the project.</P>
489 <P>Of course, this infrastructure is not cheap. There are a variety
490 of monthly and one-time expenses that are required to keep it
491 going. If you or your company has money it can donate to help fund
492 this effort, please go to <A href="http://store.pgsql.com/shopping/">http://store.pgsql.com/shopping/</A>
493 and make a donation.</P>
495 <P>Although the web page mentions PostgreSQL, Inc, the
496 "contributions" item is solely to support the PostgreSQL project
497 and does not fund any specific company. If you prefer, you can also
498 send a check to the contact address.</P>
501 <H2 align="center">User Client Questions</H2>
503 <H4><A name="2.1">2.1</A>) Are there <SMALL>ODBC</SMALL> drivers
506 <P>There are two <SMALL>ODBC</SMALL> drivers available, PsqlODBC
507 and OpenLink <SMALL>ODBC</SMALL>.</P>
509 <P>You can download PsqlODBC from <A href=
510 "http://gborg.postgresql.org/project/psqlodbc/projdisplay.php">
511 http://gborg.postgresql.org/project/psqlodbc/projdisplay.php</A>.</P>
513 <P>OpenLink <SMALL>ODBC</SMALL> can be gotten from <A href=
514 "http://www.openlinksw.com/">http://www.openlinksw.com</A>. It
515 works with their standard <SMALL>ODBC</SMALL> client software so
516 you'll have PostgreSQL <SMALL>ODBC</SMALL> available on every
517 client platform they support (Win, Mac, Unix, VMS).</P>
519 <P>They will probably be selling this product to people who need
520 commercial-quality support, but a freeware version will always be
521 available. Please send questions to <A href=
522 "mailto:postgres95@openlink.co.uk">postgres95@openlink.co.uk</A>.</P>
524 <H4><A name="2.2">2.2</A>) What tools are available for using
525 PostgreSQL with Web pages?</H4>
527 <P>A nice introduction to Database-backed Web pages can be seen at:
528 <A href="http://www.webreview.com">http://www.webreview.com</A></P>
530 <P>For Web integration, PHP is an excellent interface. It is at <A
531 href="http://www.php.net">http://www.php.net</A>.</P>
533 <P>For complex cases, many use the Perl interface and CGI.pm or mod_perl.</P>
535 <H4><A name="2.3">2.3</A>) Does PostgreSQL have a graphical user
538 Yes, there are several graphical interfaces to PostgreSQL available.
539 These include PgAccess <a href="http://www.pgaccess.org">
540 http://www.pgaccess.org</a>), PgAdmin II (<a
541 href="http://www.pgadmin.org">http://www.pgadmin.org</a>,
542 Win32-only), RHDB Admin (<a
543 href="http://sources.redhat.com/rhdb/">http://sources.redhat.com/rhdb/
544 </a>) and Rekall (<a href="http://www.thekompany.com/products/rekall/">
545 http://www.thekompany.com/products/rekall/</a>, proprietary). There is
546 also PHPPgAdmin (<a href="http://phppgadmin.sourceforge.net/">
547 http://phppgadmin.sourceforge.net/ </a>), a web-based interface to
550 <H4><A name="2.4">2.4</A>) What languages are able to communicate with
553 <P>Most popular programming languages contain an interface to
554 PostgreSQL. Check your programming language's list of extension
557 <P>The following interfaces are included in the PostgreSQL
563 <LI>Embedded C (ecpg)</LI>
567 <LI>Python (PyGreSQL)</LI>
569 <LI>TCL (libpgtcl)</LI>
572 <P>Additional interfaces are available at
573 <a href="http://gborg.postgresql.org">http://gborg.postgresql.org</A>
574 in the <I>Drivers/Interfaces</I> section.
578 <H2 align="center">Administrative Questions</H2>
580 <H4><A name="3.1">3.1</A>) How do I install PostgreSQL somewhere
581 other than <I>/usr/local/pgsql</I>?</H4>
583 <P>Specify the <I>--prefix</I> option when running
584 <I>configure</I>.</P>
586 <H4><A name="3.2">3.2</A>) When I start <I>postmaster</I>, I get a
587 <I>Bad System Call</I> or core dumped message. Why?</H4>
589 <P>It could be a variety of problems, but first check to see that
590 you have System V extensions installed in your kernel. PostgreSQL
591 requires kernel support for shared memory and semaphores.</P>
593 <H4><A name="3.3">3.3</A>) When I try to start <I>postmaster</I>, I
594 get <I>IpcMemoryCreate</I> errors. Why?</H4>
596 <P>You either do not have shared memory configured properly in your
597 kernel or you need to enlarge the shared memory available in the
598 kernel. The exact amount you need depends on your architecture and
599 how many buffers and backend processes you configure for
600 <I>postmaster</I>. For most systems, with default numbers of
601 buffers and processes, you need a minimum of ~1 MB. See the <A
603 "http://www.postgresql.org/idocs/index.php?kernel-resources.html">PostgreSQL
604 Administrator's Guide</A> for more detailed information about
605 shared memory and semaphores.</P>
607 <H4><A name="3.4">3.4</A>) When I try to start <I>postmaster</I>, I
608 get <I>IpcSemaphoreCreate</I> errors. Why?</H4>
610 <P>If the error message is <I>IpcSemaphoreCreate: semget failed (No
611 space left on device)</I> then your kernel is not configured with
612 enough semaphores. Postgres needs one semaphore per potential
613 backend process. A temporary solution is to start <I>postmaster</I>
614 with a smaller limit on the number of backend processes. Use
615 <I>-N</I> with a parameter less than the default of 32. A more
616 permanent solution is to increase your kernel's
617 <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI</SMALL> parameters.</P>
619 <P>Inoperative semaphores can also cause crashes during heavy
622 <P>If the error message is something else, you might not have
623 semaphore support configured in your kernel at all. See the
624 PostgreSQL Administrator's Guide for more detailed information
625 about shared memory and semaphores.</P>
627 <H4><A name="3.5">3.5</A>) How do I control connections from other
630 <P>By default, PostgreSQL only allows connections from the local
631 machine using Unix domain sockets. Other machines will not be able
632 to connect unless you add the <I>-i</I> flag to <I>postmaster</I>,
633 <B>and</B> enable host-based authentication by modifying the file
634 <I>$PGDATA/pg_hba.conf</I> accordingly. This will allow TCP/IP
637 <H4><A name="3.6">3.6</A>) How do I tune the database engine for
638 better performance?</H4>
640 <P>Certainly, indexes can speed up queries. The
641 <SMALL>EXPLAIN</SMALL> command allows you to see how PostgreSQL is
642 interpreting your query, and which indexes are being used.</P>
644 <P>If you are doing many <SMALL>INSERTs</SMALL>, consider doing
645 them in a large batch using the <SMALL>COPY</SMALL> command. This
646 is much faster than individual <SMALL>INSERTS</SMALL>. Second,
647 statements not in a <SMALL>BEGIN WORK/COMMIT</SMALL> transaction
648 block are considered to be in their own transaction. Consider
649 performing several statements in a single transaction block. This
650 reduces the transaction overhead. Also, consider dropping and
651 recreating indexes when making large data changes.</P>
653 <P>There are several tuning options. You can disable <I>fsync()</I>
654 by starting <I>postmaster</I> with a <I>-o -F</I> option. This will
655 prevent <I>fsync()</I>s from flushing to disk after every
658 <P>You can also use the <I>postmaster</I> <I>-B</I> option to
659 increase the number of shared memory buffers used by the backend
660 processes. If you make this parameter too high, the
661 <I>postmaster</I> may not start because you have exceeded your
662 kernel's limit on shared memory space. Each buffer is 8K and the
663 default is 64 buffers.</P>
665 <P>You can also use the backend <I>-S</I> option to increase the
666 maximum amount of memory used by the backend process for temporary
667 sorts. The <I>-S</I> value is measured in kilobytes, and the
668 default is 512 (i.e. 512K).</P>
670 <P>You can also use the <SMALL>CLUSTER</SMALL> command to group
671 data in tables to match an index. See the <SMALL>CLUSTER</SMALL>
672 manual page for more details.</P>
674 <H4><A name="3.7">3.7</A>) What debugging features are
677 <P>PostgreSQL has several features that report status information
678 that can be valuable for debugging purposes.</P>
680 <P>First, by running <I>configure</I> with the --enable-cassert
681 option, many <I>assert()</I>s monitor the progress of the backend
682 and halt the program when something unexpected occurs.</P>
684 <P>Both <I>postmaster</I> and <I>postgres</I> have several debug
685 options available. First, whenever you start <I>postmaster</I>,
686 make sure you send the standard output and error to a log file,
690 ./bin/postmaster >server.log 2>&1 &
693 <P>This will put a server.log file in the top-level PostgreSQL
694 directory. This file contains useful information about problems or
695 errors encountered by the server. <I>Postmaster</I> has a <I>-d</I>
696 option that allows even more detailed information to be reported.
697 The <I>-d</I> option takes a number that specifies the debug level.
698 Be warned that high debug level values generate large log
701 <P>If <I>postmaster</I> is not running, you can actually run the
702 <I>postgres</I> backend from the command line, and type your
703 <SMALL>SQL</SMALL> statement directly. This is recommended
704 <B>only</B> for debugging purposes. Note that a newline terminates
705 the query, not a semicolon. If you have compiled with debugging
706 symbols, you can use a debugger to see what is happening. Because
707 the backend was not started from <I>postmaster</I>, it is not
708 running in an identical environment and locking/backend interaction
709 problems may not be duplicated.</P>
711 <P>If <I>postmaster</I> is running, start <I>psql</I> in one
712 window, then find the <SMALL>PID</SMALL> of the <I>postgres</I>
713 process used by <I>psql</I>. Use a debugger to attach to the
714 <I>postgres</I> <SMALL>PID</SMALL>. You can set breakpoints in the
715 debugger and issue queries from <I>psql</I>. If you are debugging
716 <I>postgres</I> startup, you can set PGOPTIONS="-W n", then start
717 <I>psql</I>. This will cause startup to delay for <I>n</I> seconds
718 so you can attach to the process with the debugger, set any
719 breakpoints, and continue through the startup sequence.</P>
721 <P>The <I>postgres</I> program has <I>-s, -A</I>, and <I>-t</I>
722 options that can be very useful for debugging and performance
725 <P>You can also compile with profiling to see what functions are
726 taking execution time. The backend profile files will be deposited
727 in the <I>pgsql/data/base/dbname</I> directory. The client profile
728 file will be put in the client's current directory. Linux requires
729 a compile with <I>-DLINUX_PROFILE</I> for proper profiling.</P>
731 <H4><A name="3.8">3.8</A>) Why do I get <I>"Sorry, too many
732 clients"</I> when trying to connect?</H4>
734 <P>You need to increase <I>postmaster</I>'s limit on how many
735 concurrent backend processes it can start.</P>
737 <P>The default limit is 32 processes. You can increase it by
738 restarting <I>postmaster</I> with a suitable <I>-N</I> value or
739 modifying <I>postgresql.conf</I>.</P>
741 <P>Note that if you make <I>-N</I> larger than 32, you must also
742 increase <I>-B</I> beyond its default of 64; <I>-B</I> must be at
743 least twice <I>-N</I>, and probably should be more than that for
744 best performance. For large numbers of backend processes, you are
745 also likely to find that you need to increase various Unix kernel
746 configuration parameters. Things to check include the maximum size
747 of shared memory blocks, <SMALL>SHMMAX;</SMALL> the maximum number
748 of semaphores, <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI;</SMALL> the
749 maximum number of processes, <SMALL>NPROC;</SMALL> the maximum
750 number of processes per user, <SMALL>MAXUPRC;</SMALL> and the
751 maximum number of open files, <SMALL>NFILE</SMALL> and
752 <SMALL>NINODE</SMALL>. The reason that PostgreSQL has a limit on
753 the number of allowed backend processes is so your system won't run
754 out of resources.</P>
756 <H4><A name="3.9">3.9</A>) What is in the <I>pgsql_tmp</I> directory?</H4>
758 <P>This directory contains temporary files generated by the query
759 executor. For example, if a sort needs to be done to satisfy an
760 <SMALL>ORDER BY</SMALL> and the sort requires more space than the
761 backend's <I>-S</I> parameter allows, then temporary files are created
762 here to hold the extra data.</P>
764 <P>The temporary files are usually deleted automatically, but might
765 remain if a backend crashes during a sort. A stop and restart of the
766 <I>postmaster</I> will remove files from those directories.</P>
768 <H4><A name="3.10">3.10</A>) Why do I need to do a dump and restore
769 to upgrade between major PostgreSQL releases?</H4>
771 <P>The PostgreSQL team makes only small changes between minor releases,
772 so upgrading from 7.2 to 7.2.1 does not require a dump and restore.
773 However, major releases (e.g. from 7.2 to 7.3) often change the internal
774 format of system tables and data files. These changes are often complex,
775 so we don't maintain backward compatability for data files. A dump outputs
776 data in a generic format that can then be loaded in using the new internal
779 <P>In releases where the on-disk format does not change, the
780 <I>pg_upgrade</I> script can be used to upgrade without a dump/restore.
781 The release notes mention whether <I>pg_upgrade</I> is available for the
786 <H2 align="center">Operational Questions</H2>
788 <H4><A name="4.1">4.1</A>) What is the difference between binary
789 cursors and normal cursors?</H4>
791 <P>See the <SMALL>DECLARE</SMALL> manual page for a
794 <H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
795 first few rows of a query?</H4>
797 <P>See the <SMALL>FETCH</SMALL> manual page, or use
798 <SMALL>SELECT</SMALL> ... <SMALL>LIMIT</SMALL>....</P>
800 <P>The entire query may have to be evaluated, even if you only want
801 the first few rows. Consider using a query that has an <SMALL>ORDER
802 BY</SMALL>. If there is an index that matches the <SMALL>ORDER
803 BY</SMALL>, PostgreSQL may be able to evaluate only the first few
804 records requested, or the entire query may have to be evaluated
805 until the desired rows have been generated.</P>
807 <H4><A name="4.3">4.3</A>) How do I get a list of tables or other
808 things I can see in <I>psql</I>?</H4>
810 <P>You can read the source code for <I>psql</I> in file
811 <I>pgsql/src/bin/psql/describe.c</I>. It contains
812 <SMALL>SQL</SMALL> commands that generate the output for psql's
813 backslash commands. You can also start <I>psql</I> with the
814 <I>-E</I> option so it will print out the queries it uses to
815 execute the commands you give.</P>
817 <H4><A name="4.4">4.4</A>) How do you remove a column from a
820 <P>This functionality was added in release 7.3 with
821 <SMALL>ALTER TABLE DROP COLUMN</SMALL>. In earlier versions,
825 LOCK TABLE old_table;
826 SELECT ... -- select all columns but the one you want to remove
829 DROP TABLE old_table;
830 ALTER TABLE new_table RENAME TO old_table;
834 <H4><A name="4.5">4.5</A>) What is the maximum size for a row, a
835 table, and a database?</H4>
837 <P>These are the limits:</P>
839 Maximum size for a database? unlimited (1 TB databases exist)
840 Maximum size for a table? 16 TB
841 Maximum size for a row? 1.6TB
842 Maximum size for a field? 1 GB
843 Maximum number of rows in a table? unlimited
844 Maximum number of columns in a table? 250-1600 depending on column types
845 Maximum number of indexes on a table? unlimited
848 Of course, these are not actually unlimited, but limited to
849 available disk space and memory/swap space. Performance may suffer
850 when these values get unusually large.
852 <P>The maximum table size of 16 TB does not require large file
853 support from the operating system. Large tables are stored as
854 multiple 1 GB files so file system size limits are not
857 <P>The maximum table size and maximum number of columns can be
858 increased if the default block size is increased to 32k.</P>
860 <H4><A name="4.6">4.6</A>) How much database disk space is required
861 to store data from a typical text file?</H4>
863 <P>A PostgreSQL database may require up to five times the disk
864 space to store data from a text file.</P>
866 <P>As an example, consider a file of 100,000 lines with an integer
867 and text description on each line. Suppose the text string
868 avergages twenty bytes in length. The flat file would be 2.8 MB.
869 The size of the PostgreSQL database file containing this data can
870 be estimated as 6.4 MB:</P>
872 36 bytes: each row header (approximate)
873 24 bytes: one int field and one text field
874 + 4 bytes: pointer on page to tuple
875 ----------------------------------------
878 The data page size in PostgreSQL is 8192 bytes (8 KB), so:
881 ------------------- = 128 rows per database page (rounded down)
885 -------------------- = 782 database pages (rounded up)
888 782 database pages * 8192 bytes per page = 6,406,144 bytes (6.4 MB)
891 <P>Indexes do not require as much overhead, but do contain the data
892 that is being indexed, so they can be large also.</P>
894 <P><SMALL>NULL</SMALL>s are stored in bitmaps, so they
895 use very little space.</P>
897 <H4><A name="4.7">4.7</A>) How do I find out what tables, indexes,
898 databases, and users are defined?</H4>
900 <P><I>psql</I> has a variety of backslash commands to show such
901 information. Use \? to see them. There are also system tables
902 beginning with <I>pg_</I> that describe these too. Also, <I>psql
903 -l</I> will list all databases.</P>
905 <P>Also try the file <I>pgsql/src/tutorial/syscat.source</I>. It
906 illustrates many of the <SMALL>SELECT</SMALL>s needed to get
907 information from the database system tables.</P>
909 <H4><A name="4.8">4.8</A>) My queries are slow or don't make use of
910 the indexes. Why?</H4>
911 Indexes are not automatically used by every query. Indexes are only
912 used if the table is larger than a minimum size, and the query
913 selects only a small percentage of the rows in the table. This is
914 because the random disk access caused by an index scan can be
915 slower than a straight read through the table, or sequential scan.
917 <P>To determine if an index should be used, PostgreSQL must have
918 statistics about the table. These statistics are collected using
919 <SMALL>VACUUM ANALYZE</SMALL>, or simply <SMALL>ANALYZE</SMALL>.
920 Using statistics, the optimizer knows how many rows are in the
921 table, and can better determine if indexes should be used.
922 Statistics are also valuable in determining optimal join order and
923 join methods. Statistics collection should be performed
924 periodically as the contents of the table change.</P>
926 <P>Indexes are normally not used for <SMALL>ORDER BY</SMALL> or to
927 perform joins. A sequential scan followed by an explicit sort is
928 usually faster than an index scan of a large table.</P>
929 However, <SMALL>LIMIT</SMALL> combined with <SMALL>ORDER BY</SMALL>
930 often will use an index because only a small portion of the table
931 is returned. In fact, though MAX() and MIN() don't use indexes,
932 it is possible to retrieve such values using an index with ORDER BY
937 ORDER BY col [ DESC ]
941 <P>If you believe the optimizer is incorrect in choosing a
942 sequential scan, use <CODE>SET enable_seqscan TO 'off'</CODE> and
943 run tests to see if an index scan is indeed faster.</P>
945 <P>When using wild-card operators such as <SMALL>LIKE</SMALL> or
946 <I>~</I>, indexes can only be used in certain circumstances:</P>
948 <LI>The beginning of the search string must be anchored to the start
951 <LI><SMALL>LIKE</SMALL> patterns must not start with <I>%</I>.</LI>
952 <LI><I>~</I> (regular expression) patterns must start with
955 <LI>The search string can not start with a character class,
957 <LI>Case-insensitive searches such as <SMALL>ILIKE</SMALL> and
958 <I>~*</I> do not utilise indexes. Instead, use functional
959 indexes, which are described in section <a href="#4.12">4.12</a>.</LI>
960 <LI>The default <I>C</I> locale must be used during
965 <H4><A name="4.9">4.9</A>) How do I see how the query optimizer is
966 evaluating my query?</H4>
968 <P>See the <SMALL>EXPLAIN</SMALL> manual page.</P>
970 <H4><A name="4.10">4.10</A>) What is an R-tree index?</H4>
972 <P>An R-tree index is used for indexing spatial data. A hash index
973 can't handle range searches. A B-tree index only handles range
974 searches in a single dimension. R-trees can handle
975 multi-dimensional data. For example, if an R-tree index can be
976 built on an attribute of type <I>point</I>, the system can more
977 efficiently answer queries such as "select all points within a
978 bounding rectangle."</P>
980 <P>The canonical paper that describes the original R-tree design
983 <P>Guttman, A. "R-trees: A Dynamic Index Structure for Spatial
984 Searching." Proceedings of the 1984 ACM SIGMOD Int'l Conf on Mgmt
987 <P>You can also find this paper in Stonebraker's "Readings in
988 Database Systems".</P>
990 <P>Built-in R-trees can handle polygons and boxes. In theory,
991 R-trees can be extended to handle higher number of dimensions. In
992 practice, extending R-trees requires a bit of work and we don't
993 currently have any documentation on how to do it.</P>
995 <H4><A name="4.11">4.11</A>) What is the Genetic Query
998 <P>The <SMALL>GEQO</SMALL> module speeds query optimization when
999 joining many tables by means of a Genetic Algorithm (GA). It allows
1000 the handling of large join queries through nonexhaustive
1003 <H4><A name="4.12">4.12</A>) How do I perform regular expression
1004 searches and case-insensitive regular expression searches? How do I
1005 use an index for case-insensitive searches?</H4>
1007 <P>The <I>~</I> operator does regular expression matching, and
1008 <I>~*</I> does case-insensitive regular expression matching. The
1009 case-insensitive variant of <SMALL>LIKE</SMALL> is called
1010 <SMALL>ILIKE</SMALL>.</P>
1012 <P>Case-insensitive equality comparisons are normally expressed
1017 WHERE lower(col) = 'abc';
1020 This will not use an standard index. However, if you create a
1021 functional index, it will be used:
1023 CREATE INDEX tabindex ON tab (lower(col));
1026 <H4><A name="4.13">4.13</A>) In a query, how do I detect if a field
1027 is <SMALL>NULL</SMALL>?</H4>
1029 <P>You test the column with <SMALL>IS NULL</SMALL> and <SMALL>IS
1030 NOT NULL</SMALL>.</P>
1032 <H4><A name="4.14">4.14</A>) What is the difference between the
1033 various character types?</H4>
1035 Type Internal Name Notes
1036 --------------------------------------------------
1037 VARCHAR(n) varchar size specifies maximum length, no padding
1038 CHAR(n) bpchar blank padded to the specified fixed length
1039 TEXT text no specific upper limit on length
1040 "char" char one character
1041 BYTEA bytea variable-length byte array (null-byte safe)
1044 <P>You will see the internal name when examining system catalogs
1045 and in some error messages.</P>
1047 <P>The last four types above are "varlena" types (i.e., the first
1048 four bytes on disk are the length, followed by the data). Thus the
1049 actual space used is slightly greater than the declared size.
1050 However, these data types are also subject to compression or being
1051 stored out-of-line by <SMALL>TOAST</SMALL>, so the space on disk
1052 might also be less than expected.</P>
1054 <SMALL>VARCHAR(n)</SMALL> is best when storing variable-length
1055 strings and it limits how long a string can be. <SMALL>TEXT</SMALL>
1056 is for strings of unlimited length, with a maximum of one gigabyte.
1057 <P><SMALL>CHAR(n)</SMALL> is for storing strings that are all the
1058 same length. <SMALL>CHAR(n)</SMALL> pads with blanks to the specified
1059 length, while <SMALL>VARCHAR(n)</SMALL> only stores the characters
1060 supplied. <SMALL>BYTEA</SMALL> is for storing binary data,
1061 particularly values that include <SMALL>NULL</SMALL> bytes. These
1062 types have similar performance characteristics.</P>
1064 <H4><A name="4.15.1">4.15.1</A>) How do I create a
1065 serial/auto-incrementing field?</H4>
1067 <P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It
1068 auto-creates a sequence and index on the column. For example,
1071 CREATE TABLE person (
1077 is automatically translated into this:
1079 CREATE SEQUENCE person_id_seq;
1080 CREATE TABLE person (
1081 id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
1084 CREATE UNIQUE INDEX person_id_key ON person ( id );
1087 See the <I>create_sequence</I> manual page for more information
1088 about sequences. You can also use each row's <I>OID</I> field as a
1089 unique value. However, if you need to dump and reload the database,
1090 you need to use <I>pg_dump</I>'s <I>-o</I> option or <SMALL>COPY
1091 WITH OIDS</SMALL> option to preserve the <SMALL>OID</SMALL>s.
1093 <H4><A name="4.15.2">4.15.2</A>) How do I get the value of a
1094 <SMALL>SERIAL</SMALL> insert?</H4>
1096 <P>One approach is to retrieve the next <SMALL>SERIAL</SMALL> value
1097 from the sequence object with the <I>nextval()</I> function
1098 <I>before</I> inserting and then insert it explicitly. Using the
1099 example table in <A href="#4.15.1">4.15.1</A>, an example in a
1100 pseudo-language would look like this:</P>
1102 new_id = execute("SELECT nextval('person_id_seq')");
1103 execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
1106 You would then also have the new value stored in
1107 <CODE>new_id</CODE> for use in other queries (e.g., as a foreign
1108 key to the <CODE>person</CODE> table). Note that the name of the
1109 automatically created <SMALL>SEQUENCE</SMALL> object will be named
1110 <<I>table</I>>_<<I>serialcolumn</I>>_<I>seq</I>, where
1111 <I>table</I> and <I>serialcolumn</I> are the names of your table
1112 and your <SMALL>SERIAL</SMALL> column, respectively.
1114 <P>Alternatively, you could retrieve the assigned
1115 <SMALL>SERIAL</SMALL> value with the <I>currval()</I> function
1116 <I>after</I> it was inserted by default, e.g.,</P>
1118 execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
1119 new_id = execute("SELECT currval('person_id_seq')");
1122 Finally, you could use the <A href="#4.16"><SMALL>OID</SMALL></A>
1123 returned from the <SMALL>INSERT</SMALL> statement to look up the
1124 default value, though this is probably the least portable approach.
1125 In Perl, using DBI with Edmund Mergl's DBD::Pg module, the oid
1126 value is made available via <I>$sth->{pg_oid_status}</I> after
1127 <I>$sth->execute()</I>.
1129 <H4><A name="4.15.3">4.15.3</A>) Don't <I>currval()</I> and
1130 <I>nextval()</I> lead to a race condition with other users?</H4>
1132 <P>No. <I>currval()</I> returns the current value assigned by your
1133 backend, not by all users.</P>
1135 <H4><A name="4.15.4">4.15.4</A>) Why aren't my sequence numbers
1136 reused on transaction abort? Why are there gaps in the numbering of
1137 my sequence/SERIAL column?</H4>
1139 <P>To improve concurrency, sequence values are given out to running
1140 transactions as needed and are not locked until the transaction
1141 completes. This causes gaps in numbering from aborted
1144 <H4><A name="4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is
1145 a <SMALL>TID</SMALL>?</H4>
1147 <P><SMALL>OID</SMALL>s are PostgreSQL's answer to unique row ids.
1148 Every row that is created in PostgreSQL gets a unique
1149 <SMALL>OID</SMALL>. All <SMALL>OID</SMALL>s generated during
1150 <I>initdb</I> are less than 16384 (from
1151 <I>include/access/transam.h</I>). All user-created
1152 <SMALL>OID</SMALL>s are equal to or greater than this. By default,
1153 all these <SMALL>OID</SMALL>s are unique not only within a table or
1154 database, but unique within the entire PostgreSQL installation.</P>
1156 <P>PostgreSQL uses <SMALL>OID</SMALL>s in its internal system
1157 tables to link rows between tables. These <SMALL>OID</SMALL>s can
1158 be used to identify specific user rows and used in joins. It is
1159 recommended you use column type <SMALL>OID</SMALL> to store
1160 <SMALL>OID</SMALL> values. You can create an index on the
1161 <SMALL>OID</SMALL> field for faster access.</P>
1163 <P>O<SMALL>ID</SMALL>s are assigned to all new rows from a central
1164 area that is used by all databases. If you want to change the
1165 <SMALL>OID</SMALL> to something else, or if you want to make a copy
1166 of the table, with the original <SMALL>OID</SMALL>s, there is no
1167 reason you can't do it:</P>
1169 CREATE TABLE new_table(old_oid oid, mycol int);
1170 SELECT old_oid, mycol INTO new FROM old;
1171 COPY new TO '/tmp/pgtable';
1173 COPY new WITH OIDS FROM '/tmp/pgtable';
1176 CREATE TABLE new_table (mycol int);
1177 INSERT INTO new_table (oid, mycol) SELECT oid, mycol FROM old_table;
1179 <P>O<SMALL>ID</SMALL>s are stored as 4-byte integers, and will
1180 overflow at 4 billion. No one has reported this ever happening, and
1181 we plan to have the limit removed before anyone does.</P>
1183 <P>T<SMALL>ID</SMALL>s are used to identify specific physical rows
1184 with block and offset values. T<SMALL>ID</SMALL>s change after rows
1185 are modified or reloaded. They are used by index entries to point
1186 to physical rows.</P>
1188 <H4><A name="4.17">4.17</A>) What is the meaning of some of the
1189 terms used in PostgreSQL?</H4>
1191 <P>Some of the source code and older documentation use terms that
1192 have more common usage. Here are some:</P>
1195 <LI>table, relation, class</LI>
1197 <LI>row, record, tuple</LI>
1199 <LI>column, field, attribute</LI>
1201 <LI>retrieve, select</LI>
1203 <LI>replace, update</LI>
1205 <LI>append, insert</LI>
1207 <LI><SMALL>OID</SMALL>, serial value</LI>
1209 <LI>portal, cursor</LI>
1211 <LI>range variable, table name, table alias</LI>
1214 <P>A list of general database terms can be found at: <A href=
1215 "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>
1217 <H4><A name="4.18">4.18</A>) Why do I get the error <I>"ERROR:
1218 Memory exhausted in AllocSetAlloc()"</I>?</H4>
1220 <P>You probably have run out of virtual memory on your system,
1221 or your kernel has a low limit for certain resources. Try this
1222 before starting <I>postmaster</I>:</P>
1228 Depending on your shell, only one of these may succeed, but it will
1229 set your process data segment limit much higher and perhaps allow
1230 the query to complete. This command applies to the current process,
1231 and all subprocesses created after the command is run. If you are
1232 having a problem with the <SMALL>SQL</SMALL> client because the
1233 backend is returning too much data, try it before starting the
1236 <H4><A name="4.19">4.19</A>) How do I tell what PostgreSQL version
1239 <P>From <I>psql</I>, type <CODE>SELECT version();</CODE></P>
1241 <H4><A name="4.20">4.20</A>) Why does my large-object operations
1242 get <I>"invalid large obj descriptor"</I>?</H4>
1244 <P>You need to put <CODE>BEGIN WORK</CODE> and <CODE>COMMIT</CODE>
1245 around any use of a large object handle, that is, surrounding
1246 <CODE>lo_open</CODE> ... <CODE>lo_close.</CODE></P>
1248 <P>Currently PostgreSQL enforces the rule by closing large object
1249 handles at transaction commit. So the first attempt to do anything
1250 with the handle will draw <I>invalid large obj descriptor</I>. So
1251 code that used to work (at least most of the time) will now
1252 generate that error message if you fail to use a transaction.</P>
1254 <P>If you are using a client interface like <SMALL>ODBC</SMALL> you
1255 may need to set <CODE>auto-commit off.</CODE></P>
1257 <H4><A name="4.21">4.21</A>) How do I create a column that will
1258 default to the current time?</H4>
1260 <P>Use <I>CURRENT_TIMESTAMP</I>:</P>
1262 <CODE>CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
1266 <H4><A name="4.22">4.22</A>) Why are my subqueries using
1267 <CODE><SMALL>IN</SMALL></CODE> so slow?</H4>
1269 <P>Currently, we join subqueries to outer queries by sequentially
1270 scanning the result of the subquery for each row of the outer
1271 query. If the subquery returns only a few rows and the outer query
1272 returns many rows, <CODE><SMALL>IN</SMALL></CODE> is fastest. To
1273 speed up other queries, replace <CODE>IN</CODE> with
1274 <CODE>EXISTS</CODE>:</P>
1277 WHERE col IN (SELECT subcol FROM subtab);
1282 WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col);
1285 For this to be fast, <CODE>subcol</CODE> should be an indexed column.
1286 This preformance problem will be fixed in 7.4.
1288 <H4><A name="4.23">4.23</A>) How do I perform an outer join?</H4>
1290 <P>PostgreSQL supports outer joins using the SQL standard syntax.
1291 Here are two examples:</P>
1294 FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
1299 FROM t1 LEFT OUTER JOIN t2 USING (col);
1302 <P>These identical queries join t1.col to t2.col, and also return
1303 any unjoined rows in t1 (those with no match in t2). A
1304 <SMALL>RIGHT</SMALL> join would add unjoined rows of t2. A
1305 <SMALL>FULL</SMALL> join would return the matched rows plus all
1306 unjoined rows from t1 and t2. The word <SMALL>OUTER</SMALL> is
1307 optional and is assumed in <SMALL>LEFT</SMALL>,
1308 <SMALL>RIGHT</SMALL>, and <SMALL>FULL</SMALL> joins. Ordinary joins
1309 are called <SMALL>INNER</SMALL> joins.</P>
1311 <P>In previous releases, outer joins can be simulated using
1312 <SMALL>UNION</SMALL> and <SMALL>NOT IN</SMALL>. For example, when
1313 joining <I>tab1</I> and <I>tab2</I>, the following query does an
1314 <I>outer</I> join of the two tables:<BR>
1318 SELECT tab1.col1, tab2.col2
1320 WHERE tab1.col1 = tab2.col1
1322 SELECT tab1.col1, NULL
1324 WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
1328 <H4><A name="4.24">4.24</A>) How do I perform queries using
1329 multiple databases?</H4>
1331 <P>There is no way to query a database other than the current one.
1332 Because PostgreSQL loads database-specific system catalogs, it is
1333 uncertain how a cross-database query should even behave.</P>
1335 <P><I>contrib/dblink</I> allows cross-database queries using
1336 function calls. Of course, a client can make simultaneous
1337 connections to different databases and merge the results on the
1340 <H4><A name="4.25">4.25</A>) How do I return multiple rows or
1341 columns from a function?</H4>
1343 <P>You can return result sets from PL/pgSQL functions using
1344 <I>refcursors</I>. See <A href=
1345 "http://www.PostgreSQL.org/idocs/index.php?plpgsql-cursors.html">
1346 http://www.PostgreSQL.org/idocs/index.php?plpgsql-cursors.html</A>,
1347 section 23.7.3.3.</P>
1349 <H4><A name="4.26">4.26</A>) Why can't I reliably create/drop
1350 temporary tables in PL/PgSQL functions?</H4>
1351 <P>PL/PgSQL caches function contents, and an unfortunate side effect
1352 is that if a PL/PgSQL function accesses a temporary table, and that
1353 table is later dropped and recreated, and the function called
1354 again, the function will fail because the cached function contents
1355 still point to the old temporary table. The solution is to use
1356 <SMALL>EXECUTE</SMALL> for temporary table access in PL/PgSQL. This
1357 will cause the query to be reparsed every time.</P>
1359 <H4><A name="4.27">4.27</A>) What replication options are available?
1361 <P>There are several master/slave replication options available.
1362 These allow only the master to make database changes and the slave
1363 can only do database reads. The bottom of <a
1364 href="http://gborg.PostgreSQL.org/genpage?replication_research">
1365 http://gborg.PostgreSQL.org/genpage?replication_research</a> lists
1366 them. A multi-master replication solution is being worked on at <a
1367 href="http://gborg.PostgreSQL.org/project/pgreplication/projdisplay.php">http://gborg.PostgreSQL.org/project/pgreplication/projdisplay.php</a>.</P>
1369 <H4><A name="4.28">4.28</A>) What encryption options are available?
1372 <LI><I>contrib/pgcrypto</I> contains many encryption functions for
1373 use in <SMALL>SQL</SMALL> queries.</LI>
1374 <LI>The only way to encrypt transmission from the client to the
1375 server is by using <I>hostssl</I> in <I>pg_hba.conf</I>.</LI>
1376 <LI>Database user passwords are automatically encrypted when stored
1377 in version 7.3. In previous versions, you must enable the option
1378 <I>PASSWORD_ENCRYPTION</I> in <I>postgresql.conf</I>.</LI>
1379 <LI>The server can run using an encrypted file system.</LI>
1384 <H2 align="center">Extending PostgreSQL</H2>
1386 <H4><A name="5.1">5.1</A>) I wrote a user-defined function. When I
1387 run it in <I>psql</I>, why does it dump core?</H4>
1389 <P>The problem could be a number of things. Try testing your
1390 user-defined function in a stand-alone test program first.</P>
1392 <H4><A name="5.2">5.2</A>) How can I contribute some nifty new
1393 types and functions to PostgreSQL?</H4>
1395 <P>Send your extensions to the <I>pgsql-hackers</I> mailing list,
1396 and they will eventually end up in the <I>contrib/</I>
1399 <H4><A name="5.3">5.3</A>) How do I write a C function to return a
1402 <P>In versions of PostgreSQL beginning with 7.3, table-returning
1403 functions are fully supported in C, PL/PgSQL, and SQL. See the
1404 Programmer's Guide for more information. An example of a
1405 table-returning function defined in C can be found in
1406 <I>contrib/tablefunc</I>.</P>
1408 <H4><A name="5.4">5.4</A>) I have changed a source file. Why does
1409 the recompile not see the change?</H4>
1411 <P>The <I>Makefiles</I> do not have the proper dependencies for
1412 include files. You have to do a <I>make clean</I> and then another
1413 <I>make</I>. If you are using <SMALL>GCC</SMALL> you can use the
1414 <I>--enable-depend</I> option of <I>configure</I> to have the
1415 compiler compute the dependencies automatically.</P>