Make LC_COLLATE and LC_CTYPE database-level settings. Collation and
[PostgreSQL.git] / doc / FAQ_AIX
blob6401eea1a5fbbbba3c2afc9dc77f0b08e407c014
1 =======================================================
2 Frequently Asked Questions (FAQ) for PostgreSQL
3 AIX Specific
4 TO BE READ IN CONJUNCTION WITH THE NORMAL FAQ
5 =======================================================
6 Last updated:        $Date: 2006/12/06 15:45:30 $
8 Topics
10 - AIX 4.3.2 Port Report
11 - AIX 5.3 Additional Information
12 - AIX, readline, and postgres 8.1.x:
13 - AIX Memory Management: An Overview
14 - Statistics Collector Fun on AIX
16 -----
18 From: Zeugswetter Andreas <ZeugswetterA@spardat.at>
19 $Date: 2006/12/06 15:45:30 $
21 On AIX 4.3.2 PostgreSQL compiled with the native IBM compiler xlc
22 (vac.C 5.0.1) passes all regression tests.  Other versions of OS and
23 compiler should also work. If you don't have a powerpc or use gcc you
24 might see rounding differences in the geometry regression test.
26 Use the following configure flags in addition to your own
27 if you have readline or libz there:
28 --with-includes=/usr/local/include --with-libraries=/usr/local/lib
30 There will probably be warnings about 0.0/0.0 division and duplicate
31 symbols which you can safely ignore.
33 Compiling PostgreSQL with gcc (2.95.3) on AIX also works.
35 You need libm.a that is in the fileset bos.adt.libm.  (Try the
36 following command.)
37 $ lslpp -l bos.adt.libm
40 ---
41 From: Christopher Browne <cbbrowne@ca.afilias.info>
42 Date: 2005-07-15
44 On AIX 5.3, there have been some problems getting PostgreSQL to
45 compile and run using GCC.
47 1.  You will want to use a version of GCC subsequent to 3.3.2,
48     particularly if you use a prepackaged version.  We had good
49     success with 4.0.1.
51     Problems with earlier versions seem to have more to do with the
52     way IBM packaged GCC than with actual issues with GCC, so that if
53     you compile GCC yourself, you might well have success with an
54     earlier version of GCC.
56 2.  AIX 5.3 has a problem where sockadr_storage is not defined to be
57     large enough.  In version 5.3, IBM increased the size of
58     sockaddr_un, the address structure for UNIX Domain Sockets, but
59     did not correspondingly increase the size of sockadr_storage.
61     The result of this is that attempts to use UDS with PostgreSQL
62     lead to libpq overflowing the data structure.  TCP/IP connections
63     work OK, but not UDS, which prevents the regression tests from
64     working.
66    The nonconformance may be readily demonstrated by compiling and
67    running the following C program which calculates and compares the
68    sizes of the various structures:
70 test_size.c
71 ------------
73 ---------- snip here - test_size.c ----------------------------
74 #include <stdio.h>
75 #include <sys/un.h>
76 #include <sys/socket.h>
77 int main (int argc, char *argv[]) {
78         struct sockaddr_storage a;
79         struct sockaddr_un b;
80         printf("Size of sockadr_storage: %d\n", sizeof(a));
81         printf ("Size of sockaddr_un:%d\n", sizeof(b));
83         if (sizeof(a) >= sizeof(b)) 
84                 printf ("Conformant to RFC 3493\n");
85         else
86                 printf ("Non-conformant to RFC 3493\n");
87
88 ---------- snip here - test_size.c ----------------------------
91 The problem was reported to IBM, and is recorded as bug report
92 PMR29657.
94 An immediate resolution is to alter _SS_MAXSIZE to = 1025 in
95 /usr/include/sys/socket.h, which will resolve the immediate problem.
97 It appears that the "final" resolution will be to alter _SS_MAXSIZE to
98 1280, making the size nicely align with page boundaries.
100 IBM will be providing a fix in the next maintenance release (expected
101 in October 2005) with an updated socket.h.
103 PMR29657 was resolved in APAR IY74147: INCOMPATIBILITY BETWEEN
104 SOCKADDR_UN AND SOCKADDR_STORAGE STRUCT
106 APAR information
107 APAR number     IY74147
108 Reported component name AIX 5.3
109 Reported component ID   5765G0300
110 Reported release        530
111 Status  CLOSED PER
112 PE      NoPE
113 HIPER   NoHIPER
114 Submitted date  2005-07-18
115 Closed date     2005-07-18
116 Last modified date      2005-09-06
118 If you upgrade to maintenance level 5300-03, that will include this
119 fix.  Use the command "oslevel -r" to determine what maintenance level
120 you are at.
122 From: Christopher Browne <cbbrowne@ca.afilias.info>
123 Date: 2005-07-15
125 Some of the AIX tools may be "a little different" from what you may be
126 accustomed to on other platforms.  If you are looking for a version of
127 ldd, useful for determining what object code depends on what
128 libraries, the following URLs may help you...
130 http://www.faqs.org/faqs/aix-faq/part4/section-22.html
132 http://www.han.de/~jum/aix/ldd.c
135 From: Christopher Browne <cbbrowne@ca.afilias.info>
136 Date: 2005-11-02
138 On AIX 5.3 ML3 (e.g. maintenance level 5300-03), there is some problem
139 with the handling of the pointer to memcpy.  It is speculated that
140 this relates to some linker bug that may have been introduced between
141 5300-02 and 5300-03, but we have so far been unable to track down the
142 cause.
144 At any rate, the following patch, which "unwraps" the function
145 reference, has been observed to allow PG 8.1 pre-releases to pass
146 regression tests.
148 The same behaviour (albeit with varying underlying functions to
149 "blame") has been observed when compiling with either GCC 4.0 or IBM
150 XLC.
152 ------------ per Seneca Cunningham -------------------
154 The following patch works on the AIX 5.3 ML3 box here and didn't cause
155 any problems with postgres on the x86 desktop.  It's just a cleaner
156 version of what I tried earlier.
158 *** dynahash.c.orig Tue Nov  1 19:41:42 2005
159 --- dynahash.c  Tue Nov  1 20:30:33 2005
160 ***************
161 *** 670,676 ****
164             /* copy key into record */
165             currBucket->hashvalue = hashvalue;
166 !           hashp->keycopy(ELEMENTKEY(currBucket), keyPtr, keysize);
169             /* caller is expected to fill the data field on return */
172 --- 670,687 ----
175             /* copy key into record */
176             currBucket->hashvalue = hashvalue;
177 !           if (hashp->keycopy == memcpy)
178 !           {
179 !               memcpy(ELEMENTKEY(currBucket), keyPtr, keysize);
180 !           }
181 !           else if (hashp->keycopy == strncpy)
182 !           {
183 !               strncpy(ELEMENTKEY(currBucket), keyPtr, keysize);
184 !           }
185 !           else
186 !           {
187 !               hashp->keycopy(ELEMENTKEY(currBucket), keyPtr, keysize);
188 !           }
191             /* caller is expected to fill the data field on return */
193 ------------ per Seneca Cunningham -------------------
197 AIX, readline, and postgres 8.1.x:
198 ----------------------------------
200 If make check doesn't work on AIX with initdb going into an infinite
201 loop or failing with child processes terminated with signal 11, the 
202 problem could be the installed copy of readline.  Previously a patch to 
203 dynahash.c was suggested to get around this, don't use it, better ways
204 to get postgres working exist.
206 See <http://archives.postgresql.org/pgsql-patches/2005-11/msg00139.php>
207 for details about the problem.
209 Working around the problem:
210 ---------------------------
211 Try one of the following:
213 o  Use the new 8.2devel backend Makefile:
215 After the matter of readline's export list and the problems that were
216 occurring on AIX because of it being linked to the backend, a filter
217 to exclude unneeded libraries from being linked against the backend was
218 added.  Get revision 1.112 of src/backend/Makefile from CVS and replace
219 the copy that came with postgres with it.  Build normally.
221 o  Use libedit
223 There are a few libedit ports available online.  Build and install the
224 desired port.  If libreadline.a can be found in /lib, /usr/lib, or in
225 any location passed to postgres' configure via "--with-libraries=",
226 readline will be detected and used by postgres.  IBM's rpm of readline
227 creates a symlink to /opt/freeware/lib/libreadline.a in /lib, so merely 
228 excluding /opt/freeware/lib from the passed library path does not stop
229 readline from being used.  
231 If the linker cannot avoid finding libreadline.a, use revision 1.433 
232 configure.in and 1.19 config/programs.m4 from CVS, change 8.2devel to 
233 the appropriate 8.1.x in configure.in and run autoconf.  Add the 
234 configure flag "--with-libedit-preferred".
236 If the version of libedit used calls its "history.h" something other
237 than history.h, place a symlink called history.h to it somewhere that
238 the C preprocessor will check.
240 o  Configure with "--without-readline"
242 postgres can be configured with the option "--without-readline".  When
243 this is enabled, postgres will not link against libreadline or libedit.
244 psql will not have history, tab completion, or any of the other niceties
245 that readline and libedit bring, but external readline wrappers exist
246 that add that functionality.
248 o  Use readline 5.0
250 Readline 5.0 does not induce the problems, however it does export
251 memcpy and strncpy when built using the easy method of "-bexpall".  Like
252 4.3, it is possible to do a build that does not export these symbols,
253 but it does take considerable manual effort and the creation of export
254 files.
256 References
257 ----------
258 "AIX 5L Porting Guide"
259   IBM Redbook
260   http://www.redbooks.ibm.com/redbooks/pdfs/sg246034.pdf
261   http://www.redbooks.ibm.com/abstracts/sg246034.html?Open
262   
263 "Developing and Porting C and C++ Applications on AIX"
264   IBM Redbook
265   http://www.redbooks.ibm.com/redbooks/pdfs/sg245674.pdf
266   http://www.redbooks.ibm.com/abstracts/sg245674.html?Open
268 -----
270 AIX Memory Management: An Overview
271 ==================================
273 by Seneca Cunningham...
275 AIX can be somewhat peculiar with regards to the way it does memory
276 management.  You can have a server with many multiples of gigabytes of
277 RAM free, but still get out of memory or address space errors when
278 running applications.
280 Two examples of AIX-specific memory problems
281 --------------------------------------------
282 Both examples were from systems with gigabytes of free RAM.
284 a) createlang failing with unusual errors
285     Running as the owner of the postgres install:
286         -bash-3.00$ createlang plpgsql template1
287         createlang: language installation failed: ERROR:  could not load library
288         "/opt/dbs/pgsql748/lib/plpgsql.so": A memory address is not in the 
289         address space for the process.
290     
291     Running as a non-owner in the group posessing the postgres install:
292         -bash-3.00$ createlang plpgsql template1
293         createlang: language installation failed: ERROR:  could not load library 
294         "/opt/dbs/pgsql748/lib/plpgsql.so": Bad address
296 b) out of memory errors in the postgres logs
297     Every memory allocation near or greater than 256MB failing.
300 The cause of these problems
301 ----------------------------
303 The overall cause of all these problems is the default bittedness and
304 memory model used by the server process.
306 By default, all binaries built on AIX are 32-bit.  This does not
307 depend upon hardware type or kernel in use.  These 32-bit processes
308 are limited to 4GB of memory laid out in 256MB segments using one of a
309 few models.  The default allows for less than 256MB in the heap as it
310 shares a single segment with the stack.
312 In the case of example a), above, check your umask and the permissions
313 of the binaries in your postgres install.  The binaries involved in
314 that example were 32-bit and installed as mode 750 instead of 755.
315 Due to the permissions being set in this fashion, only the owner or a
316 member of the possessing group can load the library.  Since it isn't
317 world-readable, the loader places the object into the process' heap
318 instead of the shared library segments where it would otherwise be
319 placed.
321 Solutions and workarounds
322 -------------------------
323 In this section, all build flag syntax is presented for gcc.
325 The "ideal" solution for this is to use a 64-bit build of postgres,
326 but that's not always practical.  Systems with 32-bit processors can
327 build, but not run, 64-bit binaries.  
329 If a 32-bit binary is desired, set LDR_CNTRL to "MAXDATA=0xn0000000",
330 where 1 <= n <= 8, before starting the postgres server and try different
331 values and postgresql.conf settings to find a configuration that works
332 satisfactorily.  This use of LDR_CNTRL tells AIX that you want the
333 server to have $MAXDATA bytes set aside for the heap, allocated in
334 256MB segments.
336 When you find a workable configuration, ldedit can be used to modify
337 the binaries so that they default to using the desired heap size.
339 PostgreSQL might also be rebuilt, passing configure
340 LDFLAGS="-Wl,-bmaxdata:0xn0000000" to achieve the same effect.
342 For a 64-bit build, set OBJECT_MODE to 64 and pass CC="gcc -maix64"
343 and LDFLAGS="-Wl,-bbigtoc" to configure.  If you omit the export of
344 OBJECT_MODE, your build may fail with linker errors.  When OBJECT_MODE
345 is set, it tells AIX's build utilities such as ar, as, and ld what
346 type of objects to default to handling.
348 Overcommit
349 ----------
351 By default, overcommit of paging space can happen.  While I have not
352 seen this occur, AIX will kill processes when it runs out of memory
353 and the overcommit is accessed.  The closest to this that I have seen
354 is fork failing because the system decided that there was not enough
355 memory for another process.  Like many other parts of AIX, the paging
356 space allocation method and out-of-memory kill is configurable on a
357 system- or process-wide basis if this becomes a problem.
359 References and resources
360 ------------------------
361 "Large Program Support"
362   AIX Documentation: General Programming Concepts: Writing and Debugging Programs
363   http://publib.boulder.ibm.com/infocenter/pseries/topic/com.ibm.aix.doc/aixprggd/genprogc/lrg_prg_support.htm
365 "Program Address Space Overview"
366   AIX Documentation: General Programming Concepts: Writing and Debugging Programs
367   http://publib.boulder.ibm.com/infocenter/pseries/topic/com.ibm.aix.doc/aixprggd/genprogc/address_space.htm
369 "Performance Overview of the Virtual Memory Manager (VMM)"
370   AIX Documentation: Performance Management Guide
371   http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.doc/aixbman/prftungd/resmgmt2.htm
373 "Page Space Allocation"
374   AIX Documentation: Performance Management Guide
375   http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.doc/aixbman/prftungd/memperf7.htm
377 "Paging-space thresholds tuning"
378   AIX Documentation: Performance Management Guide
379   http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.doc/aixbman/prftungd/memperf6.htm
381 "Developing and Porting C and C++ Applications on AIX"
382   IBM Redbook
383   http://www.redbooks.ibm.com/redbooks/pdfs/sg245674.pdf
384   http://www.redbooks.ibm.com/abstracts/sg245674.html?Open
387 Statistics Collector Fun on AIX
388 --------------------------------
390 When implementing PostgreSQL version 8.1 on AIX 5.3, we periodically
391 ran into problems where the statistics collector would "mysteriously"
392 not come up successfully.
394 This appears to be the result of unexpected behaviour in the IPv6
395 implementation.  It looks like PostgreSQL and IPv6 do not play very
396 well together at this time on AIX.
398 Any of the following actions "fix" the problem.
400 1.  Delete the localhost ipv6 address
402 (as root)
403 # ifconfig lo0 inet6 ::1/0 delete
405 2.  Remove IPv6 from net services.  The file /etc/netsvc.conf, on AIX,
406 is roughly equivalent to /etc/nsswitch.conf on Solaris/Linux.
408 The default, on AIX, is thus:
410   hosts=local,bind
412 Replace this with:
414   hosts=local4,bind4
416 to deactivate searching for IPv6 addresses.
419 Shared Linking
420 --------------
422 Shared libraries in AIX are different from shared libraries in Linux.
424 A shared library on AIX is an 'ar' archive containing shared objects. A
425 shared object is produced by the linker when invoked appropriately (e.g.
426 with -G), it is what we call a shared library on Linux.
428 -> On AIX, you can do a static as well as a dynamic
429 -> link against a shared library, it depends on how you
430 -> invoke the linker.
432 When you link statically, the shared objects from the library are added
433 to your executable as required; when you link dynamically, only
434 references to the shared objects are included in the executable.
436 Consequently you do not need a separate static library on AIX if you
437 have a dynamic library.
439 However, you CAN have static libraries (ar archives containing *.o
440 files), and the linker will link against them. This will of course
441 always be a static link.
443 When the AIX linker searches for libraries to link, it will look for a
444 library libxy.a as well as for a single shared object libxy.so when you
445 tell it to -lyx. When it finds both in the same directory, it will
446 prefer libpq.a unless invoked with -brtl.
448 This is where the problem occurs:
450 By default, PostgreSQL will (in the Linux way) create a shared object
451 libpq.so and a static library libpq.a in the same directory.
453 Up to now, since the linker was invoked without the -brtl flag, linking
454 on AIX was always static, as the linker preferred libpq.a over libpq.so.
456 We could have solved the problem by linking with -brtl on AIX, but we
457 chose to go a more AIX-conforming way so that third party programs
458 linking against PostgreSQL libraries will not be fooled into linking
459 statically by default.
461 The 'new way' on AIX is:
462 - Create libxy.so.n as before from the static library
463   libxy.a with the linker.
464 - Remove libxy.a
465 - Recreate libxy.a as a dynamic library with
466   ar -cr libxy.a libxy.so.n
467 - Only install libxy.a, do not install libxy.so
469 Since linking is dynamic on AIX now, we have a new problem:
471 We must make sure that the executable finds its library even if the
472 library is not installed in one of the standard library paths (/usr/lib
473 or /lib).
475 On Linux this is done with an RPATH, on AIX the equivalent is LIBPATH
476 that can be specified at link time with -blibpath:<colon separated path>
477 . If you do not specify the LIBPATH, it is automatically computed from
478 the -L arguments given to the linker. The LIBPATH, when set, must
479 contain ALL directories where shared libraries should be searched,
480 including the standard library directories.
482 Makefile.aix has been changed to link executables with a LIBPATH that
483 contains --libdir when PostgreSQL is configured with --enable-rpath (the
484 default).
486 The AIX equivalent for the Linux environment variable LD_LIBRARY_PATH is
487 LIBPATH.
489 The regression tests rely on LD_LIBRARY_PATH and have to be changed to
490 set LIBPATH as well.
492 Laurenz Albe