Commit 7f20a592 authored by Bruce Momjian's avatar Bruce Momjian

Update with Gavin's additions.

parent 4b9a12b1
Developer's Frequently Asked Questions (FAQ) for PostgreSQL Developer's Frequently Asked Questions (FAQ) for PostgreSQL
Last updated: Sat Nov 27 01:02:35 EST 2004 Last updated: Wed Dec 1 16:11:11 EST 2006
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us) Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
...@@ -12,19 +12,24 @@ ...@@ -12,19 +12,24 @@
General Questions General Questions
1.1) How do I get involved in PostgreSQL development? 1.1) How do I get involved in PostgreSQL development?
1.2) How do I add a feature or fix a bug? 1.2) What development environment is required to develop code?
1.3) How do I download/update the current source tree? 1.3) What areas need work?
1.4) How do I test my changes? 1.4) What do I do after choosing an item to work on?
1.5) What tools are available for developers? 1.5) Where can I learn more about the code?
1.6) What books are good for developers? 1.6) I've developed a patch, what next?
1.7) What is configure all about? 1.7) How do I download/update the current source tree?
1.8) How do I add a new port? 1.8) How do I test my changes?
1.9) Why don't you use threads/raw devices/async-I/O, <insert your 1.9) What tools are available for developers?
1.10) What books are good for developers?
1.11) What is configure all about?
1.12) How do I add a new port?
1.13) Why don't you use threads/raw devices/async-I/O, <insert your
favorite wizz-bang feature here>? favorite wizz-bang feature here>?
1.10) How are RPM's packaged? 1.14) How are RPM's packaged?
1.11) How are CVS branches handled? 1.15) How are CVS branches handled?
1.12) Where can I get a copy of the SQL standards? 1.16) Where can I get a copy of the SQL standards?
1.1) How do I get involved in PostgreSQL web site development? 1.17) Where can I get technical assistance?
1.18) How do I get involved in PostgreSQL web site development?
Technical Questions Technical Questions
...@@ -43,150 +48,157 @@ ...@@ -43,150 +48,157 @@
1.1) How go I get involved in PostgreSQL development? 1.1) How go I get involved in PostgreSQL development?
This was written by Lamar Owen: Download the code and have a look around. See 1.7.
Subscribe to and read the pgsql-hackers mailing list (often termed
'hackers'). This is where the major contributors and core members of
the project discuss development.
2001-06-22 1.2) What development environment is required to develop code?
What open source development process is used by the PostgreSQL team?
Read HACKERS for six months (or a full release cycle, whichever is
longer). Really. HACKERS _is_the process. The process is not well
documented (AFAIK -- it may be somewhere that I am not aware of) --
and it changes continually.
What development environment (OS, system, compilers, etc) is required
to develop code?
Developers Corner on the website has links to this information. The
distribution tarball itself includes all the extra tools and documents
that go beyond a good Unix-like development environment. In general, a
modern unix with a modern gcc, GNU make or equivalent, autoconf (of a
particular version), and good working knowledge of those tools are
required.
What areas need support?
The TODO list.
You've made the first step, by finding and subscribing to HACKERS.
Once you find an area to look at in the TODO, and have read the
documentation on the internals, etc, then you check out a current
CVS,write what you are going to write (keeping your CVS checkout up to
date in the process), and make up a patch (as a context diff only) and
send to the PATCHES list, prefereably.
Discussion on the patch typically happens here. If the patch adds a
major feature, it would be a good idea to talk about it first on the
HACKERS list, in order to increase the chances of it being accepted,
as well as toavoid duplication of effort. Note that experienced
developers with a proven track record usually get the big jobs -- for
more than one reason. Also note that PostgreSQL is highly portable --
nonportable code will likely be dismissed out of hand.
Once your contributions get accepted, things move from there.
Typically, you would be added as a developer on the list on the
website when one of the other developers recommends it. Membership on
the steering committee is by invitation only, by the other steering
committee members, from what I have gathered watching froma distance.
I make these statements from having watched the process for over two
years.
To see a good example of how one goes about this, search the archives
for the name 'Tom Lane' and see what his first post consisted of, and
where he took things. In particular, note that this hasn't been _that_
long ago -- and his bugfixing and general deep knowledge with this
codebase is legendary. Take a few days to read after him. And pay
special attention to both the sheer quantity as well as the
painstaking quality of his work. Both are in high demand.
1.2) How do I add a feature or fix a bug?
The source code is over 350,000 lines. Many fixes/features are PostgreSQL is developed mostly in the C programming language. It also
isolated to one specific area of the code. Others require knowledge of makes use of Yacc and Lex.
much of the source. If you are confused about where to start, ask the
hackers list, and they will be glad to assess the complexity and give The source code is targeted at most of the popular Unix platforms and
pointers on where to start. the Windows environment (XP, Windows 2000, and up).
Another thing to keep in mind is that many fixes and features can be Most developers make use of the open source development tool chain. If
added with surprisingly little code. I often start by adding code, you have contributed to open source software before, you will probably
then looking at other areas in the code where similar things are done, be familiar with these tools. They include: GCC (http://gcc.gnu.org,
and by the time I am finished, the patch is quite small and compact. GDB (www.gnu.org/software/gdb/gdb.html), autoconf
(www.gnu.org/software/autoconf/) AND GNU make
When adding code, keep in mind that it should use the existing (www.gnu.org/software/make/make.html.
facilities in the source, for performance reasons and for simplicity.
Often a review of existing code doing similar things is helpful. Developers using this tool chain on Windows make use of MingW (see
http://www.mingw.org/).
The usual process for source additions is:
* Review the TODO list. Some developers use compilers from other software vendors with mixed
* Discuss hackers the desirability of the fix/feature. results.
* How should it behave in complex circumstances?
* How should it be implemented? Developers who are regularly rebuilding the source often pass the
* Submit the patch to the patches list. --enable-depend flag to configure. The result is that when you make a
* Answer email questions. modification to a C header file, all files depend upon that file are
* Wait for the patch to be applied. also rebuilt.
1.3) How do I download/update the current source tree? 1.3) What areas need work?
Outstanding features are detailed in the TODO list. This is located in
doc/TODO in the source distribution or at
http://developer.postgresql.org/todo.php.
You can learn more about these features by consulting the archives,
the SQL standards and the recommend texts (see 1.10).
1.4) What do I do after choosing an item to work on?
Send an email to pgsql-hackers with a proposal for what you want to do
(assuming your contribution is not trivial). Working in isolation is
not advisable: others may be working on the same TODO item; you may
have misunderstood the TODO item; your approach may benefit from the
review of others.
1.5) Where can I learn more about the code?
Other than documentation in the source tree itself, you can find some
papers/presentations discussing the code at
http://developers.postgresql.org.
1.6) I've developed a patch, what next?
Generate the patch in contextual diff format. If you are unfamiliar
with this, you may find the script src/tools/makediff/difforig useful.
Ensure that your patch is generated against the most recent version of
the code. If it is a patch adding new functionality, the most recent
version is cvs HEAD; if it is a bug fix, this will be the most
recently version of the branch which suffers from the bug (for more on
branches in PostgreSQL, see 1.15).
Finally, submit the patch to pgsql-patches@postgresql.org. It will be
reviewed by other contributors to the project and may be either
accepted or sent back for further work.
1.7) How do I download/update the current source tree?
There are several ways to obtain the source tree. Occasional There are several ways to obtain the source tree. Occasional
developers can just get the most recent source tree snapshot from developers can just get the most recent source tree snapshot from
ftp.postgresql.org. For regular developers, you can use CVS. CVS ftp://ftp.postgresql.org.
allows you to download the source tree, then occasionally update your
copy of the source tree with any new changes. Using CVS, you don't Regular developers may want to take advantage of anonymous access to
have to download the entire source each time, only the changed files. our source code management system. The source tree is currently hosted
Anonymous CVS does not allows developers to update the remote source in CVS. For details of how to obtain the source from CVS see
tree, though privileged developers can do this. There is a CVS section http://developer.postgresql.org/docs/postgres/cvs.html.
(http://developer.postgresql.org/docs/postgres/cvs.html) in our
documentation that describes how to use remote CVS. You can also use 1.8) How do I test my changes?
CVSup, which has similarly functionality, and is available from
ftp.postgresql.org.
To update the source tree, there are two ways. You can generate a
patch against your current source tree, perhaps using the make_diff
tools mentioned above, and send them to the patches list. They will be
reviewed, and applied in a timely manner. If the patch is major, and
we are in beta testing, the developers may wait for the final release
before applying your patches.
For hard-core developers, Marc(scrappy@postgresql.org) will give you a
Unix shell account on postgresql.org, so you can use CVS to update the
main source tree, or you can ftp your files into your account, patch,
and cvs install the changes directly into the source tree.
1.4) How do I test my changes?
First, use psql to make sure it is working as you expect. Then run Basic system testing
src/test/regress and get the output of src/test/regress/checkresults
with and without your changes, to see that your patch does not change The easiest way to test your code is to ensure that it builds against
the regression test in unexpected ways. This practice has saved me the latest verion of the code and that it does not generate compiler
many times. The regression tests test the code in ways I would never warnings.
do, and has caught many bugs in my patches. By finding the problems
now, you save yourself a lot of debugging later when things are It is worth advised that you pass --enable-cassert to configure. This
broken, and you can't figure out when it happened. will turn on assertions with in the source which will often show us
bugs because they cause data corruption of segmentation violations.
1.5) What tools are available for developers? This generally makes debugging much easier.
Then, perform run time testing via psql.
Regression test suite
The next step is to test your changes against the existing regression
test suite. To do this, issue "make check" in the root directory of
the source tree. If any tests failure, investigate.
If you've deliberately changed existing behaviour, this change may
cause a regression test failure but not any actual regression. If so,
you should also patch the regression test suite.
Other run time testing
Some developers make use of tools such as valgrind
(http://valgrind.kde.org) for memory testing, gprof (which comes with
the GNU binutils suite) and oprofile
(http://oprofile.sourceforge.net/) for profiling and other related
tools.
What about unit testing, static analysis, model checking...?
There have been a number of discussions about other testing frameworks
and some developers are exploring these ideas.
1.9) What tools are available for developers?
Aside from the User documentation mentioned in the regular FAQ, there First, all the files in the src/tools directory are designed for
are several development tools available. First, all the files in the developers.
/tools directory are designed for developers.
RELEASE_CHANGES changes we have to make for each release RELEASE_CHANGES changes we have to make for each release
SQL_keywords standard SQL'92 keywords
backend description/flowchart of the backend directories backend description/flowchart of the backend directories
ccsym find standard defines made by your compiler ccsym find standard defines made by your compiler
copyright fixes copyright notices
entab converts tabs to spaces, used by pgindent entab converts tabs to spaces, used by pgindent
find_static finds functions that could be made static find_static finds functions that could be made static
find_typedef finds typedefs in the source code find_typedef finds typedefs in the source code
find_badmacros finds macros that use braces incorrectly find_badmacros finds macros that use braces incorrectly
fsync a script to provide information about the cost of cache
syncing system calls
make_ctags make vi 'tags' file in each directory make_ctags make vi 'tags' file in each directory
make_diff make *.orig and diffs of source make_diff make *.orig and diffs of source
make_etags make emacs 'etags' files make_etags make emacs 'etags' files
make_keywords make comparison of our keywords and SQL'92 make_keywords make comparison of our keywords and SQL'92
make_mkid make mkid ID files make_mkid make mkid ID files
mkldexport create AIX exports file pgcvslog used to generate a list of changes for each release
pgindent indents C source files
pgjindent indents Java source files
pginclude scripts for adding/removing include files pginclude scripts for adding/removing include files
unused_oids in pgsql/src/include/catalog pgindent indents source files
pgtest a semi-automated build system
thread a thread testing script
In src/include/catalog:
unused_oids a script which generates unused OIDs for use in system
catalogs
duplicate_oids finds duplicate OIDs in system catalog definitions
Let me note some of these. If you point your browser at the If you point your browser at the tools/backend/index.html file, you
file:/usr/local/src/pgsql/src/tools/backend/index.html directory, you
will see few paragraphs describing the data flow, the backend will see few paragraphs describing the data flow, the backend
components in a flow chart, and a description of the shared memory components in a flow chart, and a description of the shared memory
area. You can click on any flowchart box to see a description. If you area. You can click on any flowchart box to see a description. If you
...@@ -203,18 +215,18 @@ ...@@ -203,18 +215,18 @@
back out twice to return to the original function. Most editors back out twice to return to the original function. Most editors
support this via tags or etags files. support this via tags or etags files.
Third, you need to get id-utils from: Third, you need to get id-utils from ftp://ftp.gnu.org/gnu/id-utils/
ftp://alpha.gnu.org/gnu/id-utils-3.2d.tar.gz
ftp://tug.org/gnu/id-utils-3.2d.tar.gz
ftp://ftp.enst.fr/pub/gnu/gnits/id-utils-3.2d.tar.gz
By running tools/make_mkid, an archive of source symbols can be By running tools/make_mkid, an archive of source symbols can be
created that can be rapidly queried like grep or edited. Others prefer created that can be rapidly queried.
glimpse.
make_diff has tools to create patch diff files that can be applied to Some developers make use of cscope, which can be found at
the distribution. This produces context diffs, which is our preferred http://cscope.sf.net/. Others use glimpse, which can be found at
format. http://webglimpse.net/.
tools/make_diff has tools to create patch diff files that can be
applied to the distribution. This produces context diffs, which is our
preferred format.
Our standard format is to indent each code level with one tab, where Our standard format is to indent each code level with one tab, where
each tab is four spaces. You will need to set your editor to display each tab is four spaces. You will need to set your editor to display
...@@ -262,7 +274,7 @@ ...@@ -262,7 +274,7 @@
pgindent will the format code by specifying flags to your operating pgindent will the format code by specifying flags to your operating
system's utility indent. This article describes the value of a system's utility indent. This article describes the value of a
constent coding style. consistent coding style.
pgindent is run on all source files just before each beta test period. pgindent is run on all source files just before each beta test period.
It auto-formats all source files to make them consistent. Comment It auto-formats all source files to make them consistent. Comment
...@@ -277,7 +289,7 @@ ...@@ -277,7 +289,7 @@
is also a script called unused_oids in pgsql/src/include/catalog that is also a script called unused_oids in pgsql/src/include/catalog that
shows the unused oids. shows the unused oids.
1.6) What books are good for developers? 1.10) What books are good for developers?
I have four good books, An Introduction to Database Systems, by C.J. I have four good books, An Introduction to Database Systems, by C.J.
Date, Addison, Wesley, A Guide to the SQL Standard, by C.J. Date, et. Date, Addison, Wesley, A Guide to the SQL Standard, by C.J. Date, et.
...@@ -285,9 +297,9 @@ ...@@ -285,9 +297,9 @@
Navathe, and Transaction Processing, by Jim Gray, Morgan, Kaufmann Navathe, and Transaction Processing, by Jim Gray, Morgan, Kaufmann
There is also a database performance site, with a handbook on-line There is also a database performance site, with a handbook on-line
written by Jim Gray at http://www.benchmarkresources.com. written by Jim Gray at http://www.benchmarkresources.com..
1.7) What is configure all about? 1.11) What is configure all about?
The files configure and configure.in are part of the GNU autoconf The files configure and configure.in are part of the GNU autoconf
package. Configure allows us to test for various capabilities of the package. Configure allows us to test for various capabilities of the
...@@ -309,7 +321,7 @@ ...@@ -309,7 +321,7 @@
removed, so you see only the file contained in the source removed, so you see only the file contained in the source
distribution. distribution.
1.8) How do I add a new port? 1.12) How do I add a new port?
There are a variety of places that need to be modified to add a new There are a variety of places that need to be modified to add a new
port. First, start in the src/template directory. Add an appropriate port. First, start in the src/template directory. Add an appropriate
...@@ -326,7 +338,7 @@ ...@@ -326,7 +338,7 @@
src/makefiles directory for port-specific Makefile handling. There is src/makefiles directory for port-specific Makefile handling. There is
a backend/port directory if you need special files for your OS. a backend/port directory if you need special files for your OS.
1.9) Why don't you use threads/raw devices/async-I/O, <insert your favorite 1.13) Why don't you use threads/raw devices/async-I/O, <insert your favorite
wizz-bang feature here>? wizz-bang feature here>?
There is always a temptation to use the newest operating system There is always a temptation to use the newest operating system
...@@ -352,7 +364,7 @@ ...@@ -352,7 +364,7 @@
cautious about their adoption. The TODO list often contains links to cautious about their adoption. The TODO list often contains links to
discussions showing our reasoning in these areas. discussions showing our reasoning in these areas.
1.10) How are RPM's packaged? 1.14) How are RPMs packaged?
This was written by Lamar Owen: This was written by Lamar Owen:
...@@ -447,7 +459,7 @@ ...@@ -447,7 +459,7 @@
Of course, there are many projects that DO include all the files Of course, there are many projects that DO include all the files
necessary to build RPMs from their Official Tarball (TM). necessary to build RPMs from their Official Tarball (TM).
1.11) How are CVS branches managed? 1.15) How are CVS branches managed?
This was written by Tom Lane: This was written by Tom Lane:
...@@ -506,7 +518,7 @@ ...@@ -506,7 +518,7 @@
tree right away after a major release --- we wait for a dot-release or tree right away after a major release --- we wait for a dot-release or
two, so that we won't have to double-patch the first wave of fixes. two, so that we won't have to double-patch the first wave of fixes.
1.12) Where can I get a copy of the SQL standards? 1.16) Where can I get a copy of the SQL standards?
There are three versions of the SQL standard: SQL-92, SQL:1999, and There are three versions of the SQL standard: SQL-92, SQL:1999, and
SQL:2003. They are endorsed by ANSI and ISO. Draft versions can be SQL:2003. They are endorsed by ANSI and ISO. Draft versions can be
...@@ -523,7 +535,20 @@ ...@@ -523,7 +535,20 @@
* http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax (SQL-92) * http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax (SQL-92)
* http://dbs.uni-leipzig.de/en/lokal/standards.pdf (paper) * http://dbs.uni-leipzig.de/en/lokal/standards.pdf (paper)
1.13) How go I get involved in PostgreSQL web site development? 1.17) Where can I get technical assistance?
Many technical questions held by those new to the code have been
answered on the pgsql-hackers mailing list - the archives of which can
be found at http://archives.postgresql.org/pgsql-hackers/.
If you cannot find discussion or your particular question, feel free
to put it to the list.
Major contributors also answer technical questions, including
questions about development of new features, on IRC at
irc.freenode.net in the #postgresql channel.
1.18) How go I get involved in PostgreSQL web site development?
PostgreSQL website development is discussed on the PostgreSQL website development is discussed on the
pgsql-www@postgresql.org mailing list. The is a project page where the pgsql-www@postgresql.org mailing list. The is a project page where the
...@@ -627,8 +652,9 @@ typedef struct nameData ...@@ -627,8 +652,9 @@ typedef struct nameData
Here are some of the List manipulation commands: Here are some of the List manipulation commands:
lfirst(i) lfirst(i), lfirst_int(i), lfirst_oid(i)
return the data at list element i. return the data (a point, inteter and OID respectively) at list
element i.
lnext(i) lnext(i)
return the next list element after i. return the next list element after i.
...@@ -640,7 +666,8 @@ typedef struct nameData ...@@ -640,7 +666,8 @@ typedef struct nameData
a typical code snippet that loops through a List containing Var a typical code snippet that loops through a List containing Var
*'s and processes each one: *'s and processes each one:
List *i, *list; List *list;
ListCell *i;
foreach(i, list) foreach(i, list)
{ {
...@@ -689,9 +716,10 @@ List *i, *list; ...@@ -689,9 +716,10 @@ List *i, *list;
The structures passing around from the parser, rewrite, optimizer, and The structures passing around from the parser, rewrite, optimizer, and
executor require quite a bit of support. Most structures have support executor require quite a bit of support. Most structures have support
routines in src/backend/nodes used to create, copy, read, and output routines in src/backend/nodes used to create, copy, read, and output
those structures. Make sure you add support for your new field to those structures (in particular, the files copyfuncs.c and
these files. Find any other places the structure may need code for equalfuncs.c. Make sure you add support for your new field to these
your new field. mkid is helpful with this (see above). files. Find any other places the structure may need code for your new
field. mkid is helpful with this (see 1.9).
2.5) Why do we use palloc() and pfree() to allocate memory? 2.5) Why do we use palloc() and pfree() to allocate memory?
......
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for BSD/OS (vers 1st July 2002), see www.w3.org">
<title>PostgreSQL Developers FAQ</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink=
"#A00000" alink="#0000FF">
<h1>Developer's Frequently Asked Questions (FAQ) for
PostgreSQL</h1>
<p>Last updated: Wed Dec 1 16:11:11 EST 2006</p>
<p>Current maintainer: Bruce Momjian (<a href=
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</a>)<br>
</p>
<p>The most recent version of this document can be viewed at <a
href=
"http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html">http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html</a>.</p>
<hr>
<br>
<center>
<h2>General Questions</h2>
</center>
<a href="#1.1">1.1</a>) How do I get involved in PostgreSQL
development?<br>
<a href="#1.2">1.2</a>) What development environment is required
to develop code?<br>
<a href="#1.3">1.3</a>) What areas need work?<br>
<a href="#1.4">1.4</a>) What do I do after choosing an item to
work on?<br>
<a href="#1.5">1.5</a>) Where can I learn more about the code?<br>
<a href="#1.6">1.6</a>) I've developed a patch, what next?<br>
<a href="#1.7">1.7</a>) How do I download/update the current
source tree?<br>
<a href="#1.8">1.8</a>) How do I test my changes?<br>
<a href="#1.9">1.9</a>) What tools are available for
developers?<br>
<a href="#1.10">1.10</a>) What books are good for developers?<br>
<a href="#1.11">1.11</a>) What is configure all about?<br>
<a href="#1.12">1.12</a>) How do I add a new port?<br>
<a href="#1.13">1.13</a>) Why don't you use threads/raw
devices/async-I/O, &lt;insert your favorite wizz-bang feature
here&gt;?<br>
<a href="#1.14">1.14</a>) How are RPM's packaged?<br>
<a href="#1.15">1.15</a>) How are CVS branches handled?<br>
<a href="#1.16">1.16</a>) Where can I get a copy of the SQL
standards?<br>
<a href="#1.17">1.17</a>) Where can I get technical
assistance?<br>
<a href="#1.18">1.18</a>) How do I get involved in PostgreSQL web
site development?<br>
<center>
<h2>Technical Questions</h2>
</center>
<a href="#2.1">2.1</a>) How do I efficiently access information in
tables from the backend code?<br>
<a href="#2.2">2.2</a>) Why are table, column, type, function,
view names sometimes referenced as <i>Name</i> or <i>NameData,</i>
and sometimes as <i>char *?</i><br>
<a href="#2.3">2.3</a>) Why do we use <i>Node</i> and <i>List</i>
to make data structures?<br>
<a href="#2.4">2.4</a>) I just added a field to a structure. What
else should I do?<br>
<a href="#2.5">2.5</a>) Why do we use <i>palloc</i>() and
<i>pfree</i>() to allocate memory?<br>
<a href="#2.6">2.6</a>) What is ereport()?<br>
<a href="#2.7">2.7</a>) What is CommandCounterIncrement()?<br>
<br>
<hr>
<center>
<h2>General Questions</h2>
</center>
<h3><a name="1.1">1.1</a>) How go I get involved in PostgreSQL
development?</h3>
<p>Download the code and have a look around. See <a href=
"#1.7">1.7</a>.</p>
<p>Subscribe to and read the <a href=
"http://archives.posrgresql.org/pgsql-hackers">pgsql-hackers</a>
mailing list (often termed 'hackers'). This is where the major
contributors and core members of the project discuss
development.</p>
<h3><a name="1.2">1.2</a>) What development environment is required
to develop code?</h3>
<p>PostgreSQL is developed mostly in the C programming language. It
also makes use of Yacc and Lex.</p>
<p>The source code is targeted at most of the popular Unix
platforms and the Windows environment (XP, Windows 2000, and
up).</p>
<p>Most developers make use of the open source development tool
chain. If you have contributed to open source software before, you
will probably be familiar with these tools. They include: GCC (<a
href="http://gcc.gnu.org">http://gcc.gnu.org</a>, GDB (<a href=
"http://www.gnu.org/software/gdb/gdb.html">www.gnu.org/software/gdb/gdb.html</a>),
autoconf (<a href=
"http://www.gnu.org/software/autoconf/">www.gnu.org/software/autoconf/</a>)
AND GNU make (<a href=
"http://www.gnu.org/software/make/make.html">www.gnu.org/software/make/make.html</a>.</p>
<p>Developers using this tool chain on Windows make use of MingW
(see <a href=
"http://www.mingw.org/">http://www.mingw.org/</a>).</p>
<p>Some developers use compilers from other software vendors with
mixed results.</p>
<p>Developers who are regularly rebuilding the source often pass
the --enable-depend flag to <i>configure</i>. The result is that
when you make a modification to a C header file, all files depend
upon that file are also rebuilt.</p>
<h3><a name="1.3">1.3</a>) What areas need work?</h3>
Outstanding features are detailed in the TODO list. This is located
in <i>doc/TODO</i> in the source distribution or at <a href=
"http://developer.postgresql.org/todo.php">http://developer.postgresql.org/todo.php</a>.
<p>You can learn more about these features by consulting the
archives, the SQL standards and the recommend texts (see <a href=
"#1.10">1.10</a>).</p>
<h3><a name="1.4">1.4</a>) What do I do after choosing an item to
work on?</h3>
<p>Send an email to pgsql-hackers with a proposal for what you want
to do (assuming your contribution is not trivial). Working in
isolation is not advisable: others may be working on the same TODO
item; you may have misunderstood the TODO item; your approach may
benefit from the review of others.</p>
<h3><a name="1.5">1.5</a>) Where can I learn more about the
code?</h3>
<p>Other than documentation in the source tree itself, you can find
some papers/presentations discussing the code at <a href=
"http://developers.postgresql.org">http://developers.postgresql.org</a>.</p>
<h3><a name="1.6">1.6</a>) I've developed a patch, what next?</h3>
<p>Generate the patch in contextual diff format. If you are
unfamiliar with this, you may find the script
<i>src/tools/makediff/difforig</i> useful.</p>
<p>Ensure that your patch is generated against the most recent
version of the code. If it is a patch adding new functionality, the
most recent version is cvs HEAD; if it is a bug fix, this will be
the most recently version of the branch which suffers from the bug
(for more on branches in PostgreSQL, see <a href=
"#1.15">1.15</a>).</p>
<p>Finally, submit the patch to pgsql-patches@postgresql.org. It
will be reviewed by other contributors to the project and may be
either accepted or sent back for further work.</p>
<h3><a name="1.7">1.7</a>) How do I download/update the current
source tree?</h3>
<p>There are several ways to obtain the source tree. Occasional
developers can just get the most recent source tree snapshot from
<a href=
"ftp://ftp.postgresql.org">ftp://ftp.postgresql.org</a>.</p>
<HTML> <p>Regular developers may want to take advantage of anonymous
<HEAD> access to our source code management system. The source tree is
<META name="generator" content="HTML Tidy, see www.w3.org"> currently hosted in CVS. For details of how to obtain the source
from CVS see <a href=
<TITLE>PostgreSQL Developers FAQ</TITLE> "http://developer.postgresql.org/docs/postgres/cvs.html">http://developer.postgresql.org/docs/postgres/cvs.html</a>.</p>
</HEAD>
<h3><a name="1.8">1.8</a>) How do I test my changes?</h3>
<BODY bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#A00000"
alink="#0000FF"> <p><b>Basic system testing</b></p>
<H1>Developer's Frequently Asked Questions (FAQ) for
PostgreSQL</H1> <p>The easiest way to test your code is to ensure that it builds
against the latest verion of the code and that it does not generate
<P>Last updated: Sat Nov 27 01:02:35 EST 2004</P> compiler warnings.</p>
<P>Current maintainer: Bruce Momjian (<A href= <p>It is worth advised that you pass --enable-cassert to
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR> <i>configure</i>. This will turn on assertions with in the source
</P> which will often show us bugs because they cause data corruption of
segmentation violations. This generally makes debugging much
<P>The most recent version of this document can be viewed at <A href= easier.</p>
"http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html">http://www.PostgreSQL.org/docs/faqs/FAQ_DEV.html</A>.</P>
<p>Then, perform run time testing via psql.</p>
<HR>
<BR> <p><b>Regression test suite</b></p>
<p>The next step is to test your changes against the existing
<CENTER> regression test suite. To do this, issue "make check" in the root
<H2>General Questions</H2> directory of the source tree. If any tests failure,
</CENTER> investigate.</p>
<A href="#1.1">1.1</A>) How do I get involved in PostgreSQL
development?<BR> <p>If you've deliberately changed existing behaviour, this change
<A href="#1.2">1.2</A>) How do I add a feature or fix a bug?<BR> may cause a regression test failure but not any actual regression.
<A href="#1.3">1.3</A>) How do I download/update the current source If so, you should also patch the regression test suite.</p>
tree?<BR>
<A href="#1.4">1.4</A>) How do I test my changes?<BR> <p><b>Other run time testing</b></p>
<A href="#1.5">1.5</A>) What tools are available for developers?<BR>
<A href="#1.6">1.6</A>) What books are good for developers?<BR> <p>Some developers make use of tools such as valgrind (<a href=
<A href="#1.7">1.7</A>) What is configure all about?<BR> "http://valgrind.kde.org">http://valgrind.kde.org</a>) for memory
<A href="#1.8">1.8</A>) How do I add a new port?<BR> testing, gprof (which comes with the GNU binutils suite) and
<A href="#1.9">1.9</A>) Why don't you use threads/raw oprofile (<a href=
devices/async-I/O, &lt;insert your favorite wizz-bang feature "http://oprofile.sourceforge.net/">http://oprofile.sourceforge.net/</a>)
here&gt;?<BR> for profiling and other related tools.</p>
<A href="#1.10">1.10</A>) How are RPM's packaged?<BR>
<A href="#1.11">1.11</A>) How are CVS branches handled?<BR> <p><b>What about unit testing, static analysis, model
<A href="#1.12">1.12</A>) Where can I get a copy of the SQL checking...?</b></p>
standards?<BR>
<A href="#1.13">1.1</A>) How do I get involved in PostgreSQL <p>There have been a number of discussions about other testing
web site development?<BR> frameworks and some developers are exploring these ideas.</p>
<CENTER> <h3><a name="1.9">1.9</a>) What tools are available for
<H2>Technical Questions</H2> developers?</h3>
</CENTER>
<A href="#2.1">2.1</A>) How do I efficiently access information in <p>First, all the files in the <i>src/tools</i> directory are
tables from the backend code?<BR> designed for developers.</p>
<A href="#2.2">2.2</A>) Why are table, column, type, function, view
names sometimes referenced as <I>Name</I> or <I>NameData,</I> and <pre>
sometimes as <I>char *?</I><BR>
<A href="#2.3">2.3</A>) Why do we use <I>Node</I> and <I>List</I> to
make data structures?<BR>
<A href="#2.4">2.4</A>) I just added a field to a structure. What else
should I do?<BR>
<A href="#2.5">2.5</A>) Why do we use <I>palloc</I>() and
<I>pfree</I>() to allocate memory?<BR>
<A href="#2.6">2.6</A>) What is ereport()?<BR>
<A href="#2.7">2.7</A>) What is CommandCounterIncrement()?<BR>
<BR>
<HR>
<CENTER>
<H2>General Questions</H2>
</CENTER>
<H3><A name="1.1">1.1</A>) How go I get involved in PostgreSQL
development?</H3>
<P>This was written by Lamar Owen:</P>
<P>2001-06-22</P>
<B>What open source development process is used by the PostgreSQL
team?</B>
<P>Read HACKERS for six months (or a full release cycle, whichever
is longer). Really. HACKERS _is_the process. The process is not
well documented (AFAIK -- it may be somewhere that I am not aware
of) -- and it changes continually.</P>
<B>What development environment (OS, system, compilers, etc) is
required to develop code?</B>
<P><A href="http://developer.postgresql.org">Developers Corner</A> on the
website has links to this information. The distribution tarball
itself includes all the extra tools and documents that go beyond a
good Unix-like development environment. In general, a modern unix
with a modern gcc, GNU make or equivalent, autoconf (of a
particular version), and good working knowledge of those tools are
required.</P>
<B>What areas need support?</B>
<P>The TODO list.</P>
<P>You've made the first step, by finding and subscribing to
HACKERS. Once you find an area to look at in the TODO, and have
read the documentation on the internals, etc, then you check out a
current CVS,write what you are going to write (keeping your CVS
checkout up to date in the process), and make up a patch (as a
context diff only) and send to the PATCHES list, prefereably.</P>
<P>Discussion on the patch typically happens here. If the patch
adds a major feature, it would be a good idea to talk about it
first on the HACKERS list, in order to increase the chances of it
being accepted, as well as toavoid duplication of effort. Note that
experienced developers with a proven track record usually get the
big jobs -- for more than one reason. Also note that PostgreSQL is
highly portable -- nonportable code will likely be dismissed out of
hand.</P>
<P>Once your contributions get accepted, things move from there.
Typically, you would be added as a developer on the list on the
website when one of the other developers recommends it. Membership
on the steering committee is by invitation only, by the other
steering committee members, from what I have gathered watching
froma distance.</P>
<P>I make these statements from having watched the process for over
two years.</P>
<P>To see a good example of how one goes about this, search the
archives for the name 'Tom Lane' and see what his first post
consisted of, and where he took things. In particular, note that
this hasn't been _that_ long ago -- and his bugfixing and general
deep knowledge with this codebase is legendary. Take a few days to
read after him. And pay special attention to both the sheer
quantity as well as the painstaking quality of his work. Both are
in high demand.</P>
<H3><A name="1.2">1.2</A>) How do I add a feature or fix a bug?</H3>
<P>The source code is over 350,000 lines. Many fixes/features
are isolated to one specific area of the code. Others require
knowledge of much of the source. If you are confused about where to
start, ask the hackers list, and they will be glad to assess the
complexity and give pointers on where to start.</P>
<P>Another thing to keep in mind is that many fixes and features
can be added with surprisingly little code. I often start by adding
code, then looking at other areas in the code where similar things
are done, and by the time I am finished, the patch is quite small
and compact.</P>
<P>When adding code, keep in mind that it should use the existing
facilities in the source, for performance reasons and for
simplicity. Often a review of existing code doing similar things is
helpful.</P>
<P>The usual process for source additions is:
<UL>
<LI>Review the TODO list.</LI>
<LI>Discuss hackers the desirability of the fix/feature.</LI>
<LI>How should it behave in complex circumstances?</LI>
<LI>How should it be implemented?</LI>
<LI>Submit the patch to the patches list.</LI>
<LI>Answer email questions.</LI>
<LI>Wait for the patch to be applied.</LI>
</UL></P>
<H3><A name="1.3">1.3</A>) How do I download/update the current source
tree?</H3>
<P>There are several ways to obtain the source tree. Occasional
developers can just get the most recent source tree snapshot from
ftp.postgresql.org. For regular developers, you can use CVS. CVS
allows you to download the source tree, then occasionally update
your copy of the source tree with any new changes. Using CVS, you
don't have to download the entire source each time, only the
changed files. Anonymous CVS does not allows developers to update
the remote source tree, though privileged developers can do this.
There is a CVS section (http://developer.postgresql.org/docs/postgres/cvs.html)
in our documentation that describes how to use remote CVS. You can
also use CVSup, which has similarly functionality, and is available
from ftp.postgresql.org.</P>
<P>To update the source tree, there are two ways. You can generate
a patch against your current source tree, perhaps using the
make_diff tools mentioned above, and send them to the patches list.
They will be reviewed, and applied in a timely manner. If the patch
is major, and we are in beta testing, the developers may wait for
the final release before applying your patches.</P>
<P>For hard-core developers, Marc(scrappy@postgresql.org) will give
you a Unix shell account on postgresql.org, so you can use CVS to
update the main source tree, or you can ftp your files into your
account, patch, and cvs install the changes directly into the
source tree.</P>
<H3><A name="1.4">1.4</A>) How do I test my changes?</H3>
<P>First, use <I>psql</I> to make sure it is working as you expect.
Then run <I>src/test/regress</I> and get the output of
<I>src/test/regress/checkresults</I> with and without your changes,
to see that your patch does not change the regression test in
unexpected ways. This practice has saved me many times. The
regression tests test the code in ways I would never do, and has
caught many bugs in my patches. By finding the problems now, you
save yourself a lot of debugging later when things are broken, and
you can't figure out when it happened.</P>
<H3><A name="1.5">1.5</A>) What tools are available for
developers?</H3>
<P>Aside from the User documentation mentioned in the regular FAQ,
there are several development tools available. First, all the files
in the <I>/tools</I> directory are designed for developers.</P>
<PRE>
RELEASE_CHANGES changes we have to make for each release RELEASE_CHANGES changes we have to make for each release
SQL_keywords standard SQL'92 keywords
backend description/flowchart of the backend directories backend description/flowchart of the backend directories
ccsym find standard defines made by your compiler ccsym find standard defines made by your compiler
copyright fixes copyright notices
entab converts tabs to spaces, used by pgindent entab converts tabs to spaces, used by pgindent
find_static finds functions that could be made static find_static finds functions that could be made static
find_typedef finds typedefs in the source code find_typedef finds typedefs in the source code
find_badmacros finds macros that use braces incorrectly find_badmacros finds macros that use braces incorrectly
fsync a script to provide information about the cost of cache
syncing system calls
make_ctags make vi 'tags' file in each directory make_ctags make vi 'tags' file in each directory
make_diff make *.orig and diffs of source make_diff make *.orig and diffs of source
make_etags make emacs 'etags' files make_etags make emacs 'etags' files
make_keywords make comparison of our keywords and SQL'92 make_keywords make comparison of our keywords and SQL'92
make_mkid make mkid ID files make_mkid make mkid ID files
mkldexport create AIX exports file pgcvslog used to generate a list of changes for each release
pgindent indents C source files
pgjindent indents Java source files
pginclude scripts for adding/removing include files pginclude scripts for adding/removing include files
unused_oids in pgsql/src/include/catalog pgindent indents source files
</PRE> pgtest a semi-automated build system
Let me note some of these. If you point your browser at the thread a thread testing script
<I>file:/usr/local/src/pgsql/src/tools/backend/index.html</I> </pre>
directory, you will see few paragraphs describing the data flow,
the backend components in a flow chart, and a description of the <p>In <i>src/include/catalog</i>:</p>
shared memory area. You can click on any flowchart box to see a
description. If you then click on the directory name, you will be <pre>
taken to the source directory, to browse the actual source code unused_oids a script which generates unused OIDs for use in system
behind it. We also have several README files in some source catalogs
directories to describe the function of the module. The browser duplicate_oids finds duplicate OIDs in system catalog definitions
will display these when you enter the directory also. The </pre>
<I>tools/backend</I> directory is also contained on our web page
under the title <I>How PostgreSQL Processes a Query.</I> If you point your browser at the <i>tools/backend/index.html</i>
file, you will see few paragraphs describing the data flow, the
<P>Second, you really should have an editor that can handle tags, backend components in a flow chart, and a description of the shared
so you can tag a function call to see the function definition, and memory area. You can click on any flowchart box to see a
then tag inside that function to see an even lower-level function, description. If you then click on the directory name, you will be
and then back out twice to return to the original function. Most taken to the source directory, to browse the actual source code
editors support this via <I>tags</I> or <I>etags</I> files.</P> behind it. We also have several README files in some source
directories to describe the function of the module. The browser
<P>Third, you need to get <I>id-utils</I> from:</P> will display these when you enter the directory also. The
<PRE> <i>tools/backend</i> directory is also contained on our web page
<A href= under the title <i>How PostgreSQL Processes a Query.</i>
"ftp://alpha.gnu.org/gnu/id-utils-3.2d.tar.gz">ftp://alpha.gnu.org/gnu/id-utils-3.2d.tar.gz</A> <p>Second, you really should have an editor that can handle tags,
<A href= so you can tag a function call to see the function definition, and
"ftp://tug.org/gnu/id-utils-3.2d.tar.gz">ftp://tug.org/gnu/id-utils-3.2d.tar.gz</A> then tag inside that function to see an even lower-level function,
<A href= and then back out twice to return to the original function. Most
"ftp://ftp.enst.fr/pub/gnu/gnits/id-utils-3.2d.tar.gz">ftp://ftp.enst.fr/pub/gnu/gnits/id-utils-3.2d.tar.gz</A> editors support this via <i>tags</i> or <i>etags</i> files.</p>
</PRE>
By running <I>tools/make_mkid</I>, an archive of source symbols can <p>Third, you need to get <i>id-utils</i> from <a href=
be created that can be rapidly queried like <I>grep</I> or edited. "ftp://ftp.gnu.org/gnu/id-utils/">ftp://ftp.gnu.org/gnu/id-utils/</a></p>
Others prefer <I>glimpse.</I>
<p>By running <i>tools/make_mkid</i>, an archive of source symbols
<P><I>make_diff</I> has tools to create patch diff files that can can be created that can be rapidly queried.</p>
be applied to the distribution. This produces context diffs, which
is our preferred format.</P> <p>Some developers make use of cscope, which can be found at <a
href="http://cscope.sf.net">http://cscope.sf.net/</a>. Others use
<P>Our standard format is to indent each code level with one tab, glimpse, which can be found at <a href=
where each tab is four spaces. You will need to set your editor to "http://webglimpse.net/">http://webglimpse.net/</a>.</p>
display tabs as four spaces:<BR>
</P> <p><i>tools/make_diff</i> has tools to create patch diff files that
<PRE> can be applied to the distribution. This produces context diffs,
which is our preferred format.</p>
<p>Our standard format is to indent each code level with one tab,
where each tab is four spaces. You will need to set your editor to
display tabs as four spaces:<br>
</p>
<pre>
vi in ~/.exrc: vi in ~/.exrc:
set tabstop=4 set tabstop=4
set sw=4 set sw=4
...@@ -286,26 +311,26 @@ ...@@ -286,26 +311,26 @@
or or
(c-add-style "pgsql" (c-add-style "pgsql"
'("bsd" '("bsd"
(indent-tabs-mode . t) (indent-tabs-mode . t)
(c-basic-offset . 4) (c-basic-offset . 4)
(tab-width . 4) (tab-width . 4)
(c-offsets-alist . (c-offsets-alist .
((case-label . +))) ((case-label . +)))
) )
nil ) ; t = set this style, nil = don't nil ) ; t = set this style, nil = don't
(defun pgsql-c-mode () (defun pgsql-c-mode ()
(c-mode) (c-mode)
(c-set-style "pgsql") (c-set-style "pgsql")
) )
and add this to your autoload list (modify file path in macro): and add this to your autoload list (modify file path in macro):
(setq auto-mode-alist (setq auto-mode-alist
(cons '("\\`/home/andrew/pgsql/.*\\.[chyl]\\'" . pgsql-c-mode) (cons '("\\`/home/andrew/pgsql/.*\\.[chyl]\\'" . pgsql-c-mode)
auto-mode-alist)) auto-mode-alist))
or or
/* /*
* Local variables: * Local variables:
...@@ -314,473 +339,498 @@ ...@@ -314,473 +339,498 @@
* c-basic-offset: 4 * c-basic-offset: 4
* End: * End:
*/ */
</PRE> </pre>
<BR>
<I>pgindent</I> will the format code by specifying flags to your <br>
operating system's utility <I>indent.</I> This <i>pgindent</i> will the format code by specifying flags to your
<A HREF="http://ezine.daemonnews.org/200112/single_coding_style.html"> operating system's utility <i>indent.</i> This <a href=
article</A> describes the value of a constent coding style. "http://ezine.daemonnews.org/200112/single_coding_style.html">article</a>
describes the value of a consistent coding style.
<P><I>pgindent</I> is run on all source files just before each beta <p><i>pgindent</i> is run on all source files just before each beta
test period. It auto-formats all source files to make them test period. It auto-formats all source files to make them
consistent. Comment blocks that need specific line breaks should be consistent. Comment blocks that need specific line breaks should be
formatted as <I>block comments,</I> where the comment starts as formatted as <i>block comments,</i> where the comment starts as
<CODE>/*------</CODE>. These comments will not be reformatted in <code>/*------</code>. These comments will not be reformatted in
any way.</P> any way.</p>
<P><I>pginclude</I> contains scripts used to add needed <p><i>pginclude</i> contains scripts used to add needed
<CODE>#include</CODE>'s to include files, and removed unneeded <code>#include</code>'s to include files, and removed unneeded
<CODE>#include</CODE>'s.</P> <code>#include</code>'s.</p>
<P>When adding system types, you will need to assign oids to them. <p>When adding system types, you will need to assign oids to them.
There is also a script called <I>unused_oids</I> in There is also a script called <i>unused_oids</i> in
<I>pgsql/src/include/catalog</I> that shows the unused oids.</P> <i>pgsql/src/include/catalog</i> that shows the unused oids.</p>
<H3><A name="1.6">1.6</A>) What books are good for developers?</H3> <h3><a name="1.10">1.10</a>) What books are good for
developers?</h3>
<P>I have four good books, <I>An Introduction to Database
Systems,</I> by C.J. Date, Addison, Wesley, <I>A Guide to the SQL <p>I have four good books, <i>An Introduction to Database
Standard,</I> by C.J. Date, et. al, Addison, Wesley, Systems,</i> by C.J. Date, Addison, Wesley, <i>A Guide to the SQL
<I>Fundamentals of Database Systems,</I> by Elmasri and Navathe, Standard,</i> by C.J. Date, et. al, Addison, Wesley,
and <I>Transaction Processing,</I> by Jim Gray, Morgan, <i>Fundamentals of Database Systems,</i> by Elmasri and Navathe,
Kaufmann</P> and <i>Transaction Processing,</i> by Jim Gray, Morgan,
Kaufmann</p>
<P>There is also a database performance site, with a handbook
on-line written by Jim Gray at <A href= <p>There is also a database performance site, with a handbook
"http://www.benchmarkresources.com">http://www.benchmarkresources.com.</A></P> on-line written by Jim Gray at <a href=
"http://www.benchmarkresources.com">http://www.benchmarkresources.com.</a>.</p>
<H3><A name="1.7">1.7</A>) What is configure all about?</H3>
<h3><a name="1.11">1.11</a>) What is configure all about?</h3>
<P>The files <I>configure</I> and <I>configure.in</I> are part of
the GNU <I>autoconf</I> package. Configure allows us to test for <p>The files <i>configure</i> and <i>configure.in</i> are part of
various capabilities of the OS, and to set variables that can then the GNU <i>autoconf</i> package. Configure allows us to test for
be tested in C programs and Makefiles. Autoconf is installed on the various capabilities of the OS, and to set variables that can then
PostgreSQL main server. To add options to configure, edit be tested in C programs and Makefiles. Autoconf is installed on the
<I>configure.in,</I> and then run <I>autoconf</I> to generate PostgreSQL main server. To add options to configure, edit
<I>configure.</I></P> <i>configure.in,</i> and then run <i>autoconf</i> to generate
<i>configure.</i></p>
<P>When <I>configure</I> is run by the user, it tests various OS
capabilities, stores those in <I>config.status</I> and <p>When <i>configure</i> is run by the user, it tests various OS
<I>config.cache,</I> and modifies a list of <I>*.in</I> files. For capabilities, stores those in <i>config.status</i> and
example, if there exists a <I>Makefile.in,</I> configure generates <i>config.cache,</i> and modifies a list of <i>*.in</i> files. For
a <I>Makefile</I> that contains substitutions for all @var@ example, if there exists a <i>Makefile.in,</i> configure generates
parameters found by configure.</P> a <i>Makefile</i> that contains substitutions for all @var@
parameters found by configure.</p>
<P>When you need to edit files, make sure you don't waste time
modifying files generated by <I>configure.</I> Edit the <I>*.in</I> <p>When you need to edit files, make sure you don't waste time
file, and re-run <I>configure</I> to recreate the needed file. If modifying files generated by <i>configure.</i> Edit the <i>*.in</i>
you run <I>make distclean</I> from the top-level source directory, file, and re-run <i>configure</i> to recreate the needed file. If
all files derived by configure are removed, so you see only the you run <i>make distclean</i> from the top-level source directory,
file contained in the source distribution.</P> all files derived by configure are removed, so you see only the
file contained in the source distribution.</p>
<H3><A name="1.8">1.8</A>) How do I add a new port?</H3>
<h3><a name="1.12">1.12</a>) How do I add a new port?</h3>
<P>There are a variety of places that need to be modified to add a
new port. First, start in the <I>src/template</I> directory. Add an <p>There are a variety of places that need to be modified to add a
appropriate entry for your OS. Also, use <I>src/config.guess</I> to new port. First, start in the <i>src/template</i> directory. Add an
add your OS to <I>src/template/.similar.</I> You shouldn't match appropriate entry for your OS. Also, use <i>src/config.guess</i> to
the OS version exactly. The <I>configure</I> test will look for an add your OS to <i>src/template/.similar.</i> You shouldn't match
exact OS version number, and if not found, find a match without the OS version exactly. The <i>configure</i> test will look for an
version number. Edit <I>src/configure.in</I> to add your new OS. exact OS version number, and if not found, find a match without
(See configure item above.) You will need to run autoconf, or patch version number. Edit <i>src/configure.in</i> to add your new OS.
<I>src/configure</I> too.</P> (See configure item above.) You will need to run autoconf, or patch
<i>src/configure</i> too.</p>
<P>Then, check <I>src/include/port</I> and add your new OS file,
with appropriate values. Hopefully, there is already locking code <p>Then, check <i>src/include/port</i> and add your new OS file,
in <I>src/include/storage/s_lock.h</I> for your CPU. There is also with appropriate values. Hopefully, there is already locking code
a <I>src/makefiles</I> directory for port-specific Makefile in <i>src/include/storage/s_lock.h</i> for your CPU. There is also
handling. There is a <I>backend/port</I> directory if you need a <i>src/makefiles</i> directory for port-specific Makefile
special files for your OS.</P> handling. There is a <i>backend/port</i> directory if you need
special files for your OS.</p>
<H3><A name="1.9">1.9</A>) Why don't you use threads/raw
devices/async-I/O, &lt;insert your favorite wizz-bang feature <h3><a name="1.13">1.13</a>) Why don't you use threads/raw
here&gt;?</H3> devices/async-I/O, &lt;insert your favorite wizz-bang feature
here&gt;?</h3>
<P>There is always a temptation to use the newest operating system
features as soon as they arrive. We resist that temptation.</P> <p>There is always a temptation to use the newest operating system
features as soon as they arrive. We resist that temptation.</p>
<P>First, we support 15+ operating systems, so any new feature has
to be well established before we will consider it. Second, most new <p>First, we support 15+ operating systems, so any new feature has
<I>wizz-bang</I> features don't provide <I>dramatic</I> to be well established before we will consider it. Second, most new
improvements. Third, they usually have some downside, such as <i>wizz-bang</i> features don't provide <i>dramatic</i>
decreased reliability or additional code required. Therefore, we improvements. Third, they usually have some downside, such as
don't rush to use new features but rather wait for the feature to be decreased reliability or additional code required. Therefore, we
established, then ask for testing to show that a measurable don't rush to use new features but rather wait for the feature to
improvement is possible.</P> be established, then ask for testing to show that a measurable
improvement is possible.</p>
<P>As an example, threads are not currently used in the backend code
because:</P> <p>As an example, threads are not currently used in the backend
code because:</p>
<UL>
<LI>Historically, threads were unsupported and buggy.</LI> <ul>
<li>Historically, threads were unsupported and buggy.</li>
<LI>An error in one backend can corrupt other backends.</LI>
<li>An error in one backend can corrupt other backends.</li>
<LI>Speed improvements using threads are small compared to the
remaining backend startup time.</LI> <li>Speed improvements using threads are small compared to the
remaining backend startup time.</li>
<LI>The backend code would be more complex.</LI>
</UL> <li>The backend code would be more complex.</li>
</ul>
<P>So, we are not ignorant of new features. It is just that
we are cautious about their adoption. The TODO list often <p>So, we are not ignorant of new features. It is just that we are
contains links to discussions showing our reasoning in cautious about their adoption. The TODO list often contains links
these areas.</P> to discussions showing our reasoning in these areas.</p>
<H3><A name="1.10">1.10</A>) How are RPM's packaged?</H3> <h3><a name="1.14">1.14</a>) How are RPMs packaged?</h3>
<P>This was written by Lamar Owen:</P> <p>This was written by Lamar Owen:</p>
<P>2001-05-03</P> <p>2001-05-03</p>
<P>As to how the RPMs are built -- to answer that question sanely <p>As to how the RPMs are built -- to answer that question sanely
requires me to know how much experience you have with the whole RPM requires me to know how much experience you have with the whole RPM
paradigm. 'How is the RPM built?' is a multifaceted question. The paradigm. 'How is the RPM built?' is a multifaceted question. The
obvious simple answer is that I maintain:</P> obvious simple answer is that I maintain:</p>
<OL> <ol>
<LI>A set of patches to make certain portions of the source tree <li>A set of patches to make certain portions of the source tree
'behave' in the different environment of the RPMset;</LI> 'behave' in the different environment of the RPMset;</li>
<LI>The initscript;</LI> <li>The initscript;</li>
<LI>Any other ancilliary scripts and files;</LI> <li>Any other ancilliary scripts and files;</li>
<LI>A README.rpm-dist document that tries to adequately document <li>A README.rpm-dist document that tries to adequately document
both the differences between the RPM build and the WHY of the both the differences between the RPM build and the WHY of the
differences, as well as useful RPM environment operations (like, differences, as well as useful RPM environment operations (like,
using syslog, upgrading, getting postmaster to start at OS boot, using syslog, upgrading, getting postmaster to start at OS boot,
etc);</LI> etc);</li>
<LI>The spec file that throws it all together. This is not a <li>The spec file that throws it all together. This is not a
trivial undertaking in a package of this size.</LI> trivial undertaking in a package of this size.</li>
</OL> </ol>
<P>I then download and build on as many different canonical <p>I then download and build on as many different canonical
distributions as I can -- currently I am able to build on Red Hat distributions as I can -- currently I am able to build on Red Hat
6.2, 7.0, and 7.1 on my personal hardware. Occasionally I receive 6.2, 7.0, and 7.1 on my personal hardware. Occasionally I receive
opportunity from certain commercial enterprises such as Great opportunity from certain commercial enterprises such as Great
Bridge and PostgreSQL, Inc. to build on other distributions.</P> Bridge and PostgreSQL, Inc. to build on other distributions.</p>
<P>I test the build by installing the resulting packages and <p>I test the build by installing the resulting packages and
running the regression tests. Once the build passes these tests, I running the regression tests. Once the build passes these tests, I
upload to the postgresql.org ftp server and make a release upload to the postgresql.org ftp server and make a release
announcement. I am also responsible for maintaining the RPM announcement. I am also responsible for maintaining the RPM
download area on the ftp site.</P> download area on the ftp site.</p>
<P>You'll notice I said 'canonical' distributions above. That <p>You'll notice I said 'canonical' distributions above. That
simply means that the machine is as stock 'out of the box' as simply means that the machine is as stock 'out of the box' as
practical -- that is, everything (except select few programs) on practical -- that is, everything (except select few programs) on
these boxen are installed by RPM; only official Red Hat released these boxen are installed by RPM; only official Red Hat released
RPMs are used (except in unusual circumstances involving software RPMs are used (except in unusual circumstances involving software
that will not alter the build -- for example, installing a newer that will not alter the build -- for example, installing a newer
non-RedHat version of the Dia diagramming package is OK -- non-RedHat version of the Dia diagramming package is OK --
installing Python 2.1 on the box that has Python 1.5.2 installed is installing Python 2.1 on the box that has Python 1.5.2 installed is
not, as that alters the PostgreSQL build). The RPM as uploaded is not, as that alters the PostgreSQL build). The RPM as uploaded is
built to as close to out-of-the-box pristine as is possible. Only built to as close to out-of-the-box pristine as is possible. Only
the standard released 'official to that release' compiler is used the standard released 'official to that release' compiler is used
-- and only the standard official kernel is used as well.</P> -- and only the standard official kernel is used as well.</p>
<P>For a time I built on Mandrake for RedHat consumption -- no <p>For a time I built on Mandrake for RedHat consumption -- no
more. Nonstandard RPM building systems are worse than useless. more. Nonstandard RPM building systems are worse than useless.
Which is not to say that Mandrake is useless! By no means is Which is not to say that Mandrake is useless! By no means is
Mandrake useless -- unless you are building Red Hat RPMs -- and Red Mandrake useless -- unless you are building Red Hat RPMs -- and Red
Hat is useless if you're trying to build Mandrake or SuSE RPMs, for Hat is useless if you're trying to build Mandrake or SuSE RPMs, for
that matter. But I would be foolish to use 'Lamar Owen's Super that matter. But I would be foolish to use 'Lamar Owen's Super
Special RPM Blend Distro 0.1.2' to build for public consumption! Special RPM Blend Distro 0.1.2' to build for public consumption!
:-)</P> :-)</p>
<P>I _do_ attempt to make the _source_ RPM compatible with as many <p>I _do_ attempt to make the _source_ RPM compatible with as many
distributions as possible -- however, since I have limited distributions as possible -- however, since I have limited
resources (as a volunteer RPM maintainer) I am limited as to the resources (as a volunteer RPM maintainer) I am limited as to the
amount of testing said build will get on other distributions, amount of testing said build will get on other distributions,
architectures, or systems.</P> architectures, or systems.</p>
<P>And, while I understand people's desire to immediately upgrade <p>And, while I understand people's desire to immediately upgrade
to the newest version, realize that I do this as a side interest -- to the newest version, realize that I do this as a side interest --
I have a regular, full-time job as a broadcast I have a regular, full-time job as a broadcast
engineer/webmaster/sysadmin/Technical Director which occasionally engineer/webmaster/sysadmin/Technical Director which occasionally
prevents me from making timely RPM releases. This happened during prevents me from making timely RPM releases. This happened during
the early part of the 7.1 beta cycle -- but I believe I was pretty the early part of the 7.1 beta cycle -- but I believe I was pretty
much on the ball for the Release Candidates and the final much on the ball for the Release Candidates and the final
release.</P> release.</p>
<P>I am working towards a more open RPM distribution -- I would <p>I am working towards a more open RPM distribution -- I would
dearly love to more fully document the process and put everything dearly love to more fully document the process and put everything
into CVS -- once I figure out how I want to represent things such into CVS -- once I figure out how I want to represent things such
as the spec file in a CVS form. It makes no sense to maintain a as the spec file in a CVS form. It makes no sense to maintain a
changelog, for instance, in the spec file in CVS when CVS does a changelog, for instance, in the spec file in CVS when CVS does a
better job of changelogs -- I will need to write a tool to generate better job of changelogs -- I will need to write a tool to generate
a real spec file from a CVS spec-source file that would add version a real spec file from a CVS spec-source file that would add version
numbers, changelog entries, etc to the result before building the numbers, changelog entries, etc to the result before building the
RPM. IOW, I need to rethink the process -- and then go through the RPM. IOW, I need to rethink the process -- and then go through the
motions of putting my long RPM history into CVS one version at a motions of putting my long RPM history into CVS one version at a
time so that version history information isn't lost.</P> time so that version history information isn't lost.</p>
<P>As to why all these files aren't part of the source tree, well, <p>As to why all these files aren't part of the source tree, well,
unless there was a large cry for it to happen, I don't believe it unless there was a large cry for it to happen, I don't believe it
should. PostgreSQL is very platform-agnostic -- and I like that. should. PostgreSQL is very platform-agnostic -- and I like that.
Including the RPM stuff as part of the Official Tarball (TM) would, Including the RPM stuff as part of the Official Tarball (TM) would,
IMHO, slant that agnostic stance in a negative way. But maybe I'm IMHO, slant that agnostic stance in a negative way. But maybe I'm
too sensitive to that. I'm not opposed to doing that if that is the too sensitive to that. I'm not opposed to doing that if that is the
consensus of the core group -- and that would be a sneaky way to consensus of the core group -- and that would be a sneaky way to
get the stuff into CVS :-). But if the core group isn't thrilled get the stuff into CVS :-). But if the core group isn't thrilled
with the idea (and my instinct says they're not likely to be), I am with the idea (and my instinct says they're not likely to be), I am
opposed to the idea -- not to keep the stuff to myself, but to not opposed to the idea -- not to keep the stuff to myself, but to not
hinder the platform-neutral stance. IMHO, of course.</P> hinder the platform-neutral stance. IMHO, of course.</p>
<P>Of course, there are many projects that DO include all the files <p>Of course, there are many projects that DO include all the files
necessary to build RPMs from their Official Tarball (TM).</P> necessary to build RPMs from their Official Tarball (TM).</p>
<H3><A name="1.11">1.11</A>) How are CVS branches managed?</H3> <h3><a name="1.15">1.15</a>) How are CVS branches managed?</h3>
<P>This was written by Tom Lane:</P> <p>This was written by Tom Lane:</p>
<P>2001-05-07</P> <p>2001-05-07</p>
<P>If you just do basic "cvs checkout", "cvs update", "cvs commit", <p>If you just do basic "cvs checkout", "cvs update", "cvs commit",
then you'll always be dealing with the HEAD version of the files in then you'll always be dealing with the HEAD version of the files in
CVS. That's what you want for development, but if you need to patch CVS. That's what you want for development, but if you need to patch
past stable releases then you have to be able to access and update past stable releases then you have to be able to access and update
the "branch" portions of our CVS repository. We normally fork off a the "branch" portions of our CVS repository. We normally fork off a
branch for a stable release just before starting the development branch for a stable release just before starting the development
cycle for the next release.</P> cycle for the next release.</p>
<P>The first thing you have to know is the branch name for the <p>The first thing you have to know is the branch name for the
branch you are interested in getting at. To do this, look at some branch you are interested in getting at. To do this, look at some
long-lived file, say the top-level HISTORY file, with "cvs status long-lived file, say the top-level HISTORY file, with "cvs status
-v" to see what the branch names are. (Thanks to Ian Lance Taylor -v" to see what the branch names are. (Thanks to Ian Lance Taylor
for pointing out that this is the easiest way to do it.) Typical for pointing out that this is the easiest way to do it.) Typical
branch names are:</P> branch names are:</p>
<PRE>
<pre>
REL7_1_STABLE REL7_1_STABLE
REL7_0_PATCHES REL7_0_PATCHES
REL6_5_PATCHES REL6_5_PATCHES
</PRE> </pre>
<P>OK, so how do you do work on a branch? By far the best way is to <p>OK, so how do you do work on a branch? By far the best way is to
create a separate checkout tree for the branch and do your work in create a separate checkout tree for the branch and do your work in
that. Not only is that the easiest way to deal with CVS, but you that. Not only is that the easiest way to deal with CVS, but you
really need to have the whole past tree available anyway to test really need to have the whole past tree available anyway to test
your work. (And you *better* test your work. Never forget that your work. (And you *better* test your work. Never forget that
dot-releases tend to go out with very little beta testing --- so dot-releases tend to go out with very little beta testing --- so
whenever you commit an update to a stable branch, you'd better be whenever you commit an update to a stable branch, you'd better be
doubly sure that it's correct.)</P> doubly sure that it's correct.)</p>
<P>Normally, to checkout the head branch, you just cd to the place <p>Normally, to checkout the head branch, you just cd to the place
you want to contain the toplevel "pgsql" directory and say</P> you want to contain the toplevel "pgsql" directory and say</p>
<PRE>
<pre>
cvs ... checkout pgsql cvs ... checkout pgsql
</PRE> </pre>
<p>To get a past branch, you cd to whereever you want it and
say</p>
<P>To get a past branch, you cd to whereever you want it and <pre>
say</P>
<PRE>
cvs ... checkout -r BRANCHNAME pgsql cvs ... checkout -r BRANCHNAME pgsql
</PRE> </pre>
<p>For example, just a couple days ago I did</p>
<P>For example, just a couple days ago I did</P> <pre>
<PRE>
mkdir ~postgres/REL7_1 mkdir ~postgres/REL7_1
cd ~postgres/REL7_1 cd ~postgres/REL7_1
cvs ... checkout -r REL7_1_STABLE pgsql cvs ... checkout -r REL7_1_STABLE pgsql
</PRE> </pre>
<P>and now I have a maintenance copy of 7.1.*.</P> <p>and now I have a maintenance copy of 7.1.*.</p>
<P>When you've done a checkout in this way, the branch name is <p>When you've done a checkout in this way, the branch name is
"sticky": CVS automatically knows that this directory tree is for "sticky": CVS automatically knows that this directory tree is for
the branch, and whenever you do "cvs update" or "cvs commit" in the branch, and whenever you do "cvs update" or "cvs commit" in
this tree, you'll fetch or store the latest version in the branch, this tree, you'll fetch or store the latest version in the branch,
not the head version. Easy as can be.</P> not the head version. Easy as can be.</p>
<P>So, if you have a patch that needs to apply to both the head and <p>So, if you have a patch that needs to apply to both the head and
a recent stable branch, you have to make the edits and do the a recent stable branch, you have to make the edits and do the
commit twice, once in your development tree and once in your stable commit twice, once in your development tree and once in your stable
branch tree. This is kind of a pain, which is why we don't normally branch tree. This is kind of a pain, which is why we don't normally
fork the tree right away after a major release --- we wait for a fork the tree right away after a major release --- we wait for a
dot-release or two, so that we won't have to double-patch the first dot-release or two, so that we won't have to double-patch the first
wave of fixes.</P> wave of fixes.</p>
<H3><A name="1.12">1.12</A>) Where can I get a copy of the SQL <h3><a name="1.16">1.16</a>) Where can I get a copy of the SQL
standards?</H3> standards?</h3>
<P>There are three versions of the SQL standard: SQL-92, SQL:1999, <p>There are three versions of the SQL standard: SQL-92, SQL:1999,
and SQL:2003. They are endorsed by ANSI and ISO. Draft versions and SQL:2003. They are endorsed by ANSI and ISO. Draft versions can
can be downloaded from: be downloaded from:</p>
<ul>
<li> SQL-92 <a <ul>
href="http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt"> <li>SQL-92 <a href=
http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt</a></li> "http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt">http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt</a></li>
<li> SQL:1999 <a
href="http://www.cse.iitb.ac.in/dbms/Data/Papers-Other/SQL1999/ansi-iso-9075-2-1999.pdf"> <li>SQL:1999 <a href=
http://www.cse.iitb.ac.in/dbms/Data/Papers-Other/SQL1999/ansi-iso-9075-2-1999.pdf</a></li> "http://www.cse.iitb.ac.in/dbms/Data/Papers-Other/SQL1999/ansi-iso-9075-2-1999.pdf">
<li> SQL:2003 <a http://www.cse.iitb.ac.in/dbms/Data/Papers-Other/SQL1999/ansi-iso-9075-2-1999.pdf</a></li>
href="http://www.wiscorp.com/sql/sql_2003_standard.zip">
http://www.wiscorp.com/sql/sql_2003_standard.zip</A></li> <li>SQL:2003 <a href=
</ul> "http://www.wiscorp.com/sql/sql_2003_standard.zip">http://www.wiscorp.com/sql/sql_2003_standard.zip</a></li>
</ul>
<P>Some SQL standards web pages are:
<ul> <p>Some SQL standards web pages are:</p>
<li><a
href="http://troels.arvin.dk/db/rdbms/links/#standards"> <ul>
http://troels.arvin.dk/db/rdbms/links/#standards</a></li> <li><a href=
<li><a "http://troels.arvin.dk/db/rdbms/links/#standards">http://troels.arvin.dk/db/rdbms/links/#standards</a></li>
href="http://www.wiscorp.com/SQLStandards.html">
http://www.wiscorp.com/SQLStandards.html</a></li> <li><a href=
<li><a "http://www.wiscorp.com/SQLStandards.html">http://www.wiscorp.com/SQLStandards.html</a></li>
href="http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax">
http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax</a> (SQL-92)</li> <li><a href=
<li><a "http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax">http://www.contrib.andrew.cmu.edu/~shadow/sql.html#syntax</a>
href="http://dbs.uni-leipzig.de/en/lokal/standards.pdf"> (SQL-92)</li>
http://dbs.uni-leipzig.de/en/lokal/standards.pdf</a> (paper)</li>
</ul> <li><a href=
"http://dbs.uni-leipzig.de/en/lokal/standards.pdf">http://dbs.uni-leipzig.de/en/lokal/standards.pdf</a>
<H3><A name="1.13">1.13</A>) How go I get involved in PostgreSQL (paper)</li>
web site development?</H3> </ul>
<P>PostgreSQL website development is discussed on the <h3><a name="1.17">1.17</a>) Where can I get technical
pgsql-www@postgresql.org mailing list. The is a project page where assistance?</h3>
the source code is available at <a
href="http://gborg.postgresql.org/project/pgweb/projdisplay.php">http://gborg.postgresql.org/project/pgweb/projdisplay.php <p>Many technical questions held by those new to the code have been
</a>, the code for the next version of the website is under the "portal" answered on the pgsql-hackers mailing list - the archives of which
module. You will al so find code for the "techdocs" website if you would can be found at <a href=
like to contribute to that. A temporary todo list for current website "http://archives.postgresql.org/pgsql-hackers/">http://archives.postgresql.org/pgsql-hackers/</a>.</p>
development issues is available at <a
href="http://xzilla.postgresql.org/todo">http://xzilla.postgresql.org/todo</a></P> <p>If you cannot find discussion or your particular question, feel
free to put it to the list.</p>
<CENTER> <p>Major contributors also answer technical questions, including
<H2>Technical Questions</H2> questions about development of new features, on IRC at
</CENTER> irc.freenode.net in the #postgresql channel.</p>
<H3><A name="2.1">2.1</A>) How do I efficiently access information in <h3><a name="1.18">1.18</a>) How go I get involved in PostgreSQL
tables from the backend code?</H3> web site development?</h3>
<P>You first need to find the tuples(rows) you are interested in. <p>PostgreSQL website development is discussed on the
There are two ways. First, <I>SearchSysCache()</I> and related pgsql-www@postgresql.org mailing list. The is a project page where
functions allow you to query the system catalogs. This is the the source code is available at <a href=
preferred way to access system tables, because the first call to "http://gborg.postgresql.org/project/pgweb/projdisplay.php">http://gborg.postgresql.org/project/pgweb/projdisplay.php</a>
the cache loads the needed rows, and future requests can return the , the code for the next version of the website is under the
results without accessing the base table. The caches use system "portal" module. You will al so find code for the "techdocs"
table indexes to look up tuples. A list of available caches is website if you would like to contribute to that. A temporary todo
located in <I>src/backend/utils/cache/syscache.c.</I> list for current website development issues is available at <a
<I>src/backend/utils/cache/lsyscache.c</I> contains many href=
column-specific cache lookup functions.</P> "http://xzilla.postgresql.org/todo">http://xzilla.postgresql.org/todo</a></p>
<P>The rows returned are cache-owned versions of the heap rows. <center>
Therefore, you must not modify or delete the tuple returned by <h2>Technical Questions</h2>
<I>SearchSysCache()</I>. What you <I>should</I> do is release it </center>
with <I>ReleaseSysCache()</I> when you are done using it; this
informs the cache that it can discard that tuple if necessary. If <h3><a name="2.1">2.1</a>) How do I efficiently access information
you neglect to call <I>ReleaseSysCache()</I>, then the cache entry in tables from the backend code?</h3>
will remain locked in the cache until end of transaction, which is
tolerable but not very desirable.</P> <p>You first need to find the tuples(rows) you are interested in.
There are two ways. First, <i>SearchSysCache()</i> and related
<P>If you can't use the system cache, you will need to retrieve the functions allow you to query the system catalogs. This is the
data directly from the heap table, using the buffer cache that is preferred way to access system tables, because the first call to
shared by all backends. The backend automatically takes care of the cache loads the needed rows, and future requests can return the
loading the rows into the buffer cache.</P> results without accessing the base table. The caches use system
table indexes to look up tuples. A list of available caches is
<P>Open the table with <I>heap_open().</I> You can then start a located in <i>src/backend/utils/cache/syscache.c.</i>
table scan with <I>heap_beginscan(),</I> then use <i>src/backend/utils/cache/lsyscache.c</i> contains many
<I>heap_getnext()</I> and continue as long as column-specific cache lookup functions.</p>
<I>HeapTupleIsValid()</I> returns true. Then do a
<I>heap_endscan().</I> <I>Keys</I> can be assigned to the <p>The rows returned are cache-owned versions of the heap rows.
<I>scan.</I> No indexes are used, so all rows are going to be Therefore, you must not modify or delete the tuple returned by
compared to the keys, and only the valid rows returned.</P> <i>SearchSysCache()</i>. What you <i>should</i> do is release it
with <i>ReleaseSysCache()</i> when you are done using it; this
<P>You can also use <I>heap_fetch()</I> to fetch rows by block informs the cache that it can discard that tuple if necessary. If
number/offset. While scans automatically lock/unlock rows from the you neglect to call <i>ReleaseSysCache()</i>, then the cache entry
buffer cache, with <I>heap_fetch(),</I> you must pass a will remain locked in the cache until end of transaction, which is
<I>Buffer</I> pointer, and <I>ReleaseBuffer()</I> it when tolerable but not very desirable.</p>
completed.</P>
<p>If you can't use the system cache, you will need to retrieve the
<P>Once you have the row, you can get data that is common to all data directly from the heap table, using the buffer cache that is
tuples, like <I>t_self</I> and <I>t_oid,</I> by merely accessing shared by all backends. The backend automatically takes care of
the <I>HeapTuple</I> structure entries. If you need a loading the rows into the buffer cache.</p>
table-specific column, you should take the HeapTuple pointer, and
use the <I>GETSTRUCT()</I> macro to access the table-specific start <p>Open the table with <i>heap_open().</i> You can then start a
of the tuple. You then cast the pointer as a <I>Form_pg_proc</I> table scan with <i>heap_beginscan(),</i> then use
pointer if you are accessing the pg_proc table, or <i>heap_getnext()</i> and continue as long as
<I>Form_pg_type</I> if you are accessing pg_type. You can then <i>HeapTupleIsValid()</i> returns true. Then do a
access the columns by using a structure pointer:</P> <i>heap_endscan().</i> <i>Keys</i> can be assigned to the
<PRE> <i>scan.</i> No indexes are used, so all rows are going to be
<CODE>((Form_pg_class) GETSTRUCT(tuple))-&gt;relnatts compared to the keys, and only the valid rows returned.</p>
</CODE>
</PRE> <p>You can also use <i>heap_fetch()</i> to fetch rows by block
You must not directly change <I>live</I> tuples in this way. The number/offset. While scans automatically lock/unlock rows from the
best way is to use <I>heap_modifytuple()</I> and pass it your buffer cache, with <i>heap_fetch(),</i> you must pass a
original tuple, and the values you want changed. It returns a <i>Buffer</i> pointer, and <i>ReleaseBuffer()</i> it when
palloc'ed tuple, which you pass to <I>heap_replace().</I> You can completed.</p>
delete tuples by passing the tuple's <I>t_self</I> to
<I>heap_destroy().</I> You use <I>t_self</I> for <p>Once you have the row, you can get data that is common to all
<I>heap_update()</I> too. Remember, tuples can be either system tuples, like <i>t_self</i> and <i>t_oid,</i> by merely accessing
cache copies, which may go away after you call the <i>HeapTuple</i> structure entries. If you need a
<I>ReleaseSysCache()</I>, or read directly from disk buffers, which table-specific column, you should take the HeapTuple pointer, and
go away when you <I>heap_getnext()</I>, <I>heap_endscan</I>, or use the <i>GETSTRUCT()</i> macro to access the table-specific start
<I>ReleaseBuffer()</I>, in the <I>heap_fetch()</I> case. Or it may of the tuple. You then cast the pointer as a <i>Form_pg_proc</i>
be a palloc'ed tuple, that you must <I>pfree()</I> when finished. pointer if you are accessing the pg_proc table, or
<i>Form_pg_type</i> if you are accessing pg_type. You can then
<H3><A name="2.2">2.2</A>) Why are table, column, type, function, view access the columns by using a structure pointer:</p>
names sometimes referenced as <I>Name</I> or <I>NameData,</I> and
sometimes as <I>char *?</I></H3> <pre>
<code>((Form_pg_class) GETSTRUCT(tuple))-&gt;relnatts
<P>Table, column, type, function, and view names are stored in </code>
system tables in columns of type <I>Name.</I> Name is a </pre>
fixed-length, null-terminated type of <I>NAMEDATALEN</I> bytes.
(The default value for NAMEDATALEN is 64 bytes.)</P> You must not directly change <i>live</i> tuples in this way. The
<PRE> best way is to use <i>heap_modifytuple()</i> and pass it your
<CODE>typedef struct nameData original tuple, and the values you want changed. It returns a
palloc'ed tuple, which you pass to <i>heap_replace().</i> You can
delete tuples by passing the tuple's <i>t_self</i> to
<i>heap_destroy().</i> You use <i>t_self</i> for
<i>heap_update()</i> too. Remember, tuples can be either system
cache copies, which may go away after you call
<i>ReleaseSysCache()</i>, or read directly from disk buffers, which
go away when you <i>heap_getnext()</i>, <i>heap_endscan</i>, or
<i>ReleaseBuffer()</i>, in the <i>heap_fetch()</i> case. Or it may
be a palloc'ed tuple, that you must <i>pfree()</i> when finished.
<h3><a name="2.2">2.2</a>) Why are table, column, type, function,
view names sometimes referenced as <i>Name</i> or <i>NameData,</i>
and sometimes as <i>char *?</i></h3>
<p>Table, column, type, function, and view names are stored in
system tables in columns of type <i>Name.</i> Name is a
fixed-length, null-terminated type of <i>NAMEDATALEN</i> bytes.
(The default value for NAMEDATALEN is 64 bytes.)</p>
<pre>
<code>typedef struct nameData
{ {
char data[NAMEDATALEN]; char data[NAMEDATALEN];
} NameData; } NameData;
typedef NameData *Name; typedef NameData *Name;
</CODE> </code>
</PRE> </pre>
Table, column, type, function, and view names that come into the
backend via user queries are stored as variable-length, Table, column, type, function, and view names that come into the
null-terminated character strings. backend via user queries are stored as variable-length,
null-terminated character strings.
<P>Many functions are called with both types of names, ie. <p>Many functions are called with both types of names, ie.
<I>heap_open().</I> Because the Name type is null-terminated, it is <i>heap_open().</i> Because the Name type is null-terminated, it is
safe to pass it to a function expecting a char *. Because there are safe to pass it to a function expecting a char *. Because there are
many cases where on-disk names(Name) are compared to user-supplied many cases where on-disk names(Name) are compared to user-supplied
names(char *), there are many cases where Name and char * are used names(char *), there are many cases where Name and char * are used
interchangeably.</P> interchangeably.</p>
<H3><A name="2.3">2.3</A>) Why do we use <I>Node</I> and <I>List</I> to <h3><a name="2.3">2.3</a>) Why do we use <i>Node</i> and
make data structures?</H3> <i>List</i> to make data structures?</h3>
<P>We do this because this allows a consistent way to pass data <p>We do this because this allows a consistent way to pass data
inside the backend in a flexible way. Every node has a inside the backend in a flexible way. Every node has a
<I>NodeTag</I> which specifies what type of data is inside the <i>NodeTag</i> which specifies what type of data is inside the
Node. <I>Lists</I> are groups of <I>Nodes chained together as a Node. <i>Lists</i> are groups of <i>Nodes chained together as a
forward-linked list.</I></P> forward-linked list.</i></p>
<P>Here are some of the <I>List</I> manipulation commands:</P> <p>Here are some of the <i>List</i> manipulation commands:</p>
<BLOCKQUOTE> <blockquote>
<DL> <dl>
<DT>lfirst(i)</DT> <dt>lfirst(i), lfirst_int(i), lfirst_oid(i)</dt>
<DD>return the data at list element <I>i.</I></DD> <dd>return the data (a point, inteter and OID respectively) at list
element <i>i.</i></dd>
<DT>lnext(i)</DT>
<dt>lnext(i)</dt>
<DD>return the next list element after <I>i.</I></DD>
<dd>return the next list element after <i>i.</i></dd>
<DT>foreach(i, list)</DT>
<dt>foreach(i, list)</dt>
<DD>
loop through <I>list,</I> assigning each list element to <dd>loop through <i>list,</i> assigning each list element to
<I>i.</I> It is important to note that <I>i</I> is a List *, <i>i.</i> It is important to note that <i>i</i> is a List *, not
not the data in the <I>List</I> element. You need to use the data in the <i>List</i> element. You need to use
<I>lfirst(i)</I> to get at the data. Here is a typical code <i>lfirst(i)</i> to get at the data. Here is a typical code snippet
snippet that loops through a List containing <I>Var *'s</I> that loops through a List containing <i>Var *'s</i> and processes
and processes each one: each one:
<PRE> <pre>
<CODE>List *i, *list; <code> List *list;
ListCell *i;
foreach(i, list) foreach(i, list)
{ {
...@@ -788,109 +838,114 @@ ...@@ -788,109 +838,114 @@
/* process var here */ /* process var here */
} }
</CODE> </code>
</PRE> </pre>
</DD> </dd>
<DT>lcons(node, list)</DT> <dt>lcons(node, list)</dt>
<DD>add <I>node</I> to the front of <I>list,</I> or create a <dd>add <i>node</i> to the front of <i>list,</i> or create a new
new list with <I>node</I> if <I>list</I> is <I>NIL.</I></DD> list with <i>node</i> if <i>list</i> is <i>NIL.</i></dd>
<DT>lappend(list, node)</DT> <dt>lappend(list, node)</dt>
<DD>add <I>node</I> to the end of <I>list.</I> This is more <dd>add <i>node</i> to the end of <i>list.</i> This is more
expensive that lcons.</DD> expensive that lcons.</dd>
<DT>nconc(list1, list2)</DT> <dt>nconc(list1, list2)</dt>
<DD>Concat <I>list2</I> on to the end of <I>list1.</I></DD> <dd>Concat <i>list2</i> on to the end of <i>list1.</i></dd>
<DT>length(list)</DT> <dt>length(list)</dt>
<DD>return the length of the <I>list.</I></DD> <dd>return the length of the <i>list.</i></dd>
<DT>nth(i, list)</DT> <dt>nth(i, list)</dt>
<DD>return the <I>i</I>'th element in <I>list.</I></DD> <dd>return the <i>i</i>'th element in <i>list.</i></dd>
<DT>lconsi, ...</DT> <dt>lconsi, ...</dt>
<DD>There are integer versions of these: <I>lconsi, lappendi</I>, <dd>There are integer versions of these: <i>lconsi, lappendi</i>,
etc. Also versions for OID lists: <I>lconso, lappendo</I>, etc.</DD> etc. Also versions for OID lists: <i>lconso, lappendo</i>,
</DL> etc.</dd>
</BLOCKQUOTE> </dl>
You can print nodes easily inside <I>gdb.</I> First, to disable </blockquote>
output truncation when you use the gdb <I>print</I> command:
<PRE> You can print nodes easily inside <i>gdb.</i> First, to disable
<CODE>(gdb) set print elements 0 output truncation when you use the gdb <i>print</i> command:
</CODE> <pre>
</PRE> <code>(gdb) set print elements 0
Instead of printing values in gdb format, you can use the next two </code>
commands to print out List, Node, and structure contents in a </pre>
verbose format that is easier to understand. List's are unrolled
into nodes, and nodes are printed in detail. The first prints in a Instead of printing values in gdb format, you can use the next two
short format, and the second in a long format: commands to print out List, Node, and structure contents in a
<PRE> verbose format that is easier to understand. List's are unrolled
<CODE>(gdb) call print(any_pointer) into nodes, and nodes are printed in detail. The first prints in a
short format, and the second in a long format:
<pre>
<code>(gdb) call print(any_pointer)
(gdb) call pprint(any_pointer) (gdb) call pprint(any_pointer)
</CODE> </code>
</PRE> </pre>
The output appears in the postmaster log file, or on your screen if
you are running a backend directly without a postmaster. The output appears in the postmaster log file, or on your screen if
you are running a backend directly without a postmaster.
<H3><A name="2.4">2.4</A>) I just added a field to a structure. What <h3><a name="2.4">2.4</a>) I just added a field to a structure.
else should I do?</H3> What else should I do?</h3>
<P>The structures passing around from the parser, rewrite, <p>The structures passing around from the parser, rewrite,
optimizer, and executor require quite a bit of support. Most optimizer, and executor require quite a bit of support. Most
structures have support routines in <I>src/backend/nodes</I> used structures have support routines in <i>src/backend/nodes</i> used
to create, copy, read, and output those structures. Make sure you to create, copy, read, and output those structures (in particular,
add support for your new field to these files. Find any other the files <i>copyfuncs.c</i> and <i>equalfuncs.c</i>. Make sure you
places the structure may need code for your new field. <I>mkid</I> add support for your new field to these files. Find any other
is helpful with this (see above).</P> places the structure may need code for your new field. <i>mkid</i>
is helpful with this (see <a href="#1.9">1.9</a>).</p>
<H3><A name="2.5">2.5</A>) Why do we use <I>palloc</I>() and
<I>pfree</I>() to allocate memory?</H3> <h3><a name="2.5">2.5</a>) Why do we use <i>palloc</i>() and
<i>pfree</i>() to allocate memory?</h3>
<P><I>palloc()</I> and <I>pfree()</I> are used in place of malloc()
and free() because we find it easier to automatically free all <p><i>palloc()</i> and <i>pfree()</i> are used in place of malloc()
memory allocated when a query completes. This assures us that all and free() because we find it easier to automatically free all
memory that was allocated gets freed even if we have lost track of memory allocated when a query completes. This assures us that all
where we allocated it. There are special non-query contexts that memory that was allocated gets freed even if we have lost track of
memory can be allocated in. These affect when the allocated memory where we allocated it. There are special non-query contexts that
is freed by the backend.</P> memory can be allocated in. These affect when the allocated memory
is freed by the backend.</p>
<H3><A name="2.6">2.6</A>) What is ereport()?</H3>
<h3><a name="2.6">2.6</a>) What is ereport()?</h3>
<P><I>ereport()</I> is used to send messages to the front-end, and
optionally terminate the current query being processed. The first <p><i>ereport()</i> is used to send messages to the front-end, and
parameter is an ereport level of <I>DEBUG</I> (levels 1-5), <I>LOG,</I> optionally terminate the current query being processed. The first
<I>INFO,</I> <I>NOTICE,</I> <I>ERROR,</I> <I>FATAL,</I> or parameter is an ereport level of <i>DEBUG</i> (levels 1-5),
<I>PANIC.</I> <I>NOTICE</I> prints on the user's terminal and the <i>LOG,</i> <i>INFO,</i> <i>NOTICE,</i> <i>ERROR,</i> <i>FATAL,</i>
postmaster logs. <I>INFO</I> prints only to the user's terminal and or <i>PANIC.</i> <i>NOTICE</i> prints on the user's terminal and
<I>LOG</I> prints only to the server logs. (These can be changed the postmaster logs. <i>INFO</i> prints only to the user's terminal
from <I>postgresql.conf.</I>) <I>ERROR</I> prints in both places, and <i>LOG</i> prints only to the server logs. (These can be
and terminates the current query, never returning from the call. changed from <i>postgresql.conf.</i>) <i>ERROR</i> prints in both
<I>FATAL</I> terminates the backend process. The remaining places, and terminates the current query, never returning from the
parameters of <I>ereport</I> are a <I>printf</I>-style set of call. <i>FATAL</i> terminates the backend process. The remaining
parameters to print.</P> parameters of <i>ereport</i> are a <i>printf</i>-style set of
parameters to print.</p>
<P><I>ereport(ERROR)</I> frees most memory and open file descriptors so
you don't need to clean these up before the call.</P> <p><i>ereport(ERROR)</i> frees most memory and open file
descriptors so you don't need to clean these up before the
<H3><A name="2.7">2.7</A>) What is CommandCounterIncrement()?</H3> call.</p>
<P>Normally, transactions can not see the rows they modify. This <h3><a name="2.7">2.7</a>) What is CommandCounterIncrement()?</h3>
allows <CODE>UPDATE foo SET x = x + 1</CODE> to work correctly.</P>
<p>Normally, transactions can not see the rows they modify. This
<P>However, there are cases where a transactions needs to see rows allows <code>UPDATE foo SET x = x + 1</code> to work correctly.</p>
affected in previous parts of the transaction. This is accomplished
using a Command Counter. Incrementing the counter allows <p>However, there are cases where a transactions needs to see rows
transactions to be broken into pieces so each piece can see rows affected in previous parts of the transaction. This is accomplished
modified by previous pieces. <I>CommandCounterIncrement()</I> using a Command Counter. Incrementing the counter allows
increments the Command Counter, creating a new part of the transactions to be broken into pieces so each piece can see rows
transaction.</P> modified by previous pieces. <i>CommandCounterIncrement()</i>
increments the Command Counter, creating a new part of the
</BODY> transaction.</p>
</HTML> </body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment