1 <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 transitional//EN">
4 <!-- DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN" -->
8 <META name="generator" content="HTML Tidy, see www.w3.org">
10 <TITLE>PostgreSQL FAQ</TITLE>
13 <BODY bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000"
15 <H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
17 <P>Last updated: Tue Jun 11 06:29:44 EDT 2002</P>
19 <P>Current maintainer: Bruce Momjian (<A href=
20 "mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
23 <P>The most recent version of this document can be viewed at <A
25 "http://www.Postgresql.org/docs/faq-english.html">http://www.PostgreSQL.org/docs/faq-english.html</A>.</P>
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>
31 <H2 align="center">General Questions</H2>
32 <A href="#1.1">1.1</A>) What is PostgreSQL? How is it
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
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
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
54 <H2 align="center">User Client Questions</H2>
55 <A href="#2.1">2.1</A>) Are there <SMALL>ODBC</SMALL> drivers for
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
62 <A href="#2.4">2.4</A>) What languages are available to
63 communicate with PostgreSQL?<BR>
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
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>
86 <H2 align="center">Operational Questions</H2>
87 <A href="#4.1">4.1</A>) What is the difference between binary
88 cursors and normal cursors?<BR>
89 <A href="#4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
90 first few rows of a query?<BR>
91 <A href="#4.3">4.3</A>) How do I get a list of tables or other
92 things I can see in <I>psql</I>?<BR>
93 <A href="#4.4">4.4</A>) How do you remove a column from a
95 <A href="#4.5">4.5</A>) What is the maximum size for a row, a
96 table, and a database?<BR>
97 <A href="#4.6">4.6</A>) How much database disk space is required
98 to store data from a typical text file?<BR>
99 <A href="#4.7">4.7</A>) How do I find out what tables, indexes,
100 databases, and users are defined?<BR>
101 <A href="#4.8">4.8</A>) My queries are slow or don't make use of
102 the indexes. Why?<BR>
103 <A href="#4.9">4.9</A>) How do I see how the query optimizer is
104 evaluating my query?<BR>
105 <A href="#4.10">4.10</A>) What is an R-tree index?<BR>
106 <A href="#4.11">4.11</A>) What is the Genetic Query Optimizer?<BR>
107 <A href="#4.12">4.12</A>) How do I perform regular expression
108 searches and case-insensitive regular expression searches? How do I
109 use an index for case-insensitive searches?<BR>
110 <A href="#4.13">4.13</A>) In a query, how do I detect if a field
111 is <SMALL>NULL</SMALL>?<BR>
112 <A href="#4.14">4.14</A>) What is the difference between the
113 various character types?<BR>
114 <A href="#4.15.1">4.15.1</A>) How do I create a
115 serial/auto-incrementing field?<BR>
116 <A href="#4.15.2">4.15.2</A>) How do I get the value of a
117 <SMALL>SERIAL</SMALL> insert?<BR>
118 <A href="#4.15.3">4.15.3</A>) Don't <I>currval()</I> and
119 <I>nextval()</I> lead to a race condition with other users?<BR>
120 <A href="#4.15.4">4.15.4</A>) Why aren't my sequence numbers
121 reused on transaction abort? Why are there gaps in the numbering of
122 my sequence/SERIAL column?<BR>
123 <A href="#4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is a
124 <SMALL>TID</SMALL>?<BR>
125 <A href="#4.17">4.17</A>) What is the meaning of some of the terms
126 used in PostgreSQL?<BR>
127 <A href="#4.18">4.18</A>) Why do I get the error <I>"ERROR: Memory
128 exhausted in AllocSetAlloc()"</I>?<BR>
129 <A href="#4.19">4.19</A>) How do I tell what PostgreSQL version I
131 <A href="#4.20">4.20</A>) Why does my large-object operations get
132 <I>"invalid large obj descriptor"</I>?<BR>
133 <A href="#4.21">4.21</A>) How do I create a column that will
134 default to the current time?<BR>
135 <A href="#4.22">4.22</A>) Why are my subqueries using
136 <CODE><SMALL>IN</SMALL></CODE> so slow?<BR>
137 <A href="#4.23">4.23</A>) How do I perform an outer join?<BR>
138 <A href="#4.24">4.24</A>) How do I perform queries using multiple
140 <A href="#4.25">4.25</A>) How do I return multiple rows or columns
142 <A href="#4.26">4.26</A>) Why can't I reliably create/drop
143 temporary tables in PL/PgSQL functions?<BR>
146 <H2 align="center">Extending PostgreSQL</H2>
147 <A href="#5.1">5.1</A>) I wrote a user-defined function. When I run
148 it in <I>psql</I>, why does it dump core?<BR>
149 <A href="#5.2">5.2</A>) How can I contribute some nifty new types
150 and functions to PostgreSQL?<BR>
151 <A href="#5.3">5.3</A>) How do I write a C function to return a
153 <A href="#5.4">5.4</A>) I have changed a source file. Why does the
154 recompile not see the change?<BR>
158 <H2 align="center">General Questions</H2>
160 <H4><A name="1.1">1.1</A>) What is PostgreSQL?</H4>
162 <P>PostgreSQL is pronounced <I>Post-Gres-Q-L</I>.</P>
164 <P>PostgreSQL is an enhancement of the POSTGRES database management
165 system, a next-generation <SMALL>DBMS</SMALL> research prototype.
166 While PostgreSQL retains the powerful data model and rich data
167 types of POSTGRES, it replaces the PostQuel query language with an
168 extended subset of <SMALL>SQL</SMALL>. PostgreSQL is free and the
169 complete source is available.</P>
171 <P>PostgreSQL development is performed by a team of Internet
172 developers who all subscribe to the PostgreSQL development mailing
173 list. The current coordinator is Marc G. Fournier (<A href=
174 "mailto:scrappy@PostgreSQL.org">scrappy@PostgreSQL.org</A>). (See
175 below on how to join). This team is now responsible for all
176 development of PostgreSQL.</P>
178 <P>The authors of PostgreSQL 1.01 were Andrew Yu and Jolly Chen.
179 Many others have contributed to the porting, testing, debugging,
180 and enhancement of the code. The original Postgres code, from which
181 PostgreSQL is derived, was the effort of many graduate students,
182 undergraduate students, and staff programmers working under the
183 direction of Professor Michael Stonebraker at the University of
184 California, Berkeley.</P>
186 <P>The original name of the software at Berkeley was Postgres. When
187 <SMALL>SQL</SMALL> functionality was added in 1995, its name was
188 changed to Postgres95. The name was changed at the end of 1996 to
191 <H4><A name="1.2">1.2</A>) What is the copyright on
194 <P>PostgreSQL is subject to the following COPYRIGHT:</P>
196 <P>PostgreSQL Data Base Management System</P>
198 <P>Portions copyright (c) 1996-2002, PostgreSQL Global Development
199 Group Portions Copyright (c) 1994-6 Regents of the University of
202 <P>Permission to use, copy, modify, and distribute this software
203 and its documentation for any purpose, without fee, and without a
204 written agreement is hereby granted, provided that the above
205 copyright notice and this paragraph and the following two
206 paragraphs appear in all copies.</P>
208 <P>IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
209 PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
210 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
211 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
212 CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</P>
214 <P>THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
215 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
216 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
217 SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
218 UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
219 SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.</P>
221 <P>The above is the BSD license, the classic open-source license.
222 It has no restrictions on how the source code may be used. We like
223 it and have no intention of changing it.</P>
225 <H4><A name="1.3">1.3</A>) What Unix platforms does PostgreSQL run
228 <P>In general, a modern Unix-compatible platform should be able to
229 run PostgreSQL. The platforms that had received explicit testing at
230 the time of release are listed in the installation
233 <H4><A name="1.4">1.4</A>) What non-Unix ports are available?</H4>
235 <P><STRONG>Client</STRONG></P>
237 <P>It is possible to compile the <I>libpq</I> C library, psql, and
238 other interfaces and binaries to run on MS Windows platforms. In
239 this case, the client is running on MS Windows, and communicates
240 via TCP/IP to a server running on one of our supported Unix
241 platforms. A file <I>win31.mak</I> is included in the distribution
242 for making a Win32 <I>libpq</I> library and <I>psql</I>. PostgreSQL
243 also communicates with <SMALL>ODBC</SMALL> clients.</P>
245 <P><STRONG>Server</STRONG></P>
247 <P>The database server can run on Windows NT and Win2k using
248 Cygwin, the Cygnus Unix/NT porting library. See
249 <I>pgsql/doc/FAQ_MSWIN</I> in the distribution or the <A href=
250 "http://www.postgresql.org/docs/faq-mswin.html">MS Windows FAQ</A>
251 on our web site. We have no plan to do a native port to any
252 Microsoft platform.</P>
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>
283 Digests are sent out to members of this list whenever the main list
284 has received around 30k of messages.
286 <P>The bugs mailing list is available. To subscribe to this list,
287 send email to <A href=
288 "mailto:pgsql-bugs-request@PostgreSQL.org">pgsql-bugs-request@PostgreSQL.org</A>
294 There is also a developers discussion mailing list available. To
295 subscribe to this list, send email to <A href=
296 "mailto:pgsql-hackers-request@PostgreSQL.org">pgsql-hackers-request@PostgreSQL.org</A>
303 <P>Additional mailing lists and information about PostgreSQL can be
304 found via the PostgreSQL WWW home page at:</P>
307 <A href="http://www.PostgreSQL.org">http://www.PostgreSQL.org</A>
310 <P>There is also an IRC channel on EFNet, channel
311 <I>#PostgreSQL</I>. I use the Unix command <CODE>irc -c
312 '#PostgreSQL' "$USER" irc.phoenix.net.</CODE></P>
314 <P>A list of commercial support companies is available at <A href=
315 "http://www.postgresql.org/users-lounge/commercial-support.html">http://www.postgresql.org/users-lounge/commercial-support.html</A>.</P>
317 <H4><A name="1.7">1.7</A>) What is the latest release?</H4>
319 <P>The latest release of PostgreSQL is version 7.2.1.</P>
321 <P>We plan to have major releases every four months.</P>
323 <H4><A name="1.8">1.8</A>) What documentation is available?</H4>
325 <P>Several manuals, manual pages, and some small test examples are
326 included in the distribution. See the <I>/doc</I> directory. You
327 can also browse the manual online at <A href=
328 "http://www.PostgreSQL.org/users-lounge/docs/">http://www.PostgreSQL.org/users-lounge/docs/</A>.</P>
330 <P>There are two PostgreSQL books available online at <A href=
331 "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
333 "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook/</A>.
334 There is a list of PostgreSQL books available for purchase at <A
336 "http://www.postgresql.org/books/">http://www.postgresql.org/books/</A>.
337 There is also a collection of PostgreSQL technical articles at <A
339 "http://techdocs.postgresql.org/">http://techdocs.postgresql.org/</A>.</P>
341 <P><I>psql</I> has some nice \d commands to show information about
342 types, operators, functions, aggregates, etc.</P>
344 <P>Our web site contains even more documentation.</P>
346 <H4><A name="1.9">1.9</A>) How do I find out about known bugs or
347 missing features?</H4>
349 <P>PostgreSQL supports an extended subset of <SMALL>SQL</SMALL>-92.
350 See our <A href="http://developer.PostgreSQL.org/todo.php">TODO</A>
351 list for known bugs, missing features, and future plans.</P>
353 <H4><A name="1.10">1.10</A>) How can I learn
354 <SMALL>SQL</SMALL>?</H4>
356 <P>The PostgreSQL book at <A href=
357 "http://www.PostgreSQL.org/docs/awbook.html">http://www.PostgreSQL.org/docs/awbook.html</A>
358 teaches <SMALL>SQL</SMALL>. There is another PostgreSQL book at <A
360 "http://www.commandprompt.com/ppbook/">http://www.commandprompt.com/ppbook.</A>
361 There is a nice tutorial at <A href=
362 "http://www.intermedia.net/support/sql/sqltut.shtm">http://www.intermedia.net/support/sql/sqltut.shtm,</A>
364 "http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM">
365 http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM,</A>
367 "http://sqlcourse.com/">http://sqlcourse.com.</A></P>
369 <P>Another one is "Teach Yourself SQL in 21 Days, Second Edition"
371 "http://members.tripod.com/er4ebus/sql/index.htm">http://members.tripod.com/er4ebus/sql/index.htm</A></P>
373 <P>Many of our users like <I>The Practical SQL Handbook</I>,
374 Bowman, Judith S., et al., Addison-Wesley. Others like <I>The
375 Complete Reference SQL</I>, Groff et al., McGraw-Hill.</P>
377 <H4><A name="1.11">1.11</A>) Is PostgreSQL Y2K compliant?</H4>
379 <P>Yes, we easily handle dates past the year 2000 AD, and before
382 <H4><A name="1.12">1.12</A>) How do I join the development
385 <P>First, download the latest source and read the PostgreSQL
386 Developers documentation on our web site, or in the distribution.
387 Second, subscribe to the <I>pgsql-hackers</I> and
388 <I>pgsql-patches</I> mailing lists. Third, submit high quality
389 patches to pgsql-patches.</P>
391 <P>There are about a dozen people who have commit privileges to the
392 PostgreSQL <SMALL>CVS</SMALL> archive. They each have submitted so
393 many high-quality patches that it was impossible for the existing
394 committers to keep up, and we had confidence that patches they
395 committed were of high quality.</P>
397 <H4><A name="1.13">1.13</A>) How do I submit a bug report?</H4>
399 <P>Please visit the <A href=
400 "http://www.postgresql.org/bugs/bugs.php">PostgreSQL BugTool</A>
401 page, which gives guidelines and directions on how to submit a
404 <P>Also check out our ftp site <A href=
405 "ftp://ftp.PostgreSQL.org/pub">ftp://ftp.PostgreSQL.org/pub</A> to
406 see if there is a more recent PostgreSQL version or patches.</P>
408 <H4><A name="1.14">1.14</A>) How does PostgreSQL compare to other
409 <SMALL>DBMS</SMALL>s?</H4>
411 <P>There are several ways of measuring software: features,
412 performance, reliability, support, and price.</P>
415 <DT><B>Features</B></DT>
417 <DD>PostgreSQL has most features present in large commercial
418 <SMALL>DBMS</SMALL>s, like transactions, subselects, triggers,
419 views, foreign key referential integrity, and sophisticated
420 locking. We have some features they do not have, like
421 user-defined types, inheritance, rules, and multi-version
422 concurrency control to reduce lock contention.<BR>
426 <DT><B>Performance</B></DT>
428 <DD>PostgreSQL has performance similar to other commercial and
429 open source databases. it is faster for some things, slower for
430 others. In comparison to MySQL or leaner database systems, we are
431 slower on inserts/updates because of transaction overhead. Of
432 course, MySQL does not have any of the features mentioned in the
433 <I>Features</I> section above. We are built for reliability and
434 features, though we continue to improve performance in every
435 release. There is an interesting Web page comparing PostgreSQL to
436 MySQL at <A href= "http://openacs.org/why-not-mysql.html">
438 http://openacs.org/why-not-mysql.html</A><BR>
443 <DT><B>Reliability</B></DT>
445 <DD>We realize that a <SMALL>DBMS</SMALL> must be reliable, or it
446 is worthless. We strive to release well-tested, stable code that
447 has a minimum of bugs. Each release has at least one month of
448 beta testing, and our release history shows that we can provide
449 stable, solid releases that are ready for production use. We
450 believe we compare favorably to other database software in this
455 <DT><B>Support</B></DT>
457 <DD>Our mailing list provides a large group of developers and
458 users to help resolve any problems encountered. While we can not
459 guarantee a fix, commercial <SMALL>DBMS</SMALL>s do not always
460 supply a fix either. Direct access to developers, the user
461 community, manuals, and the source code often make PostgreSQL
462 support superior to other <SMALL>DBMS</SMALL>s. There is
463 commercial per-incident support available for those who need it.
464 (See <A href="#1.6">support FAQ item</A>.)<BR>
468 <DT><B>Price</B></DT>
470 <DD>We are free for all use, both commercial and non-commercial.
471 You can add our code to your product with no limitations, except
472 those outlined in our BSD-style license stated above.<BR>
477 <H4><A name="1.15">1.15</A>) How can I financially assist
480 <P>PostgreSQL has had a first-class infrastructure since we started
481 six years ago. This is all thanks to Marc Fournier, who has created
482 and managed this infrastructure over the years.</P>
484 <P>Quality infrastructure is very important to an open-source
485 project. It prevents disruptions that can greatly delay forward
486 movement of the project.</P>
488 <P>Of course, this infrastructure is not cheap. There are a variety
489 of monthly and one-time expenses that are required to keep it
490 going. If you or your company has money it can donate to help fund
491 this effort, please go to <A href=
492 "http://www.pgsql.com/pg_goodies">http://www.pgsql.com/pg_goodies</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>PsqlODBC is included in the distribution. More information about
510 it can be gotten from <A href=
511 "ftp://ftp.PostgreSQL.org/pub/odbc/">ftp://ftp.PostgreSQL.org/pub/odbc/</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 <P>See also the <A href=
525 "http://www.postgresql.org/devel-corner/docs/programmer/odbc.html">ODBC
526 chapter of the Programmer's Guide</A>.</P>
528 <H4><A name="2.2">2.2</A>) What tools are available for using
529 PostgreSQL with Web pages?</H4>
531 <P>A nice introduction to Database-backed Web pages can be seen at:
532 <A href="http://www.webreview.com">http://www.webreview.com</A></P>
534 <P>There is also one at <A href=
535 "http://www.phone.net/home/mwm/hotlist/">http://www.phone.net/home/mwm/hotlist/.</A></P>
537 <P>For Web integration, PHP is an excellent interface. It is at <A
538 href="http://www.php.net">http://www.php.net</A>.</P>
540 <P>For complex cases, many use the Perl interface and CGI.pm.</P>
542 <H4><A name="2.3">2.3</A>) Does PostgreSQL have a graphical user
543 interface? A report generator? An embedded query language
546 <P>We have a nice graphical user interface called <I>pgaccess</I>,
547 which is shipped as part of the distribution. <I>pgaccess</I> also
548 has a report generator. The Web page is <A href=
549 "http://www.flex.ro/pgaccess">http://www.flex.ro/pgaccess</A></P>
551 <P>We also include <I>ecpg</I>, which is an embedded SQL query
552 language interface for C.</P>
554 <H4><A name="2.4">2.4</A>) What languages are available to
555 communicate with PostgreSQL?</H4>
562 <LI>C++ (libpq++)</LI>
564 <LI>Embedded C (ecpg)</LI>
568 <LI>Perl (perl5)</LI>
572 <LI>Python (PyGreSQL)</LI>
574 <LI>TCL (libpgtcl)</LI>
576 <LI>C Easy API (libpgeasy)</LI>
578 <LI>Embedded <SMALL>HTML</SMALL> (<A href=
579 "http://www.php.net">PHP from http://www.php.net</A>)</LI>
583 <H2 align="center">Administrative Questions</H2>
585 <H4><A name="3.1">3.1</A>) How do I install PostgreSQL somewhere
586 other than <I>/usr/local/pgsql</I>?</H4>
588 <P>Specify the <I>--prefix</I> option when running
589 <I>configure</I>.</P>
591 <H4><A name="3.2">3.2</A>) When I start <I>postmaster</I>, I get a
592 <I>Bad System Call</I> or core dumped message. Why?</H4>
594 <P>It could be a variety of problems, but first check to see that
595 you have System V extensions installed in your kernel. PostgreSQL
596 requires kernel support for shared memory and semaphores.</P>
598 <H4><A name="3.3">3.3</A>) When I try to start <I>postmaster</I>, I
599 get <I>IpcMemoryCreate</I> errors. Why?</H4>
601 <P>You either do not have shared memory configured properly in your
602 kernel or you need to enlarge the shared memory available in the
603 kernel. The exact amount you need depends on your architecture and
604 how many buffers and backend processes you configure for
605 <I>postmaster</I>. For most systems, with default numbers of
606 buffers and processes, you need a minimum of ~1 MB. See the <A
608 "http://www.postgresql.org/idocs/index.php?kernel-resources.html">PostgreSQL
609 Administrator's Guide</A> for more detailed information about
610 shared memory and semaphores.</P>
612 <H4><A name="3.4">3.4</A>) When I try to start <I>postmaster</I>, I
613 get <I>IpcSemaphoreCreate</I> errors. Why?</H4>
615 <P>If the error message is <I>IpcSemaphoreCreate: semget failed (No
616 space left on device)</I> then your kernel is not configured with
617 enough semaphores. Postgres needs one semaphore per potential
618 backend process. A temporary solution is to start <I>postmaster</I>
619 with a smaller limit on the number of backend processes. Use
620 <I>-N</I> with a parameter less than the default of 32. A more
621 permanent solution is to increase your kernel's
622 <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI</SMALL> parameters.</P>
624 <P>Inoperative semaphores can also cause crashes during heavy
627 <P>If the error message is something else, you might not have
628 semaphore support configured in your kernel at all. See the
629 PostgreSQL Administrator's Guide for more detailed information
630 about shared memory and semaphores.</P>
632 <H4><A name="3.5">3.5</A>) How do I control connections from other
635 <P>By default, PostgreSQL only allows connections from the local
636 machine using Unix domain sockets. Other machines will not be able
637 to connect unless you add the <I>-i</I> flag to <I>postmaster</I>,
638 <B>and</B> enable host-based authentication by modifying the file
639 <I>$PGDATA/pg_hba.conf</I> accordingly. This will allow TCP/IP
642 <H4><A name="3.6">3.6</A>) How do I tune the database engine for
643 better performance?</H4>
645 <P>Certainly, indexes can speed up queries. The
646 <SMALL>EXPLAIN</SMALL> command allows you to see how PostgreSQL is
647 interpreting your query, and which indexes are being used.</P>
649 <P>If you are doing many <SMALL>INSERTs</SMALL>, consider doing
650 them in a large batch using the <SMALL>COPY</SMALL> command. This
651 is much faster than individual <SMALL>INSERTS.</SMALL> Second,
652 statements not in a <SMALL>BEGIN WORK/COMMIT</SMALL> transaction
653 block are considered to be in their own transaction. Consider
654 performing several statements in a single transaction block. This
655 reduces the transaction overhead. Also, consider dropping and
656 recreating indexes when making large data changes.</P>
658 <P>There are several tuning options. You can disable <I>fsync()</I>
659 by starting <I>postmaster</I> with a <I>-o -F</I> option. This will
660 prevent <I>fsync()</I>s from flushing to disk after every
663 <P>You can also use the <I>postmaster</I> <I>-B</I> option to
664 increase the number of shared memory buffers used by the backend
665 processes. If you make this parameter too high, the
666 <I>postmaster</I> may not start because you have exceeded your
667 kernel's limit on shared memory space. Each buffer is 8K and the
668 default is 64 buffers.</P>
670 <P>You can also use the backend <I>-S</I> option to increase the
671 maximum amount of memory used by the backend process for temporary
672 sorts. The <I>-S</I> value is measured in kilobytes, and the
673 default is 512 (i.e. 512K).</P>
675 <P>You can also use the <SMALL>CLUSTER</SMALL> command to group
676 data in tables to match an index. See the <SMALL>CLUSTER</SMALL>
677 manual page for more details.</P>
679 <H4><A name="3.7">3.7</A>) What debugging features are
682 <P>PostgreSQL has several features that report status information
683 that can be valuable for debugging purposes.</P>
685 <P>First, by running <I>configure</I> with the --enable-cassert
686 option, many <I>assert()</I>s monitor the progress of the backend
687 and halt the program when something unexpected occurs.</P>
689 <P>Both <I>postmaster</I> and <I>postgres</I> have several debug
690 options available. First, whenever you start <I>postmaster</I>,
691 make sure you send the standard output and error to a log file,
695 ./bin/postmaster >server.log 2>&1 &
698 <P>This will put a server.log file in the top-level PostgreSQL
699 directory. This file contains useful information about problems or
700 errors encountered by the server. <I>Postmaster</I> has a <I>-d</I>
701 option that allows even more detailed information to be reported.
702 The <I>-d</I> option takes a number that specifies the debug level.
703 Be warned that high debug level values generate large log
706 <P>If <I>postmaster</I> is not running, you can actually run the
707 <I>postgres</I> backend from the command line, and type your
708 <SMALL>SQL</SMALL> statement directly. This is recommended
709 <B>only</B> for debugging purposes. Note that a newline terminates
710 the query, not a semicolon. If you have compiled with debugging
711 symbols, you can use a debugger to see what is happening. Because
712 the backend was not started from <I>postmaster</I>, it is not
713 running in an identical environment and locking/backend interaction
714 problems may not be duplicated.</P>
716 <P>If <I>postmaster</I> is running, start <I>psql</I> in one
717 window, then find the <SMALL>PID</SMALL> of the <I>postgres</I>
718 process used by <I>psql</I>. Use a debugger to attach to the
719 <I>postgres</I> <SMALL>PID.</SMALL> You can set breakpoints in the
720 debugger and issue queries from <I>psql</I>. If you are debugging
721 <I>postgres</I> startup, you can set PGOPTIONS="-W n", then start
722 <I>psql</I>. This will cause startup to delay for <I>n</I> seconds
723 so you can attach to the process with the debugger, set any
724 breakpoints, and continue through the startup sequence.</P>
726 <P>The <I>postgres</I> program has <I>-s, -A</I>, and <I>-t</I>
727 options that can be very useful for debugging and performance
730 <P>You can also compile with profiling to see what functions are
731 taking execution time. The backend profile files will be deposited
732 in the <I>pgsql/data/base/dbname</I> directory. The client profile
733 file will be put in the client's current directory. Linux requires
734 a compile with <I>-DLINUX_PROFILE</I> for proper profiling.</P>
736 <H4><A name="3.8">3.8</A>) Why do I get <I>"Sorry, too many
737 clients"</I> when trying to connect?</H4>
739 <P>You need to increase <I>postmaster</I>'s limit on how many
740 concurrent backend processes it can start.</P>
742 <P>The default limit is 32 processes. You can increase it by
743 restarting <I>postmaster</I> with a suitable <I>-N</I> value or
744 modifying <I>postgresql.conf</I>.</P>
746 <P>Note that if you make <I>-N</I> larger than 32, you must also
747 increase <I>-B</I> beyond its default of 64; <I>-B</I> must be at
748 least twice <I>-N</I>, and probably should be more than that for
749 best performance. For large numbers of backend processes, you are
750 also likely to find that you need to increase various Unix kernel
751 configuration parameters. Things to check include the maximum size
752 of shared memory blocks, <SMALL>SHMMAX;</SMALL> the maximum number
753 of semaphores, <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI;</SMALL> the
754 maximum number of processes, <SMALL>NPROC;</SMALL> the maximum
755 number of processes per user, <SMALL>MAXUPRC;</SMALL> and the
756 maximum number of open files, <SMALL>NFILE</SMALL> and
757 <SMALL>NINODE.</SMALL> The reason that PostgreSQL has a limit on
758 the number of allowed backend processes is so your system won't run
759 out of resources.</P>
761 <P>In PostgreSQL versions prior to 6.5, the maximum number of
762 backends was 64, and changing it required a rebuild after altering
763 the MaxBackendId constant in
764 <I>include/storage/sinvaladt.h</I>.</P>
766 <H4><A name="3.9">3.9</A>) What are the <I>pg_sorttempNNN.NN</I>
767 files in my database directory?</H4>
769 <P>They are temporary files generated by the query executor. For
770 example, if a sort needs to be done to satisfy an <SMALL>ORDER
771 BY,</SMALL> and the sort requires more space than the backend's
772 <I>-S</I> parameter allows, then temporary files are created to
773 hold the extra data.</P>
775 <P>The temporary files should be deleted automatically, but might
776 not if a backend crashes during a sort. If you have no backends
777 running at the time, it is safe to delete the pg_tempNNN.NN
781 <H2 align="center">Operational Questions</H2>
783 <H4><A name="4.1">4.1</A>) What is the difference between binary
784 cursors and normal cursors?</H4>
786 <P>See the <SMALL>DECLARE</SMALL> manual page for a
789 <H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
790 first few rows of a query?</H4>
792 <P>See the <SMALL>FETCH</SMALL> manual page, or use
793 <SMALL>SELECT</SMALL> ... <SMALL>LIMIT</SMALL>....</P>
795 <P>The entire query may have to be evaluated, even if you only want
796 the first few rows. Consider a query that has an <SMALL>ORDER
797 BY.</SMALL> If there is an index that matches the <SMALL>ORDER
798 BY</SMALL>, PostgreSQL may be able to evaluate only the first few
799 records requested, or the entire query may have to be evaluated
800 until the desired rows have been generated.</P>
802 <H4><A name="4.3">4.3</A>) How do I get a list of tables or other
803 things I can see in <I>psql</I>?</H4>
805 <P>You can read the source code for <I>psql</I> in file
806 <I>pgsql/src/bin/psql/describe.c</I>. It contains
807 <SMALL>SQL</SMALL> commands that generate the output for psql's
808 backslash commands. You can also start <I>psql</I> with the
809 <I>-E</I> option so it will print out the queries it uses to
810 execute the commands you give.</P>
812 <H4><A name="4.4">4.4</A>) How do you remove a column from a
815 <P>We do not support <SMALL>ALTER TABLE DROP COLUMN,</SMALL> but do
819 LOCK TABLE old_table;
820 SELECT ... -- select all columns but the one you want to remove
823 DROP TABLE old_table;
824 ALTER TABLE new_table RENAME TO old_table;
828 <H4><A name="4.5">4.5</A>) What is the maximum size for a row, a
829 table, and a database?</H4>
831 <P>These are the limits:</P>
833 Maximum size for a database? unlimited (500 GB databases exist)
834 Maximum size for a table? 16 TB
835 Maximum size for a row? unlimited in 7.1 and later
836 Maximum size for a field? 1 GB in 7.1 and later
837 Maximum number of rows in a table? unlimited
838 Maximum number of columns in a table? 250-1600 depending on column types
839 Maximum number of indexes on a table? unlimited
841 Of course, these are not actually unlimited, but limited to
842 available disk space and memory/swap space. Performance may suffer
843 when these values get unusually large.
845 <P>The maximum table size of 16 TB does not require large file
846 support from the operating system. Large tables are stored as
847 multiple 1 GB files so file system size limits are not
850 <P>The maximum table size and maximum number of columns can be
851 increased if the default block size is increased to 32k.</P>
853 <H4><A name="4.6">4.6</A>) How much database disk space is required
854 to store data from a typical text file?</H4>
856 <P>A PostgreSQL database may require up to five times the disk
857 space to store data from a text file.</P>
859 <P>As an example, consider a file of 100,000 lines with an integer
860 and text description on each line. Suppose the text string
861 avergages twenty bytes in length. The flat file would be 2.8 MB.
862 The size of the PostgreSQL database file containing this data can
863 be estimated as 6.4 MB:</P>
865 36 bytes: each row header (approximate)
866 24 bytes: one int field and one text filed
867 + 4 bytes: pointer on page to tuple
868 ----------------------------------------
871 The data page size in PostgreSQL is 8192 bytes (8 KB), so:
874 ------------------- = 128 rows per database page (rounded down)
878 -------------------- = 782 database pages (rounded up)
881 782 database pages * 8192 bytes per page = 6,406,144 bytes (6.4 MB)
884 <P>Indexes do not require as much overhead, but do contain the data
885 that is being indexed, so they can be large also.</P>
887 <H4><A name="4.7">4.7</A>) How do I find out what tables, indexes,
888 databases, and users are defined?</H4>
890 <P><I>psql</I> has a variety of backslash commands to show such
891 information. Use \? to see them. There are also system tables
892 beginning with <I>pg_</I> that describe these too. Also, <I>psql
893 -l</I> will list all databases.</P>
895 <P>Also try the file <I>pgsql/src/tutorial/syscat.source</I>. It
896 illustrates many of the <SMALL>SELECT</SMALL>s needed to get
897 information from the database system tables.</P>
899 <H4><A name="4.8">4.8</A>) My queries are slow or don't make use of
900 the indexes. Why?</H4>
901 Indexes are not automatically used by every query. Indexes are only
902 used if the table is larger than a minimum size, and the query
903 selects only a small percentage of the rows in the table. This is
904 because the random disk access caused by an index scan is sometimes
905 slower than a straight read through the table, or sequential scan.
907 <P>To determine if an index should be used, PostgreSQL must have
908 statistics about the table. These statistics are collected using
909 <SMALL>VACUUM ANALYZE</SMALL>, or simply <SMALL>ANALYZE</SMALL>.
910 Using statistics, the optimizer knows how many rows are in the
911 table, and can better determine if indexes should be used.
912 Statistics are also valuable in determining optimal join order and
913 join methods. Statistics collection should be performed
914 periodically as the contents of the table change.</P>
916 <P>Indexes are normally not used for <SMALL>ORDER BY</SMALL> or to
917 perform joins. A sequential scan followed by an explicit sort is
918 usually faster than an index scan of a large table.</P>
919 However, <SMALL>LIMIT</SMALL> combined with <SMALL>ORDER BY</SMALL>
920 often will use an index because only a small portion of the table
923 <P>When using wild-card operators such as <SMALL>LIKE</SMALL> or
924 <I>~</I>, indexes can only be used if the beginning of the search
925 is anchored to the start of the string. Therefore, to use indexes,
926 <SMALL>LIKE</SMALL> patterns must not start with <I>%</I>, and
927 <I>~</I>(regular expression) patterns must start with <I>^</I>.</P>
929 <H4><A name="4.9">4.9</A>) How do I see how the query optimizer is
930 evaluating my query?</H4>
932 <P>See the <SMALL>EXPLAIN</SMALL> manual page.</P>
934 <H4><A name="4.10">4.10</A>) What is an R-tree index?</H4>
936 <P>An R-tree index is used for indexing spatial data. A hash index
937 can't handle range searches. A B-tree index only handles range
938 searches in a single dimension. R-trees can handle
939 multi-dimensional data. For example, if an R-tree index can be
940 built on an attribute of type <I>point</I>, the system can more
941 efficiently answer queries such as "select all points within a
942 bounding rectangle."</P>
944 <P>The canonical paper that describes the original R-tree design
947 <P>Guttman, A. "R-trees: A Dynamic Index Structure for Spatial
948 Searching." Proceedings of the 1984 ACM SIGMOD Int'l Conf on Mgmt
951 <P>You can also find this paper in Stonebraker's "Readings in
952 Database Systems".</P>
954 <P>Built-in R-trees can handle polygons and boxes. In theory,
955 R-trees can be extended to handle higher number of dimensions. In
956 practice, extending R-trees requires a bit of work and we don't
957 currently have any documentation on how to do it.</P>
959 <H4><A name="4.11">4.11</A>) What is the Genetic Query
962 <P>The <SMALL>GEQO</SMALL> module speeds query optimization when
963 joining many tables by means of a Genetic Algorithm (GA). It allows
964 the handling of large join queries through nonexhaustive
967 <H4><A name="4.12">4.12</A>) How do I perform regular expression
968 searches and case-insensitive regular expression searches? How do I
969 use an index for case-insensitive searches?</H4>
971 <P>The <I>~</I> operator does regular expression matching, and
972 <I>~*</I> does case-insensitive regular expression matching. The
973 case-insensitive variant of <SMALL>LIKE</SMALL> is called
974 <SMALL>ILIKE</SMALL> in PostgreSQL 7.1 and later.</P>
976 <P>Case-insensitive equality comparisons are normally expressed
981 WHERE lower(col) = 'abc'
984 This will not use an standard index. However, if you create a
985 functional index, it will be used:
987 CREATE INDEX tabindex on tab (lower(col));
991 <H4><A name="4.13">4.13</A>) In a query, how do I detect if a field
992 is <SMALL>NULL</SMALL>?</H4>
994 <P>You test the column with <SMALL>IS NULL</SMALL> and <SMALL>IS
995 NOT NULL</SMALL>.</P>
997 <H4><A name="4.14">4.14</A>) What is the difference between the
998 various character types?</H4>
1000 Type Internal Name Notes
1001 --------------------------------------------------
1002 "char" char 1 character
1003 CHAR(#) bpchar blank padded to the specified fixed length
1004 VARCHAR(#) varchar size specifies maximum length, no padding
1005 TEXT text no specific upper limit on length
1006 BYTEA bytea variable-length byte array (null-byte safe)
1009 <P>You will see the internal name when examining system catalogs
1010 and in some error messages.</P>
1012 <P>The last four types above are "varlena" types (i.e., the first
1013 four bytes on disk are the length, followed by the data). Thus the
1014 actual space used is slightly greater than the declared size.
1015 However, these data types are also subject to compression or being
1016 stored out-of-line by <SMALL>TOAST</SMALL>, so the space on disk
1017 might also be less than expected.</P>
1019 <P><SMALL>CHAR()</SMALL> is best when storing strings that are
1020 usually the same length. <SMALL>VARCHAR()</SMALL> is best when
1021 storing variable-length strings but it limits how long a string can
1022 be. <SMALL>TEXT</SMALL> is for strings of unlimited length, maximum
1023 1 gigabyte. <SMALL>BYTEA</SMALL> is for storing binary data,
1024 particularly values that include <SMALL>NULL</SMALL> bytes.</P>
1026 <H4><A name="4.15.1">4.15.1</A>) How do I create a
1027 serial/auto-incrementing field?</H4>
1029 <P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It
1030 auto-creates a sequence and index on the column. For example,
1033 CREATE TABLE person (
1038 is automatically translated into this:
1040 CREATE SEQUENCE person_id_seq;
1041 CREATE TABLE person (
1042 id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
1045 CREATE UNIQUE INDEX person_id_key ON person ( id );
1047 See the <I>create_sequence</I> manual page for more information
1048 about sequences. You can also use each row's <I>OID</I> field as a
1049 unique value. However, if you need to dump and reload the database,
1050 you need to use <I>pg_dump</I>'s <I>-o</I> option or <SMALL>COPY
1051 WITH OIDS</SMALL> option to preserve the <SMALL>OID</SMALL>s.
1053 <H4><A name="4.15.2">4.15.2</A>) How do I get the value of a
1054 <SMALL>SERIAL</SMALL> insert?</H4>
1056 <P>One approach is to retrieve the next <SMALL>SERIAL</SMALL> value
1057 from the sequence object with the <I>nextval()</I> function
1058 <I>before</I> inserting and then insert it explicitly. Using the
1059 example table in <A href="#4.15.1">4.15.1</A>, that might look like
1062 new_id = output of "SELECT nextval('person_id_seq')"
1063 INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal');
1065 You would then also have the new value stored in
1066 <CODE>new_id</CODE> for use in other queries (e.g., as a foreign
1067 key to the <CODE>person</CODE> table). Note that the name of the
1068 automatically created <SMALL>SEQUENCE</SMALL> object will be named
1069 <<I>table</I>>_<<I>serialcolumn</I>>_<I>seq</I>, where
1070 <I>table</I> and <I>serialcolumn</I> are the names of your table
1071 and your <SMALL>SERIAL</SMALL> column, respectively.
1073 <P>Alternatively, you could retrieve the assigned
1074 <SMALL>SERIAL</SMALL> value with the <I>currval</I>() function
1075 <I>after</I> it was inserted by default, e.g.,</P>
1077 INSERT INTO person (name) VALUES ('Blaise Pascal');
1078 new_id = output of "SELECT currval('person_id_seq')";
1080 Finally, you could use the <A href="#4.16"><SMALL>OID</SMALL></A>
1081 returned from the <SMALL>INSERT</SMALL> statement to look up the
1082 default value, though this is probably the least portable approach.
1083 In Perl, using DBI with Edmund Mergl's DBD::Pg module, the oid
1084 value is made available via <I>$sth->{pg_oid_status}</I> after
1085 <I>$sth->execute()</I>.
1087 <H4><A name="4.15.3">4.15.3</A>) Don't <I>currval()</I> and
1088 <I>nextval()</I> lead to a race condition with other users?</H4>
1090 <P>No. Currval() returns the current value assigned by your
1091 backend, not by all users.</P>
1093 <H4><A name="4.15.4">4.15.4</A>) Why aren't my sequence numbers
1094 reused on transaction abort? Why are there gaps in the numbering of
1095 my sequence/SERIAL column?</H4>
1097 <P>To improve concurrency, sequence values are given out to running
1098 transactions as needed and are not locked until the transaction
1099 completes. This causes gaps in numbering from aborted
1102 <H4><A name="4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is
1103 a <SMALL>TID</SMALL>?</H4>
1105 <P><SMALL>OID</SMALL>s are PostgreSQL's answer to unique row ids.
1106 Every row that is created in PostgreSQL gets a unique
1107 <SMALL>OID</SMALL>. All <SMALL>OID</SMALL>s generated during
1108 <I>initdb</I> are less than 16384 (from
1109 <I>backend/access/transam.h</I>). All user-created
1110 <SMALL>OID</SMALL>s are equal to or greater than this. By default,
1111 all these <SMALL>OID</SMALL>s are unique not only within a table or
1112 database, but unique within the entire PostgreSQL installation.</P>
1114 <P>PostgreSQL uses <SMALL>OID</SMALL>s in its internal system
1115 tables to link rows between tables. These <SMALL>OID</SMALL>s can
1116 be used to identify specific user rows and used in joins. It is
1117 recommended you use column type <SMALL>OID</SMALL> to store
1118 <SMALL>OID</SMALL> values. You can create an index on the
1119 <SMALL>OID</SMALL> field for faster access.</P>
1121 <P>O<SMALL>ID</SMALL>s are assigned to all new rows from a central
1122 area that is used by all databases. If you want to change the
1123 <SMALL>OID</SMALL> to something else, or if you want to make a copy
1124 of the table, with the original <SMALL>OID</SMALL>s, there is no
1125 reason you can't do it:</P>
1127 CREATE TABLE new_table(old_oid oid, mycol int);
1128 SELECT old_oid, mycol INTO new FROM old;
1129 COPY new TO '/tmp/pgtable';
1131 COPY new WITH OIDS FROM '/tmp/pgtable';
1133 CREATE TABLE new_table (mycol int);
1134 INSERT INTO new_table (oid, mycol) SELECT oid, mycol FROM old_table;
1138 <P>O<SMALL>ID</SMALL>s are stored as 4-byte integers, and will
1139 overflow at 4 billion. No one has reported this ever happening, and
1140 we plan to have the limit removed before anyone does.</P>
1142 <P>T<SMALL>ID</SMALL>s are used to identify specific physical rows
1143 with block and offset values. T<SMALL>ID</SMALL>s change after rows
1144 are modified or reloaded. They are used by index entries to point
1145 to physical rows.</P>
1147 <H4><A name="4.17">4.17</A>) What is the meaning of some of the
1148 terms used in PostgreSQL?</H4>
1150 <P>Some of the source code and older documentation use terms that
1151 have more common usage. Here are some:</P>
1154 <LI>table, relation, class</LI>
1156 <LI>row, record, tuple</LI>
1158 <LI>column, field, attribute</LI>
1160 <LI>retrieve, select</LI>
1162 <LI>replace, update</LI>
1164 <LI>append, insert</LI>
1166 <LI><SMALL>OID</SMALL>, serial value</LI>
1168 <LI>portal, cursor</LI>
1170 <LI>range variable, table name, table alias</LI>
1173 <P>A list of general database terms can be found at: <A href=
1174 "http://www.comptechnews.com/~reaster/dbdesign.html">http://www.comptechnews.com/~reaster/dbdesign.html</A></P>
1176 <H4><A name="4.18">4.18</A>) Why do I get the error <I>"ERROR:
1177 Memory exhausted in AllocSetAlloc()"</I>?</H4>
1179 <P>If you are running a version older than 7.1, an upgrade may fix
1180 the problem. Also it is possible you have run out of virtual memory
1181 on your system, or your kernel has a low limit for certain
1182 resources. Try this before starting <I>postmaster</I>:</P>
1187 Depending on your shell, only one of these may succeed, but it will
1188 set your process data segment limit much higher and perhaps allow
1189 the query to complete. This command applies to the current process,
1190 and all subprocesses created after the command is run. If you are
1191 having a problem with the <SMALL>SQL</SMALL> client because the
1192 backend is returning too much data, try it before starting the
1195 <H4><A name="4.19">4.19</A>) How do I tell what PostgreSQL version
1198 <P>From <I>psql</I>, type <CODE>select version();</CODE></P>
1200 <H4><A name="4.20">4.20</A>) Why does my large-object operations
1201 get <I>"invalid large obj descriptor"</I>?</H4>
1203 <P>You need to put <CODE>BEGIN WORK</CODE> and <CODE>COMMIT</CODE>
1204 around any use of a large object handle, that is, surrounding
1205 <CODE>lo_open</CODE> ... <CODE>lo_close.</CODE></P>
1207 <P>Currently PostgreSQL enforces the rule by closing large object
1208 handles at transaction commit. So the first attempt to do anything
1209 with the handle will draw <I>invalid large obj descriptor</I>. So
1210 code that used to work (at least most of the time) will now
1211 generate that error message if you fail to use a transaction.</P>
1213 <P>If you are using a client interface like <SMALL>ODBC</SMALL> you
1214 may need to set <CODE>auto-commit off.</CODE></P>
1216 <H4><A name="4.21">4.21</A>) How do I create a column that will
1217 default to the current time?</H4>
1219 <P>Use <I>CURRENT_TIMESTAMP</I>:</P>
1221 <CODE>CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
1225 <H4><A name="4.22">4.22</A>) Why are my subqueries using
1226 <CODE><SMALL>IN</SMALL></CODE> so slow?</H4>
1228 <P>Currently, we join subqueries to outer queries by sequentially
1229 scanning the result of the subquery for each row of the outer
1230 query. A workaround is to replace <CODE>IN</CODE> with
1231 <CODE>EXISTS</CODE>:</P>
1235 WHERE col1 IN (SELECT col2 FROM TAB2)
1242 WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
1245 We hope to fix this limitation in a future release.
1247 <H4><A name="4.23">4.23</A>) How do I perform an outer join?</H4>
1249 <P>PostgreSQL 7.1 and later supports outer joins using the SQL
1250 standard syntax. Here are two examples:</P>
1253 FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
1258 FROM t1 LEFT OUTER JOIN t2 USING (col);
1261 <P>These identical queries join t1.col to t2.col, and also return
1262 any unjoined rows in t1 (those with no match in t2). A
1263 <SMALL>RIGHT</SMALL> join would add unjoined rows of t2. A
1264 <SMALL>FULL</SMALL> join would return the matched rows plus all
1265 unjoined rows from t1 and t2. The word <SMALL>OUTER</SMALL> is
1266 optional and is assumed in <SMALL>LEFT</SMALL>,
1267 <SMALL>RIGHT</SMALL>, and <SMALL>FULL</SMALL> joins. Ordinary joins
1268 are called <SMALL>INNER</SMALL> joins.</P>
1270 <P>In previous releases, outer joins can be simulated using
1271 <SMALL>UNION</SMALL> and <SMALL>NOT IN</SMALL>. For example, when
1272 joining <I>tab1</I> and <I>tab2</I>, the following query does an
1273 <I>outer</I> join of the two tables:<BR>
1277 SELECT tab1.col1, tab2.col2
1279 WHERE tab1.col1 = tab2.col1
1281 SELECT tab1.col1, NULL
1283 WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
1287 <H4><A name="4.24">4.24</A>) How do I perform queries using
1288 multiple databases?</H4>
1290 <P>There is no way to query any database except the current one.
1291 Because PostgreSQL loads database-specific system catalogs, it is
1292 uncertain how a cross-database query should even behave.</P>
1294 <P>Of course, a client can make simultaneous connections to
1295 different databases and merge the information that way.</P>
1297 <H4><A name="4.25">4.25</A>) How do I return multiple rows or
1298 columns from a function?</H4>
1300 <P>You can return result sets from PL/pgSQL functions using
1301 <I>refcursors</I>. See <A href=
1302 "http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html">
1303 http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html,</A>
1304 section 23.7.3.3.</P>
1306 <H4><A href="4.26">4.26</A>) Why can't I reliably create/drop
1307 temporary tables in PL/PgSQL functions?</H4>
1308 PL/PgSQL caches function contents, and an unfortunate side effect
1309 is that if a PL/PgSQL function accesses a temporary table, and that
1310 table is later dropped and recreated, and the function called
1311 again, the function will fail because the cached function contents
1312 still point to the old temporary table. The solution is to use
1313 <SMALL>EXECUTE</SMALL> for temporary table access in PL/PgSQL. This
1314 will cause the query to be reparsed every time.
1318 <H2 align="center">Extending PostgreSQL</H2>
1320 <H4><A name="5.1">5.1</A>) I wrote a user-defined function. When I
1321 run it in <I>psql</I>, why does it dump core?</H4>
1323 <P>The problem could be a number of things. Try testing your
1324 user-defined function in a stand-alone test program first.</P>
1326 <H4><A name="5.2">5.2</A>) How can I contribute some nifty new
1327 types and functions to PostgreSQL?</H4>
1329 <P>Send your extensions to the <I>pgsql-hackers</I> mailing list,
1330 and they will eventually end up in the <I>contrib/</I>
1333 <H4><A name="5.3">5.3</A>) How do I write a C function to return a
1336 <P>This requires wizardry so extreme that the authors have never
1337 tried it, though in principle it can be done.</P>
1339 <H4><A name="5.4">5.4</A>) I have changed a source file. Why does
1340 the recompile not see the change?</H4>
1342 <P>The <I>Makefiles</I> do not have the proper dependencies for
1343 include files. You have to do a <I>make clean</I> and then another
1344 <I>make</I>. If you are using <SMALL>GCC</SMALL> you can use the
1345 <I>--enable-depend</I> option of <I>configure</I> to have the
1346 compiler compute the dependencies automatically.</P>