]> granicus.if.org Git - postgresql/blob - doc/src/FAQ.html
Minor markup changes. Refer to (".../catalog") in the emacs hints.
[postgresql] / doc / src / FAQ.html
1 <HTML>
2 <HEAD>
3 <TITLE>PostgreSQL FAQ</TITLE>
4 </HEAD>
5 <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#A00000" ALINK="#0000FF">
6 <H1>
7 Frequently Asked Questions (FAQ) for PostgreSQL
8 </H1>
9 <P>
10 Last updated:           Tue Mar 21 16:09:11 EST 2000
11 <P>
12 Current maintainer:     Bruce Momjian (<A
13 HREF="mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR><P>
14
15 The most recent version of this document can be viewed at the postgreSQL
16 Web site, <A HREF="http://www.Postgresql.org">http://www.PostgreSQL.org</A>.<P>
17
18 Linux-specific questions are answered in <A
19 HREF="http://www.PostgreSQL.org/docs/faq-linux.html">http://www.PostgreSQL.org/docs/faq-linux.html</A>.<P>
20
21 Irix-specific questions are answered in <A
22 HREF="http://www.PostgreSQL.org/docs/faq-irix.html">http://www.PostgreSQL.org/docs/faq-irix.html</A>.<P>
23
24 HPUX-specific questions are answered in <A
25 HREF="http://www.PostgreSQL.org/docs/faq-hpux.shtml">http://www.PostgreSQL.org/docs/faq-hpux.shtml</A>.<P>
26
27 <HR><P>
28
29 <H2><CENTER>General Questions</CENTER></H2>
30
31 <A HREF="#1.1">1.1</A>) What is PostgreSQL?<BR>
32 <A HREF="#1.2">1.2</A>) What's the copyright on PostgreSQL?<BR>
33 <A HREF="#1.3">1.3</A>) What Unix platforms does PostgreSQL run on?<BR>
34 <A HREF="#1.4">1.4</A>) What non-unix ports are available?<BR>
35 <A HREF="#1.5">1.5</A>) Where can I get PostgreSQL?<BR>
36 <A HREF="#1.6">1.6</A>) Where can I get support for PostgreSQL?<BR>
37 <A HREF="#1.7">1.7</A>) What is the latest release of PostgreSQL?<BR>
38 <A HREF="#1.8">1.8</A>) What documentation is available for PostgreSQL?<BR>
39 <A HREF="#1.9">1.9</A>) How do I find out about known bugs or missing features?<BR>
40 <A HREF="#1.10">1.10</A>)       How can I learn SQL?<BR>
41 <A HREF="#1.11">1.11</A>)       Is PostgreSQL Y2K compliant?<BR>
42 <A HREF="#1.12">1.12</A>)       How do I join the development team?<BR>
43 <A HREF="#1.13">1.13</A>)       How do I submit a bug report?<BR>
44 <A HREF="#1.14">1.14</A>)       How does PostgreSQL compare to other DBMS's?<BR>
45
46
47 <H2><CENTER>User Client Questions</CENTER></H2>
48
49 <A HREF="#2.1">2.1</A>) Are there ODBC drivers for
50 PostgreSQL?<BR>
51 <A HREF="#2.2">2.2</A>) What tools are available for hooking
52 PostgreSQL to Web pages?<BR>
53 <A HREF="#2.3">2.3</A>) Does PostgreSQL have a graphical user interface?
54 A report generator? An embedded query language interface?<BR>
55 <A HREF="#2.4">2.4</A>) What languages are available to communicate
56 with PostgreSQL?<BR>
57
58
59 <H2><CENTER>Administrative Questions</CENTER></H2>
60
61 <A HREF="#3.1">3.1</A>) Why does initdb fail?<BR>
62 <A HREF="#3.2">3.2</A>) How do I install PostgreSQL somewhere other than
63 /usr/local/pgsql?<BR>
64 <A HREF="#3.3">3.3</A>) When I start the postmaster, I get a
65 <I>Bad System Call</I> or core dumped message.  Why?<BR>
66 <A HREF="#3.4">3.4</A>) When I try to start the postmaster, I get
67 <I>IpcMemoryCreate</I> errors3.  Why?<BR>
68 <A HREF="#3.5">3.5</A>) When I try to start the postmaster, I get
69 <I>IpcSemaphoreCreate</I> errors.  Why?<BR>
70 <A HREF="#3.6">3.6</A>) How do I prevent other hosts from accessing my
71 PostgreSQL database?<BR>
72 <A HREF="#3.7">3.7</A>) Why can't I connect to my database from
73 another machine?<BR>
74 <A HREF="#3.8">3.8</A>) Why can't I access the database as the
75 <I>root</I> user?<BR>
76 <A HREF="#3.9">3.9</A>) All my servers crash under concurrent
77 table access.  Why?<BR>
78 <A HREF="#3.10">3.10</A>)       How do I tune the database engine for
79 better performance?<BR>
80 <A HREF="#3.11">3.11</A>)       What debugging features are available in
81 PostgreSQL?<BR>
82 <A HREF="#3.12">3.12</A>) I get 'Sorry, too many clients' when trying to
83 connect.  Why?<BR>
84 <A HREF="#3.13">3.13</A>)       What are the pg_psort.XXX files in my
85 database directory?<BR>
86 <A HREF="#3.14">3.14</A>)       How do I set up a pg_group?<BR>
87
88 <H2><CENTER>Operational Questions</CENTER></H2>
89
90 <A HREF="#4.1">4.1</A>) The system seems to be confused about commas,
91 decimal points, and date formats.<BR>
92 <A HREF="#4.2">4.2</A>) What is the exact difference between
93 binary cursors and normal cursors?<BR>
94 <A HREF="#4.3">4.3</A>) How do I <I>select</I> only the first few rows of
95 a query?<BR>
96
97 <A HREF="#4.4">4.4</A>) How do I get a list of tables, or other
98 things I can see in <I>psql?</I><BR>
99 <A HREF="#4.5">4.5</A>) How do you remove a column from a table?<BR>
100
101 <A HREF="#4.6">4.6</A>) What is the maximum size for a
102 row, table, database?<BR>
103 <A HREF="#4.7">4.7</A>) How much database disk space is required
104 to store data from a typical flat file?<BR>
105
106 <A HREF="#4.8">4.8</A>) How do I find out what indices or
107 operations are defined in the database?<BR>
108 <A HREF="#4.9">4.9</A>) My queries are slow or don't make use of the
109 indexes.  Why?<BR>
110 <A HREF="#4.10">4.10</A>)       How do I see how the query optimizer is
111 evaluating my query?<BR>
112 <A HREF="#4.11">4.11</A>)       What is an R-tree index?<BR>
113 <A HREF="#4.12">4.12</A>)       What is Genetic Query Optimization?<BR>
114
115 <A HREF="#4.13">4.13</A>)       How do I do regular expression searches
116 and case-insensitive regexp searching?<BR>
117 <A HREF="#4.14">4.14</A>)       In a query, how do I detect if a field
118 is NULL?<BR>
119 <A HREF="#4.15">4.15</A>)       What is the difference between the
120 various character types?<BR>
121 <A HREF="#4.16.1">4.16.1</A>)   How do I create a serial/auto-incrementing field?<BR>
122 <A HREF="#4.16.2">4.16.2</A>)   How do I get the value of a serial insert?<BR>
123 <A HREF="#4.16.3">4.16.3</A>)   Wouldn't use of currval() and nextval() lead to a race condition with other concurrent backend processes?<BR>
124
125 <A HREF="#4.17">4.17</A>)       What is an oid?  What is a tid?<BR>
126 <A HREF="#4.18">4.18</A>)       What is the meaning of some of the terms
127 used in PostgreSQL?<BR>
128
129 <A HREF="#4.19">4.19</A>)       Why do I get the error "FATAL:  palloc
130 failure: memory exhausted?"<BR>
131 <A HREF="#4.20">4.20</A>)       How do I tell what PostgreSQL version I
132 am running? <BR>
133 <A HREF="#4.21">4.21</A>)       My large-object operations get <I>invalid
134 large obj descriptor.</I>  Why?<BR>
135 <A HREF="#4.22">4.22</A>)       How do I create a column that will default to the
136 current time?<BR>
137 <A HREF="#4.23">4.23</A>)       Why are my subqueries using <CODE>IN</CODE> so slow?<BR>
138
139 <H2><CENTER>Extending PostgreSQL</CENTER></H2>
140
141 <A HREF="#5.1">5.1</A>) I wrote a user-defined function.  When I run
142 it in <I>psql,</I> why does it dumps core?<BR>
143 <A HREF="#5.2">5.2</A>) What does the message:
144 <I>NOTICE:PortalHeapMemoryFree: 0x402251d0 not in alloc set!</I> mean?<BR>
145 <A HREF="#5.3">5.3</A>) How can I contribute some nifty new types and functions
146 for PostgreSQL?<BR>
147 <A HREF="#5.4">5.4</A>) How do I write a C function to return a
148 tuple?<BR>
149 <A HREF="#5.5">5.5</A>) I have changed a source file.  Why does the
150 recompile does not see the change?<BR>
151
152
153 <HR>
154
155 <H2><CENTER>General Questions</CENTER></H2>
156 <H4><A
157 NAME="1.1">1.1</A>)     What is PostgreSQL?</H4><P>
158
159 PostgreSQL is an enhancement of the POSTGRES database management system,
160 a next-generation DBMS research prototype.  While PostgreSQL retains the
161 powerful data model and rich data types of POSTGRES, it replaces the
162 PostQuel query language with an extended subset of SQL.  PostgreSQL is
163 free and the complete source is available.<P>
164
165 PostgreSQL development is being performed by a team of Internet
166 developers who all subscribe to the PostgreSQL development mailing list.
167 The current coordinator is Marc G. Fournier (<A
168 HREF="mailto:scrappy@postgreSQL.org">scrappy@postgreSQL.org</A>). (See
169 below on how to join). This team is now responsible for all current and
170 future development of PostgreSQL.<P>
171
172 The authors of PostgreSQL 1.01 were Andrew Yu and Jolly Chen. Many
173 others have contributed to the porting, testing, debugging and
174 enhancement of the code.  The original Postgres code, from which
175 PostgreSQL is derived, was the effort of many graduate students,
176 undergraduate students, and staff programmers working under the
177 direction of Professor Michael Stonebraker at the University of
178 California, Berkeley.<P>
179
180 The original name of the software at Berkeley was Postgres.  When SQL
181 functionality was added in 1995, its name was changed to Postgres95. The
182 name was changed at the end of 1996 to PostgreSQL.<P>
183
184 <H4><A NAME="1.2">1.2</A>)      What's the copyright on
185 PostgreSQL?</H4><P>
186
187 PostgreSQL is subject to the following COPYRIGHT.<P>
188
189 PostgreSQL Data Base Management System<P>
190
191 Portions copyright (c) 1996-2000, PostgreSQL, Inc
192
193 Portions Copyright (c) 1994-6 Regents of the University of California<P>
194
195 Permission to use, copy, modify, and distribute this software and its
196 documentation for any purpose, without fee, and without a written
197 agreement is hereby granted, provided that the above copyright notice
198 and this paragraph and the following two paragraphs appear in all
199 copies.<P>
200
201 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
202 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
203 INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
204 DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF
205 THE POSSIBILITY OF SUCH DAMAGE.<P>
206
207 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
208 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
209 AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER
210 IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO
211 OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
212 MODIFICATIONS.<P>
213
214
215
216 <H4><A NAME="1.3">1.3</A>)      What Unix platforms does PostgreSQL run
217 on?</H4><P>
218
219 The authors have compiled and tested PostgreSQL on the following
220 platforms (some of these compiles require gcc):
221 <UL>
222 <LI>   aix -           IBM on AIX 3.2.5 or 4.x
223 <LI>   alpha -         DEC Alpha AXP on Digital Unix 2.0, 3.2, 4.0
224 <LI>   BSD44_derived - OSs derived from 4.4-lite BSD (NetBSD, FreeBSD)
225 <LI>   bsdi -          BSD/OS 2.x, 3.x, 4.x
226 <LI>   dgux -          DG/UX 5.4R4.11
227 <LI>   hpux -          HP PA-RISC on HP-UX 9.*, 10.*
228 <LI>   i386_solaris -  i386 Solaris
229 <LI>   irix5 -         SGI MIPS on IRIX 5.3
230 <LI>   linux -         Intel i86
231                        Alpha
232                        SPARC
233                        PPC
234                        M68k
235 <LI>   sco -           SCO 3.2v5
236                        Unixware
237 <LI>   sparc_solaris - SUN SPARC on Solaris 2.4, 2.5, 2.5.1
238 <LI>   sunos4 -        SUN SPARC on SunOS 4.1.3
239 <LI>   svr4 -          Intel x86 on Intel SVR4 and MIPS
240 <LI>   ultrix4 -       DEC MIPS on Ultrix 4.4
241 </UL>
242 <P>
243
244 <H4><A NAME="1.4">1.4</A>)      What non-unix ports are available?</H4><P>
245
246 It is possible to compile the libpq C library, psql, and other
247 interfaces and binaries to run on MS Windows platforms.  In this case,
248 the client is running on MS Windows, and communicates via TCP/IP to a
249 server running on one of our supported Unix platforms.<P>
250
251 A file <I>win31.mak</I> is included in the distribution for making a
252 Win32 libpq library and psql.<P>
253
254 The database server is now working on Windows NT using the Cygnus
255 Unix/NT porting library.  See pgsql/doc/README.NT in the distribution.<P>
256 There is also a web page at <A HREF=
257 "http://www.freebsd.org/~kevlo/postgres/portNT.html">
258 http://www.freebsd.org/~kevlo/postgres/portNT.html.</A>
259
260 There is another port using U/Win at <A HREF=
261 "http://surya.wipro.com/uwin/ported.html">http://surya.wipro.com/uwin/ported.html.</A>
262
263
264 <H4><A NAME="1.5">1.5</A>)      Where can I get PostgreSQL?</H4><P>
265 The primary anonymous ftp site for PostgreSQL is
266 <A
267 HREF="ftp://ftp.postgreSQL.org/pub">ftp://ftp.postgreSQL.org/pub</A>
268 <P>
269 For mirror sites, see our main web site.
270
271 <H4><A NAME="1.6">1.6</A>)      Where can I get support for PostgreSQL?</H4><P>
272
273 There is no official support for PostgreSQL from the  University of
274 California, Berkeley.  It is maintained through volunteer effort.<P>
275
276 The main mailing list is: <A
277 HREF="mailto:pgsql-general@postgreSQL.org">pgsql-general@postgreSQL.org</A>.
278 It is available for discussion of matters pertaining to PostgreSQL.
279 To subscribe, send a mail with the lines in the body (not
280 the subject line)
281
282 <PRE>
283         subscribe
284         end
285 </PRE><P>
286
287 to <A
288 HREF="mailto:pgsql-general-request@postgreSQL.org">pgsql-general-request@postgreSQL.org</A>.<P>
289
290 There is also a digest list available.  To subscribe to this list, send
291 email to: <A HREF="mailto:pgsql-general-digest-request@postgreSQL.org">
292 pgsql-general-digest-request@postgreSQL.org</A> with a BODY of:
293
294 <PRE>
295         subscribe
296         end
297 </PRE>
298
299 Digests are sent out to members of this list whenever the main list has
300 received around 30k of messages.<P>
301
302 The bugs mailing list is available.  To subscribe to this list, send email
303 to <A
304 HREF="mailto:bugs-request@postgreSQL.org">bugs-request@postgreSQL.org</A>
305 with a BODY of:<P>
306
307 <PRE>
308         subscribe
309         end
310 </PRE>
311
312 There is also a developers discussion mailing list available.  To
313 subscribe to this list, send email to <A
314 HREF="mailto:hackers-request@postgreSQL.org">hackers-request@postgreSQL.org</A>
315 with a BODY of:<P>
316
317 <PRE>
318         subscribe
319         end
320 </PRE><P>
321
322 Additional mailing lists and information about PostgreSQL can be found
323 via the PostgreSQL WWW home page at:
324
325 <BLOCKQUOTE>
326 <A HREF="http://postgreSQL.org">http://postgreSQL.org</A>
327 </BLOCKQUOTE><P>
328
329 There is also an IRC channel on EFNet, channel #PostgreSQL.
330 I use the unix command <CODE>irc -c '#PostgreSQL' "$USER"
331 irc.phoenix.net</CODE><P>
332
333 Commercial support for PostgreSQL is available at <A
334 HREF="http://www.pgsql.com">http://www.pgsql.com/</A><P>
335
336
337 <H4><A NAME="1.7">1.7</A>)      What is the latest release of PostgreSQL?</H4><P>
338
339 The latest release of PostgreSQL is version 7.0.<P>
340
341 We plan to have major releases every four months.<P>
342
343
344 <H4><A NAME="1.8">1.8</A>)      What documentation is available for PostgreSQL?</H4><P>
345
346 Several manuals, manual pages, and some small test examples are 
347 included in the distribution. See the /doc directory.  You can also
348 browse the manual on-line at <A
349 HREF="http://www.postgresql.org/docs/postgres">
350 http://www.postgresql.org/docs/postgres.</A>
351 in the distribution.
352 <P>
353
354 <I>psql</I> has some nice \d commands to show information about types,
355 operators, functions, aggregates, etc.<P>
356
357 The web site contains even more documentation.<P>
358
359 <H4><A NAME="1.9">1.9</A>)      How do I find out about known bugs or missing features?
360 </H4><P>
361
362 PostgreSQL supports an extended subset of SQL-92.  See our
363 <A HREF="http://www.postgreSQL.org/docs/todo.html">
364 TODO</A> for a list of known bugs, missing features, and future plans.<P>
365
366 <H4><A NAME="1.10">1.10</A>)    How can I learn SQL?</H4><P>
367
368 There is a nice tutorial at <A
369 HREF="http://w3.one.net/~jhoffman/sqltut.htm">
370 http://w3.one.net/~jhoffman/sqltut.htm</A> and at <A
371 HREF="http://ourworld.compuserve.com/homepages/Graeme_Bircall/HTM_COOK.HTM">
372 http://ourworld.compuserve.com/homepages/Graeme_Birchall/HTM_COOK.HTM.</A><P>
373
374 Another one is "Teach Yourself SQL in 21 Days, Second Edition" at <A
375 HREF="http://members.tripod.com/er4ebus/sql/index.htm">
376 http://members.tripod.com/er4ebus/sql/index.htm </A><P>
377
378 Many of our users like <I>The Practical SQL Handbook</I>, Bowman et al.,
379 Addison Wesley.  Others like <I>Lan Times Guide to SQL</I>, Groff et al.,
380 Osborne McGraw-Hill.<P>
381
382
383 <H4><A NAME="1.11">1.11</A>)    Is PostgreSQL Y2K compliant?</H4><P>
384
385 Yes, we easily handle dates past the year 2000AD, and before 2000BC.<P>
386
387
388 <H4><A NAME="1.12">1.12</A>)    How do I join the development team?</H4><P>
389
390 First, download the latest sources and read the PostgreSQL Developers
391 documentation on our web site, or in the distribution.
392 Second, subscribe to the pgsql-hackers and pgsql-patches mailing lists.
393 Third, submit high-quality patches to pgsql-patches.<P>
394
395 There are about a dozen people who have <SMALL>COMMIT</SMALL> privileges to
396 the PostgreSQL CVS archive. All of them have submitted so many
397 high-quality patches that it was a pain for the existing
398 committers to keep up, and we had confidence that patches they
399 committed were likely to be of high quality.
400
401 <H4><A NAME="1.13">1.13</A>)    How do I submit a bug report?</H4><P>
402
403 Fill out the "bug-template" file and send it to:  <A
404 HREF="mailto:bugs@postgreSQL.org">bugs@postgreSQL.org</A><P>
405
406 Also check out our ftp site <A
407 HREF="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>
409
410
411 <H4><A NAME="1.14">1.14</A>)    How does PostgreSQL compare to other
412 DBMS's?</H4><P>
413
414 There are several ways of measuring software:  features, performance,
415 reliability, support, and price.<P>
416
417 <DL>
418 <DT> <B>Features</B>
419 <DD>
420
421 PostgreSQL has most features present in large commercial DBMS's, like
422 transactions, subselects, triggers, views, and sophisticated locking. 
423 We have some features they don't have, like user-defined types,
424 inheritance, rules, and multi-version concurrency control to reduce lock
425 contention.  We don't have foreign key referential integrity or outer
426 joins, but are working on them for our next release.<BR><BR>
427
428 <DT> <B>Performance</B>
429 <DD>
430
431 PostgreSQL runs in two modes. Normal <I>fsync</I> mode flushes every
432 completed transaction to disk, guaranteeing that if the OS crashes or
433 loses power in the next few seconds, all your data is safely stored on
434 disk. In this mode, we are slower than most commercial databases, partly
435 because few of them do such conservative flushing to disk in their
436 default modes. In <I>no-fsync</I> mode, we are usually faster than
437 commercial databases, though in this mode, an OS crash could cause data
438 corruption. We are working to provide an intermediate mode that suffers
439 less performance overhead than full fsync mode, and will allow data
440 integrity within 30 seconds of an OS crash. The mode is select-able by
441 the database administrator.<BR><BR>
442
443 In comparison to MySQL or leaner database systems, we are slower on
444 inserts/updates because we have transaction overhead. Of course, MySQL
445 doesn't have any of the features mentioned in the <I>Features</I>
446 section above. We are built for flexibility and features, though we
447 continue to improve performance through profiling and source code
448 analysis.<BR><BR>
449
450 We handle each user connection by creating a Unix process. Backend
451 processes share data buffers and locking information. With multiple
452 CPU's, multiple backends can easily run on different CPU's.<BR><BR>
453
454 <DT> <B>Reliability</B>
455 <DD>
456
457 We realize that a DBMS must be reliable, or it is worthless.  We strive
458 to release well-tested, stable code that has a minimum of bugs.  Each
459 release has at least one month of beta testing, and our release history
460 shows that we can provide stable, solid releases that are ready for
461 production use.  We believe we compare favorably to other database
462 software in this area.<BR><BR>
463
464 <DT> <B>Support</B>
465 <DD>
466
467 Our mailing list provides a large group of developers and users to help
468 resolve any problems encountered.  While we can not guarantee a fix,
469 commercial DBMS's don't always supply a fix either.  Direct access to
470 developers, the user community, manuals, and the source code often make
471 PostgreSQL support superior to other DBMS's.
472 There is commercial per-incident support available for those who need
473 it. (See support FAQ item.)<BR><BR>
474
475 <DT> <B>Price</B>
476 <DD>
477
478 We are free for all use, both commercial and non-commercial.  You can
479 add our code to your product with no limitations, except those outlined
480 in our BSD-style license stated above.<BR><BR>
481 </DL>
482
483
484 <HR>
485
486 <H2><CENTER>User Client Questions</CENTER></H2>
487 <P>
488
489
490
491 <H4><A NAME="2.1">2.1</A>)      Are there ODBC drivers for PostgreSQL?</H4><P>
492
493 There are two ODBC drivers available, PostODBC and OpenLink ODBC.<P>
494
495 PostODBC is included in the distribution. More information about it can
496 be gotten from: <A HREF="http://www.insightdist.com/psqlodbc">
497 http://www.insightdist.com/psqlodbc</A><P>
498
499 OpenLink ODBC can be gotten from <A HREF="http://www.openlinksw.com/">
500 http://www.openlinksw.com</A>. It works with their standard ODBC client
501 software so you'll have PostgreSQL ODBC available on every client
502 platform they support (Win, Mac, Unix, VMS).<P>
503
504 They will probably be selling this product to people who need
505 commercial-quality support, but a freeware version will always be
506 available. Questions to  <A
507 HREF="mailto:postgres95@openlink.co.uk">postgres95@openlink.co.uk</A>.<P>
508
509
510
511 <H4><A NAME="2.2">2.2</A>)      What tools are available for hooking
512 PostgreSQL to Web pages?</H4><P>
513
514 A nice introduction to Database-backed Web pages can be seen at: <A
515 HREF="http://www.webtools.com">http://www.webtools.com</A><P>
516
517 There is also one at <A HREF="http://www.phone.net/home/mwm/hotlist/">
518 http://www.phone.net/home/mwm/hotlist/.</A><P>
519
520 For web integration, PHP is an excellent interface.  It is at:
521 <A HREF="http://www.php.net">http://www.php.net</A><P>
522
523 PHP is great for simple stuff, but for more complex cases, many
524 use the perl interface and CGI.pm.<P>
525
526 A WWW gateway based on WDB using perl can be downloaded from <A
527 HREF="http://www.eol.ists.ca/~dunlop/wdb-p95">http://www.eol.ists.ca/~dunlop/wdb-p95</A>
528
529 <H4><A NAME="2.3">2.3</A>)      Does PostgreSQL have a graphical user interface?
530 A report generator? An embedded query language interface?</H4><P>
531
532 We have a nice graphical user interface called <I>pgaccess,</I> which is
533 shipped as part of the distribution.  <I>Pgaccess</I> also has a report
534 generator.  The web page is <A HREF=
535 "http://www.flex.ro/pgaccess">http://www.flex.ro/pgaccess</A><P>
536
537 We also include <I>ecpg,</I> which is an embedded SQL query language interface for
538 C.
539
540 <H4><A NAME="2.4">2.4</A>)      What languages are available to
541 communicate with PostgreSQL?</H4><P>
542
543 We have:
544 <UL>
545 <LI>C(libpq)
546 <LI>C++(libpq++)
547 <LI>Embedded C(ecpg)
548 <LI>Java(jdbc)
549 <LI>Perl(perl5)
550 <LI>ODBC(odbc)
551 <LI>Python(PyGreSQL)
552 <LI>TCL(libpgtcl)
553 <LI>C Easy API(libpgeasy)
554 <LI>Embedded HTML(<A HREF="http://www.php.net">PHP from http://www.php.net</A>)
555 </UL><P>
556
557 <HR>
558
559 <H2><CENTER>Administrative Questions</CENTER></H2><P>
560
561
562 <H4><A NAME="3.1">3.1</A>)      Why does initdb fail?</H4><P>
563
564 <UL>
565 <LI> check that you don't have any of the previous version's binaries in
566 your path   (If you see the message <CODE>WARN:heap_modifytuple: repl is
567 \  9</CODE>, this is the problem.)
568 <Li> check to see that you have the proper paths set
569 <LI> check that the <I>postgres</I> user owns the proper files
570 </UL><P>
571
572
573 <H4><A NAME="3.2">3.2</A>)      How do I install PostgreSQL somewhere
574 other than /usr/local/pgsql?</H4><P>
575
576 The simplest way is to specify the --prefix option when running configure.
577 If you forgot to do that, you can edit Makefile.global and change POSTGRESDIR
578 accordingly, or create a Makefile.custom and define POSTGRESDIR there.<P>
579
580
581 <H4><A NAME="3.3">3.3</A>)      When I start the postmaster, I get a <I>Bad
582 System Call</I> or core dumped message.  Why?</H4><P>
583
584 It could be a variety of problems, but first check to see that you
585 have system V extensions installed in your kernel. PostgreSQL requires
586 kernel support for shared memory and semaphores.<P>
587
588
589 <H4><A NAME="3.4">3.4</A>)      When I try to start the postmaster, I
590 get <I>IpcMemoryCreate</I> errors.  Why?</H4><P>
591
592 You either do not have shared memory configured properly in kernel or
593 you need to enlarge the shared memory available in the kernel.  The
594 exact amount you need depends on your architecture  and how many buffers
595 and backend processes you configure postmaster to run with.
596 For most systems, with default numbers of buffers and processes, you
597 need a minimum of ~1MB.<P>
598
599 <H4><A NAME="3.5">3.5</A>)      When I try to start the postmaster, I
600 get <I>IpcSemaphoreCreate</I> errors.  Why?</H4><P>
601
602 If the error message is <I>IpcSemaphoreCreate: semget failed (No space
603 left on device)</I> then your kernel is not configured with enough
604 semaphores. Postgres needs one semaphore per potential backend process.
605 A temporary solution is to start the postmaster with a smaller limit on
606 the number of backend processes.  Use <I>-N</I> with a parameter less
607 than the default of 32.  A more permanent solution is to increase your
608 kernel's <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI</SMALL> parameters.<P>
609
610 If the error message is something else, you might not have semaphore
611 support configured in your kernel at all.<P>
612
613
614 <H4><A NAME="3.6">3.6</A>)      How do I prevent other hosts from
615 accessing my PostgreSQL database?</H4><P>
616
617 By default, PostgreSQL only allows connections from the local machine
618 using unix domain sockets.  Other machines will not be able to connect
619 unless you add the <I>-i</I> flag to the <I>postmaster,</I>
620 <B>and</B> enable host-based authentication by modifying the file
621 <I>$PGDATA/pg_hba.conf</I> accordingly.  This will allow TCP/IP connections.
622 <P>
623
624 <H4><A NAME="3.7">3.7</A>)      Why can't I connect to my database from
625 another machine?</H4><P>
626
627 The default configuration allows only unix domain socket connections
628 from the local machine.  To enable TCP/IP connections, make sure the
629 postmaster has been started with the <I>-i</I> option, and add an
630 appropriate host entry to the file
631 <I>pgsql/data/pg_hba.conf</I>.  See the <I>pg_hba.conf</I> manual page.<P>
632
633
634 <H4><A NAME="3.8">3.8</A>)      Why can't I access the database as the <I>root</I>
635 user?</H4><P>
636
637 You should not create database users with user id 0 (root). They will  be
638 unable to access the database.  This is a security precaution  because
639 of the ability of any user to dynamically link object modules  into the
640 database engine.<P>
641
642
643 <H4><A NAME="3.9">3.9</A>)      All my servers crash under concurrent
644 table access.  Why?</H4><P>
645
646 This problem can be caused by a kernel that is not configured to support
647 semaphores.<P>
648
649
650 <H4><A NAME="3.10">3.10</A>)    How do I tune the database engine for
651 better performance?</H4><P>
652
653 Certainly, indices can speed up queries.  The <SMALL>EXPLAIN</SMALL> command
654 allows you to see how PostgreSQL is interpreting your query, and which
655 indices are being used.<P>
656
657 If you are doing a lot of <SMALL>INSERTs</SMALL>, consider doing them in a large
658 batch using the <SMALL>COPY</SMALL> command.  This is much faster than single
659 individual <SMALL>INSERTS.</SMALL>  Second, statements not in a <SMALL>BEGIN
660 WORK/COMMIT</SMALL> transaction block are considered to be in their
661 own transaction.  Consider performing several statements in a single
662 transaction block.  This reduces the transaction overhead.  Also
663 consider dropping and recreating indices when making large data
664 changes.<P>
665
666 There are several tuning things that can be done.  You can disable
667 fsync() by starting the postmaster with a  <I>-o -F</I> option.  This will
668 prevent <I>fsync()'s</I> from flushing to disk after every transaction.<P>
669
670 You can also use the postmaster -B option to increase the number of
671 shared memory buffers used by the backend processes.  If you make this
672 parameter too high, the postmaster may not start up because you've exceeded
673 your kernel's limit on shared memory space.
674 Each buffer is 8K and the default is 64 buffers.<P>
675
676 You can also use the backend -S option to increase the maximum amount
677 of memory used by each backend process for temporary sorts.  The -S value
678 is measured in kilobytes, and the default is 512 (ie, 512K).  It is unwise
679 to make this value too large, or you may run out of memory when a query
680 invokes several concurrent sorts.<P>
681
682 You can also use the <SMALL>CLUSTER</SMALL> command to group data in base tables to
683 match an index.  See the cluster(l) manual page for more details.<P>
684
685
686 <H4><A NAME="3.11">3.11</A>)    What debugging features are available in
687 PostgreSQL?</H4><P>
688
689 PostgreSQL has several features that report status information that can
690 be valuable for debugging purposes.<P>
691
692 First, by running configure with the --enable-cassert option, many
693 <I>assert()'s</I> monitor the progress of the backend and halt the program when
694 something unexpected occurs.<P>
695
696 Both postmaster and postgres have several debug options available.
697 First, whenever you start the postmaster, make sure you send the
698 standard output and error to a log file, like:
699 <PRE>
700         cd /usr/local/pgsql
701         ./bin/postmaster &gt;server.log 2&gt;&1 &
702 </PRE><P>
703
704 This will put a server.log file in the top-level PostgreSQL directory.
705 This file contains useful information about problems or errors
706 encountered by the server.  Postmaster has a -d option that allows even
707 more detailed information to be reported.  The -d option takes a number
708 that specifies the debug level.  Be warned that high debug level values
709 generate large log files.<P>
710
711 You can actually run the postgres backend from the command line, and
712 type your SQL statement directly.  This is recommended <B>only</B> for
713 debugging purposes.  Note that a newline terminates the query, not a
714 semicolon.  If you have compiled with debugging symbols, you can use a
715 debugger to see what is happening.  Because the backend was not started
716 from the postmaster, it is not running in an identical environment and
717 locking/backend interaction problems may not be duplicated.  Some
718 debuggers can attach to an already-running backend; that is the most
719 convenient way to diagnose problems in the normal multi-backend
720 environment.
721 <P>
722
723 The postgres program has -s, -A, and -t options that can be very useful
724 for debugging and performance measurements.<P>
725
726 You can also compile with profiling to see what functions are taking
727 execution time.  The backend profile files will be deposited in the
728 pgsql/data/base/dbname directory.  The client profile file will be put
729 in the client's current directory.<P>
730
731
732 <H4><A NAME="3.12">3.12</A>) I get 'Sorry, too many clients' when trying
733 to connect.  Why?</H4><P>
734
735 You need to increase the postmaster's limit on how many concurrent backend
736 processes it can start.<P>
737
738 In Postgres 6.5 and up, the default limit is 32 processes. You can
739 increase it by restarting the postmaster with a suitable <I>-N</I>
740 value. With the default configuration you can set <I>-N</I> as large as
741 1024; if you need more, increase <SMALL>MAXBACKENDS</SMALL> in
742 <I>include/config.h</I> and rebuild. You can set the default value of
743 <I>-N</I> at configuration time, if you like, using configure's
744 <I>--with-maxbackends</I> switch.<P>
745
746 Note that if you make <I>-N</I> larger than 32, you must also increase
747 <I>-B</I> beyond its default of 64; -B must be at least twice -N, and
748 probably should be more than that for best performance. For large
749 numbers of backend processes, you are also likely to find that you need
750 to increase various Unix kernel configuration parameters. Things to
751 check include the maximum size of shared memory blocks,
752 <SMALL>SHMMAX,</SMALL> the maximum number of semaphores,
753 <SMALL>SEMMNS</SMALL> and <SMALL>SEMMNI,</SMALL> the maximum number of
754 processes, <SMALL>NPROC,</SMALL> the maximum number of processes per
755 user, <SMALL>MAXUPRC,</SMALL> and the maximum number of open files,
756 <SMALL>NFILE</SMALL> and <SMALL>NINODE.</SMALL> The reason that Postgres
757 has a limit on the number of allowed backend processes is so that you
758 can ensure that your system won't run out of resources.<P>
759
760 In Postgres versions prior to 6.5, the maximum number of backends was
761 64, and changing it required a rebuild after altering the MaxBackendId
762 constant in <I>include/storage/sinvaladt.h.</I><P>
763
764 <H4><A NAME="3.13">3.13</A>)    What are the pg_tempNNN.NN files in my
765 database directory?</H4><P>
766
767 They are temporary files generated by the query executor. For
768 example, if a sort needs to be done to satisfy an <SMALL>ORDER BY,</SMALL> and
769 the sort requires more space than the backend's -S parameter allows,
770 then temp files are created to hold the extra data.<P>
771
772 The temp files should go away automatically, but might not if a backend
773 crashes during a sort.  If you have no transactions running at the time,
774 it is safe to delete the pg_tempNNN.NN files.<P>
775
776 <H4><A NAME="3.14">3.14</A>)    How do I set up a pg_group?</H4><P>
777
778 Currently, there is no easy interface to set up user groups. You have to
779 explicitly insert/update the pg_group table. For example:
780
781 <PRE>
782         jolly=&gt; insert into pg_group (groname, grosysid, grolist)
783         jolly=&gt;     values ('posthackers', '1234', '{5443, 8261}');
784         INSERT 548224
785         jolly=&gt; grant insert on foo to group posthackers;
786         CHANGE
787         jolly=&gt;
788 </PRE><P>
789
790         The fields in pg_group are:
791 <UL>
792 <LI>groname:  the group name.  This a name and should
793 be purely alphanumeric.  Do not include underscores
794 or other punctuation.
795 <LI>grosysid: the group id.  This is an int4.
796 This should be unique for each group.
797 <LI>grolist:   the list of pg_user id's that belong in the group.
798 This is an int4[].
799 </UL><P>
800
801
802 <HR>
803
804 <H2><CENTER>Operational Questions</CENTER></H2><P>
805
806
807 <H4><A NAME="4.1">4.1</A>)      The system seems to be confused about
808 commas, decimal points, and date formats.</H4><P>
809
810 Check your locale configuration. PostgreSQL uses the locale settings of
811 the user that ran the postmaster process.  There are postgres and psql
812 SET commands to control the date format.  Set those accordingly for
813 your operating environment.<P>
814
815
816 <H4><A NAME="4.2">4.2</A>)      What is the exact difference between
817 binary cursors and normal cursors?</H4><P>
818
819 See the <SMALL>DECLARE</SMALL> manual page for a description.<P>
820
821 <H4><A NAME="4.3">4.3</A>)      How do I <SMALL>SELECT</SMALL> only the first few
822 rows of a query?</H4><P>
823
824 See the <SMALL>FETCH</SMALL> manual page, or use SELECT ... LIMIT....<P>
825
826 The entire query may have to be evaluated, even if you only want the
827 first few rows. Consider a query that has an <SMALL>ORDER BY.</SMALL> 
828 If there is an index that matches the <SMALL>ORDER BY</SMALL>,
829 PostgreSQL may be able to evaluate only the first few records requested,
830 or the entire query may have to be evaluated until the desired rows have
831 been generated.<P>
832
833 <H4><A NAME="4.4">4.4</A>) How do I get a list of tables, or other
834 information I see in <I>psql?</I><BR></H4><P>
835
836 You can read the source code for <I>psql,</I> file
837 pgsql/src/bin/psql/psql.c. It contains SQL commands that generate the
838 output for psql's backslash commands.  You can also start <I>psql</I>
839 with the <I>-E</I> option so that it will print out the queries it uses
840 to execute the commands you give.<P>
841
842
843 <H4><A NAME="4.5">4.5</A>)      How do you remove a column from a
844 table?</H4><P>
845
846 We do not support <SMALL>ALTER TABLE DROP COLUMN,</SMALL> but do
847 this: 
848 <PRE>
849         SELECT ...  -- select all columns but the one you want to remove
850         INTO TABLE new_table
851         FROM old_table;
852         DROP TABLE old_table;
853         ALTER TABLE new_table RENAME TO old_table;
854 </PRE><P>
855
856
857
858
859 <H4><A NAME="4.6">4.6</A>)      What is the maximum size for a
860 row, table, database?</H4><P>
861
862 Rows are limited to 8K bytes, but this can be changed by editing
863 <I>include/config.h</I> and changing <SMALL>BLCKSZ.</SMALL> To use attributes
864 larger than 8K, you can also use the large object interface.<P>
865
866 Rows do not cross 8k boundaries so a 5k row will require 8k of
867 storage.<P>
868
869 Table and database sizes are unlimited.  There are many databases that
870 are tens of gigabytes, and probably some that are hundreds.
871
872 <H4><A NAME="4.7">4.7</A>)How much database disk space is required to
873 store data from a typical flat file?<BR></H4><P>
874
875 A Postgres database can require about six and a half times the disk space
876 required to store the data in a flat file.<P>
877
878 Consider a file of 300,000 lines with two integers on each line. The
879 flat file is 2.4MB.  The size of the PostgreSQL database file containing
880 this data can be estimated at 14MB:
881
882 <PRE>
883     36 bytes: each row header (approximate)
884    + 8 bytes: two int fields @ 4 bytes each
885    + 4 bytes: pointer on page to tuple
886    ----------------------------------------
887     48 bytes per row
888
889    The data page size in PostgreSQL is 8192 bytes (8 KB), so:
890
891    8192 bytes per page
892    -------------------   =  171 rows per database page (rounded up)
893      48 bytes per row
894
895    300000 data rows
896    --------------------  =  1755 database pages
897       171 rows per page
898
899 1755 database pages * 8192 bytes per page  =  14,376,960 bytes (14MB)
900 </PRE></P>
901
902 Indexes do not contain as much overhead, but do contain the data that is
903 being indexed, so they can be large also.<P>
904
905 <H4><A NAME="4.8">4.8</A>)      How do I find out what indices or
906 operations are defined in the database?</H4><P>
907
908 <I>psql</I> has a variety of backslash commands to show such information.  Use
909 \? to see them.<P>
910
911 Also try the file <I>pgsql/src/tutorial/syscat.source.</I>  It
912 illustrates many of the <SMALL>SELECT</SMALL>s needed to get information from
913 the database system tables.<P>
914
915
916 <H4><A NAME="4.9">4.9</A>)      My queries are slow or don't make
917 use of the indexes.  Why?</H4><P>
918
919 PostgreSQL does not automatically maintain statistics.  One has to make
920 an explicit <SMALL>VACUUM</SMALL> call to update the statistics.   After
921 statistics are updated, the optimizer knows how many rows in the table,
922 and can better decide if it should use indices.  Note that the optimizer
923 does not use indices in cases when the table is small because a
924 sequential scan would be faster.<P>
925
926 For column-specific optimization statistics, use <SMALL>VACUUM
927 ANALYZE.</SMALL>  <SMALL>VACUUM ANALYZE</SMALL> is important for complex
928 multi-join queries, so the optimizer can estimate the number of rows
929 returned from each table, and choose the proper join order.  The backend
930 does not keep track of column statistics on its own, so <SMALL>VACUUM
931 ANALYZE</SMALL> must be run to collect them periodically.<P>
932
933 Indexes are usually not used for <SMALL>ORDER BY</SMALL> operations: a
934 sequential scan followed by an explicit sort is faster than an indexscan
935 of all tuples of a large table, because it takes fewer disk accesses.
936 <P>
937
938 When using wild-card operators such as <SMALL>LIKE</SMALL> or <I>~,</I> indices can
939 only be used if the beginning of the search is anchored to the start of
940 the string.  So, to use indices, <SMALL>LIKE</SMALL> searches should not
941 begin with <I>%,</I> and <I>~</I>(regular expression searches) should
942 start with <I>^.</I>
943
944 <H4><A NAME="4.10">4.10</A>)    How do I see how the query optimizer is
945 evaluating my query?</H4><P>
946
947 See the <SMALL>EXPLAIN</SMALL> manual page.<P>
948
949 <H4><A NAME="4.11">4.11</A>)    What is an R-tree index?</H4><P>
950
951 An r-tree index is used for indexing spatial data. A hash index can't
952 handle range searches. A B-tree index only handles range searches in a
953 single dimension. R-tree's can handle multi-dimensional data.  For
954 example, if an R-tree index can be built on an attribute of type <I>point,</I>
955 the system can more efficient answer queries like select all points
956 within a bounding rectangle.<P>
957
958 The canonical paper that describes the original R-Tree design is:<P>
959
960 Guttman, A. "R-Trees: A Dynamic Index Structure for Spatial Searching."
961 Proc of the 1984 ACM SIGMOD Int'l Conf on Mgmt of Data, 45-57.<P>
962
963 You can also find this paper in Stonebraker's "Readings in Database
964 Systems"<P>
965
966 Builtin R-Trees can handle polygons and boxes.  In theory, R-trees can
967 be extended to handle higher number of dimensions.  In practice,
968 extending R-trees require a bit of work and we don't currently have any
969 documentation on how to do it.<P>
970
971
972 <H4><A NAME="4.12">4.12</A>)    What is Genetic Query
973 Optimization?</H4><P>
974
975 The GEQO module in PostgreSQL is intended to solve the query
976 optimization problem of joining many tables by means of a Genetic
977 Algorithm (GA). It allows the handling of large join queries through
978 non-exhaustive search.<P>
979
980 For further information see the documentation.
981
982
983
984 <H4><A NAME="4.13">4.13</A>)    How do I do regular expression searches and
985 case-insensitive regexp searching?</H4><P>
986
987 The <I>~</I> operator does regular-expression matching, and <I>~*</I>
988 does case-insensitive regular-expression matching. There is no
989 case-insensitive variant of the LIKE operator, but you can get the
990 effect of case-insensitive <SMALL>LIKE</SMALL> with this:
991 <PRE>
992         WHERE lower(textfield) LIKE lower(pattern)
993 </PRE>
994
995 <H4><A NAME="4.14">4.14</A>)    In a query, how do I detect if a field
996 is NULL?</H4><P>
997
998 You test the column with IS NULL and IS NOT NULL.<P>
999
1000
1001 <H4><A NAME="4.15">4.15</A>)    What is the difference between the
1002 various character types?</H4>
1003
1004 <PRE>
1005 Type            Internal Name   Notes
1006 --------------------------------------------------
1007 "char"          char            1 character
1008 CHAR(#)         bpchar          blank padded to the specified fixed length
1009 VARCHAR(#)      varchar         size specifies maximum length, no padding
1010 TEXT            text            length limited only by maximum row length
1011 BYTEA           bytea           variable-length array of bytes
1012 </PRE><P>
1013
1014 You will see the internal name when examining system catalogs
1015 and in some error messages.<P>
1016
1017 The last four types above are "varlena" types (i.e. the first four bytes
1018 are the length, followed by the data). <I>char(#)</I> allocates the
1019 maximum number of bytes no matter how much data is stored in the field.
1020 <I>text, varchar(#),</I> and <I>bytea</I> all have variable length on the disk,
1021 and because of this, there is a small performance penalty for using
1022 them. Specifically, the penalty is for access to all columns after the
1023 first column of this type.<P>
1024
1025
1026 <H4><A NAME="4.16.1">4.16.1</A>)        How do I create a
1027 serial/auto-incrementing field?</H4><P>
1028
1029 PostgreSQL supports <SMALL>SERIAL</SMALL> data type.  It auto-creates a
1030 sequence and index on the column.  For example, this...
1031 <PRE>
1032         CREATE TABLE person ( 
1033                 id   SERIAL, 
1034                 name TEXT 
1035         );
1036 </PRE>
1037 ...is automatically translated into this...
1038 <PRE>
1039         CREATE SEQUENCE person_id_seq;
1040         CREATE TABLE person ( 
1041                 id   INT4 NOT NULL DEFAULT nextval('person_id_seq'),
1042                 name TEXT 
1043         );
1044         CREATE UNIQUE INDEX person_id_key ON person ( id );
1045 </PRE>
1046 See the <I>create_sequence</I> manual page for more information about sequences.
1047
1048 You can also use each row's <I>oid</I> field as a unique value.  However, if
1049 you need to dump and reload the database, you need to use <I>pg_dump's -o</I>
1050 option or <SMALL>COPY WITH OIDS</SMALL> option to preserve the oids.<P>
1051
1052 For more details, see Bruce Momjian's chapter on 
1053 <A HREF="http://www.postgresql.org/docs/aw_pgsql_book/node74.html">Numbering Rows.</A>
1054
1055 <H4><A NAME="4.16.2">4.16.2</A>)        How do I get the back the generated SERIAL value after an insert?</H4><P>
1056 Probably the simplest approach is to to retrieve the next SERIAL value from the sequence object with the <I>nextval()</I> function <I>before</I> inserting and then insert it explicitly.  Using the example table in <A HREF="#4.16.1">4.16.1</A>, that might look like this:
1057 <PRE>
1058         $newSerialID = nextval('person_id_seq');
1059         INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
1060 </PRE>
1061 You would then also have the new value stored in <CODE>$newSerialID</CODE> for use in other queries (e.g., as a foreign key to the <CODE>person</CODE> table).  Note that the name of the automatically-created SEQUENCE object will be named &lt<I>table</I>&gt_&lt<I>serialcolumn</I>&gt_<I>seq</I>, where <I>table</I> and <I>serialcolumn</I> are the names of your table and your SERIAL column, respectively.  
1062 <P>
1063 Similarly, you could retrieve the just-assigned SERIAL value with the <I>currval</I>() function <I>after</I> it was inserted by default, e.g.,
1064 <PRE>
1065         INSERT INTO person (name) VALUES ('Blaise Pascal');
1066         $newID = currval('person_id_seq');
1067 </PRE>
1068 Finally, you could use the <A HREF="#4.17">oid</A> returned from the INSERT statement to lookup the default value, though this is probably the least portable approach.  In perl, using DBI with Edmund Mergl's DBD::Pg module, the oid value is made available via $sth->{pg_oid_status} after $sth->execute().
1069
1070 <H4><A NAME="4.16.3">4.16.3</A>)        Wouldn't use of currval() and nextval() lead to a race condition with other concurrent backend processes?</H4><P>
1071
1072 No.  That has been handled by the backends.
1073
1074
1075 <H4><A NAME="4.17">4.17</A>)    What is an oid?  What is a tid?</H4><P>
1076
1077 Oids are PostgreSQL's answer to unique row ids.  Every row that is
1078 created in PostgreSQL gets a unique oid.  All oids generated during
1079 initdb are less than 16384 (from <I>backend/access/transam.h</I>).  All
1080 user-created oids are equal or greater that this.  By default, all these
1081 oids are unique not only within a table, or database, but unique within
1082 the entire PostgreSQL installation.<P>
1083
1084 PostgreSQL uses oids in its internal system tables to link rows between
1085 tables.  These oids can be used to identify specific user rows and used
1086 in joins.  It is recommended you use column type oid to store oid
1087 values.  See the <I>sql(l)</I> manual page to see the other internal columns.
1088 You can create an index on the oid field for faster access.<P>
1089
1090 Oids are assigned to all new rows from a central area that is used by
1091 all databases.  If you want to change the oid to something else, or if
1092 you want to make a copy of the table, with the original oid's, there is
1093 no reason you can't do it:
1094
1095 <PRE>
1096         CREATE TABLE new_table(old_oid oid, mycol int);
1097         SELECT INTO new SELECT old_oid, mycol FROM old;
1098         COPY new TO '/tmp/pgtable';
1099         DELETE FROM new;
1100         COPY new WITH OIDS FROM '/tmp/pgtable';
1101 <!--
1102         CREATE TABLE new_table (mycol int);
1103         INSERT INTO new_table (oid, mycol) SELECT oid, mycol FROM old_table;
1104 -->
1105 </PRE><P>
1106
1107 Tids are used to identify specific physical rows with block and offset
1108 values.  Tids change after rows are modified or reloaded.  They are used
1109 by index entries to point to physical rows.<P>
1110
1111
1112 <H4><A NAME="4.18">4.18</A>)    What is the meaning of some of the terms
1113 used in PostgreSQL?</H4><P>
1114
1115 Some of the source code and older documentation use terms that have more
1116 common usage.  Here are some:
1117
1118 <UL>
1119 <LI> table, relation, class
1120 <LI> row, record, tuple
1121 <LI> column, field, attribute
1122 <LI> retrieve, select
1123 <LI> replace, update
1124 <LI> append, insert
1125 <LI> oid, serial value
1126 <LI> portal, cursor
1127 <LI> range variable, table name, table alias
1128 </UL><P>
1129
1130 <H4><A NAME="4.19">4.19</A>) Why do I get the error "FATAL:  palloc
1131 failure: memory exhausted?"<BR></H4><P>
1132
1133 It is possible you have run out of virtual memory on your system, or
1134 your kernel has a low limit for certain resources.  Try this before
1135 starting the postmaster:
1136
1137 <PRE>
1138         ulimit -d 65536
1139         limit datasize 64m
1140 </PRE>
1141
1142 Depending on your shell, only one of these may succeed, but it will set
1143 your process data segment limit much higher and perhaps allow the query
1144 to complete.  This command applies to the current process, and all
1145 subprocesses created after the command is run.  If you are having a problem
1146 with the SQL client because the backend is returning too much data, try
1147 it before starting the client.<P>
1148
1149 <H4><A NAME="4.20">4.20</A>) How do I tell what PostgreSQL version I
1150 am running? <BR></H4><P>
1151
1152 From <I>psql,</I> type <CODE>select version();</CODE><P>
1153
1154 <H4><A NAME="4.21">4.21</A>) My large-object operations get <I>invalid
1155 large obj descriptor.</I>  Why? <BR></H4><P>
1156
1157 You need to put <CODE>BEGIN WORK</CODE> and <CODE>COMMIT
1158 </CODE> around any use of a large object handle, that is,
1159 surrounding <CODE>lo_open</CODE> ... <CODE>lo_close.</CODE><P>
1160
1161 Current PostgreSQL enforces the rule by closing large object handles at
1162 transaction commit, which will be instantly upon completion of the
1163 <I>lo_open</I> command if you are not inside a transaction.  So the
1164 first attempt to do anything with the handle will draw <I>invalid large
1165 obj descriptor.</I>  So code that used to work (at least most of the
1166 time) will now generate that error message if you fail to use a
1167 transaction.<P>
1168
1169 If you are using a client interface like ODBC you may need to set
1170 <CODE>auto-commit off.</CODE><P>
1171
1172 <H4><A NAME="4.22">4.22</A>) How do I create a column that will default to the
1173 current time?<BR></H4><P>
1174 This way always works:
1175 <CODE><PRE>
1176         CREATE TABLE test (x int, modtime timestamp default now() );
1177 </PRE></CODE>
1178 In releases 7.0 and later, you may use:
1179 <CODE><PRE>
1180         create table test (x int, modtime timestamp default 'now');
1181 </PRE></CODE>
1182 <P>
1183 <H4><A NAME="4.23">4.23</A>) Why are my subqueries using <CODE>IN</CODE> so 
1184 slow?<BR></H4><P>
1185 Currently, we join subqueries to outer queries by sequential scanning
1186 the result of the subquery for each row of the outer query. A workaround
1187 is to replace <CODE>IN</CODE> with <CODE>EXISTS</CODE>. For example,
1188 change:
1189 <CODE><PRE>
1190         SELECT *
1191         FROM tab
1192         WHERE col1 IN (SELECT col2 FROM TAB2)
1193 </PRE></CODE>
1194 to:
1195 <CODE><PRE>
1196         SELECT *
1197         FROM tab
1198         WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
1199 </PRE></CODE>
1200 We hope to fix this limitation in a future release.
1201
1202 <HR>
1203
1204 <H2><CENTER>Extending PostgreSQL</CENTER></H2><P>
1205
1206
1207 <H4><A NAME="5.1">5.1</A>)      I wrote a user-defined function.  When
1208 I run it in <I>psql,</I> why does it dump core?</H4><P>
1209
1210 The problem could be a number of things.  Try testing your user-defined
1211 function in a stand alone test program first.
1212
1213 <H4><A NAME="5.2">5.2</A>)      What does the message:
1214 <I>NOTICE:PortalHeapMemoryFree: 0x402251d0 not in alloc set!</I> mean?</H4><P>
1215
1216 You are <I>pfree'ing</I> something that was not <I>palloc'ed.</I>
1217 Beware of mixing <I>malloc/free</I> and <I>palloc/pfree.</I>
1218
1219
1220 <H4><A NAME="5.3">5.3</A>)      How can I contribute some nifty new types and
1221 functions for PostgreSQL?</H4><P>
1222
1223
1224 Send your extensions to the pgsql-hackers mailing list, and they will
1225 eventually end up in the <I>contrib/</I> subdirectory.<P>
1226
1227
1228 <H4><A NAME="5.4">5.4</A>)      How do I write a C function to return a
1229 tuple?</H4><P>
1230
1231 This requires wizardry so extreme that the authors have never
1232 tried it, though in principle it can be done.<P>
1233
1234 <H4><A NAME="5.5">5.5</A>)      I have changed a source file.  Why does the
1235 recompile does not see the change?</H4><P>
1236
1237 The Makefiles do not have the proper dependencies for include files. You
1238 have to do a <I>make clean</I> and then another <I>make</I>.
1239  You
1240 have to do a <I>make clean</I> and then another <I>make.</I><P>
1241
1242
1243 </BODY>
1244 </HTML>
1245
1246