SIGBUS in AllocSetAlloc & jdbc - Mailing list pgsql-hackers

From Brian P Millett
Subject SIGBUS in AllocSetAlloc & jdbc
Date
Msg-id 37288B68.E7EDDEE@ec-group.com
Whole thread Raw
Responses Re: SIGBUS in AllocSetAlloc & jdbc  (Peter T Mount <peter@retep.org.uk>)
List pgsql-hackers
Peter, I hope this long and boring message can shed some light on my
difficulties getting jdbc & postgres6.5b1(current snapshot) to work
with blobs.  I have NO problem with text, numeric, etc.  Just blobs &
the LO interface.

I feel that it is a 64 vs 32 bit memory management problem.

My system:

uname -a
SunOS vlad 5.7 Generic_106541-03 sun4u sparc SUNW,Ultra-5_10

postgreSQL:
[PostgreSQL 6.5.0 on sparc-sun-solaris2.7, compiled by cc ]

cc -V
cc: WorkShop Compilers 5.0 98/12/15 C 5.0

The database & tables:

mini_stores=> select * from item;
item_num|item_picture|item_descr
|ship_unit |unit_price|stock
--------+------------+--------------------------------------------------------------+----------+----------+-----
      1|       18602|Maximum protection for high-mileage
runners                   |pair      |$75.50    | 1000      2|       18617|Customize your mountain bike with
extra-durable
crankset      |each      |$20.00    |  500      3|       18634|Long drive golf balls -fluorescent
yellow                     |pack of 12|$50.00    |  200      4|       18652|Your first season's baseball
glove                            |pair      |$25.00    |  250      5|       18668|Minimum chin contact, feather-light,
maximum
protection helmet|each      |$35.50    |   50
(5 rows)


Now the java code that reads the item table and tries to display the
image & data.  This is "borrowed" from an example from informix &
their store7/mini_stores jdbc examples.
-----BEGIN---
/***************************************************************************
**  Title:          demo4.java**  Description:    To use the fetch_buf_size connection parameter to*
optimizethe query and retrieve large byte data in
 
the*                  form of an image**  An example of running the program:**   java demo4 jdbc:postgresql:mini_stores
<userid><password>****************************************************************************
 

*/

import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.sql.*;

public class demo4 extends Frame {   static String connURL; // the URL to be used for establishing the
JDBCstatic String usr; // the user id to connect with.static String pwd; // the pasword of the user id.
   Connection conn;        // the database connection   ResultSet queryResults; // the ResultSet containing the rows
returned by
   // The GUI controls   Label itemNumLabel;   TextField itemNumField;   Label itemDescrLabel;   TextArea
itemDescrArea;  Label shipUnitLabel;   TextField shipUnitField;   Label unitPriceLabel;   TextField unitPriceField;
LabelstockLabel;   TextField stockField;   Label itemPictureLabel;   ImgCanvas itemPictureCanvas;   Button nextRowBtn;
 

   public static void main(String args[]) { if (args.length != 0) {  connURL = args[0];  usr = args[1];  pwd = args[2];
demo4 thisDemo = new demo4(); } else {  System.out.println("Missing input!! Please specify the connection
 
URL");  System.out.println("Usage...java demo4 <jdbc_conn_url>"); }   }
   public demo4() { super(); createControls(); connectToDBServer(); executeQuery();   }
   private void createControls() { setLayout(null); setSize(700,500); setVisible(true); setTitle("Item Table Data");
 // Adding label & text-field for item_num column itemNumLabel = new Label("Item Num");
itemNumLabel.setBounds(12,24,60,24);add(itemNumLabel); itemNumField = new TextField();
itemNumField.setBounds(84,24,50,38);add(itemNumField);
 
 // Adding label and text-area for item_descr column itemDescrLabel = new Label("Item Description");
itemDescrLabel.setBounds(12,72,96,24);add(itemDescrLabel); itemDescrArea = new TextArea();
itemDescrArea.setBounds(12,108,194,168);add(itemDescrArea);
 
 // Adding label & text-field for ship_unit column shipUnitLabel = new Label("Ship Unit");
shipUnitLabel.setBounds(24,288,60,38);add(shipUnitLabel); shipUnitField = new TextField();
shipUnitField.setBounds(84,288,84,38);add(shipUnitField);
 
 // Adding label & text-field for unit_price column unitPriceLabel = new Label("Unit Price");
unitPriceLabel.setBounds(24,336,60,38);add(unitPriceLabel); unitPriceField = new TextField();
unitPriceField.setBounds(84,336,84,38);add(unitPriceField);
 
 // Adding label & text-field for stock column stockLabel = new Label("Stock"); stockLabel.setBounds(36,384,36,38);
add(stockLabel);stockField = new TextField(); stockField.setBounds(84,384,84,38); add(stockField);
 
 // Adding label & ImgCanvas for item_picture column itemPictureLabel = new Label("Item Picture");
itemPictureLabel.setBounds(216,24,72,24);add(itemPictureLabel); itemPictureCanvas = new ImgCanvas();
itemPictureCanvas.setBounds(216,60,480,432);add(itemPictureCanvas);
 
 // Adding Next Row button nextRowBtn = new Button("Next Row"); nextRowBtn.setBounds(60,432,84,48); add(nextRowBtn);
 // Adding actionListener for button action events nextRowBtn.addActionListener((ActionListener)         new
nextRowBtnActionListener());
 // Adding WindowListener for the main frame to process window events addWindowListener((WindowListener) new
demo4WindowAdapter());  }
 
   private void connectToDBServer() { try {  String psqlDriver = "postgresql.Driver";
  // Register the POSTGRESQL-JDBC driver  Driver PgsqlDrv = (Driver) Class.forName(psqlDriver).newInstance();
  // Get a connection to the database server  conn = DriverManager.getConnection(connURL, usr, pwd);
  System.out.println("Driver loaded...and connection established"); } catch (Exception e) {  System.out.println("Could
notconnect to database server....");  System.out.println(e.getMessage()); }   }
 
   private void executeQuery() { // The select statement to be used for querying the item table String selectStmt =
"SELECT* FROM item";
 
 try {  // Create a Statement object and use it to execute the query  Statement stmt = conn.createStatement();
queryResults= stmt.executeQuery(selectStmt);
 
  System.out.println("Query executed..."); } catch (Exception e) {  System.out.println("Could not execute query....");
System.out.println(e.getMessage());}   }
 

   // Private inner class extending java.awt.Canvas   // Will be used for displaying the item_picture image   private
classImgCanvas extends Canvas { Image myImage;
 
 private ImgCanvas() {  super();  myImage = null; }
 private void setImage(Image img) {  myImage = img; }
 public void paint(Graphics g) {  if(myImage == null)   return;  else   g.drawImage(myImage, 0, 0, this); }   }
   // Private inner class implementing the ActionListener interface   // for the 'Next Row' button   private class
nextRowBtnActionListenerimplements ActionListener { // This is the code that will be executed whenever the 'Next Row'
//button is pressed // Here, we get the values of all the columns of the current row // and display them public void
actionPerformed(ActionEventevt) {  try {   if (queryResults.next()) {    // Getting the values of the item_num,
ship_unit   // unit_price, item_descr & stock columns and displaying them
itemNumField.setText(queryResults.getString(1));   itemDescrArea.setText(queryResults.getString(3));
shipUnitField.setText(queryResults.getString(4));   unitPriceField.setText(queryResults.getString(5));
stockField.setText(queryResults.getString(6));
    // Getting the value of the item_picture column and    // displaying it    System.err.println("Got oid
"+queryResults.getInt(2));   byte itemPictureArray [] = queryResults.getBytes(2);    if (itemPictureArray != null) {
Image img =
 
Toolkit.getDefaultToolkit().createImage(itemPictureArray);     itemPictureCanvas.setImage(img);
itemPictureCanvas.repaint();   }   } else {    System.out.println("No more rows!!");   }  } catch (Exception e) {
System.out.println("Couldnot display next row...");   System.out.println(e.getMessage());  } }   }
 

   // Private inner class implementing the WindowAdapter interface   // for the main frame window   private class
demo4WindowAdapterextends WindowAdapter { // This is the code that will be executed whenever the frame // window is
closedusing the button in its upper-right corner public void windowClosing(WindowEvent evt) {  setVisible(false); //
hidethe main frame  dispose();   // free the system resources  System.exit(0);  // close the application }   }
 
}
------END----

Now I start it & attach to the backend with gdb.  After the frame is
up, I can select the next row (the first).  It works as it should.
When I select next (for the second), then I get the following back
trace:

vlad: ps -ef | grep po   root   272     1  0   Apr 27 ?        0:00 /usr/lib/power/powerd    bpm   771     1  0
10:45:48pts/2    0:00 /opt/pgsql/bin/postmaster
 
-o -F -o /opt/pgsql/logs/backend.log -S 16384 -i -p 5    bpm   796   771  1 10:53:49 pts/2    0:00
/opt/pgsql/bin/postmaster
-o -F -o /opt/pgsql/logs/backend.log -S 16384 -i -p 5    bpm   798  1153  0 10:53:53 pts/10   0:00 grep po
vlad: gdb /opt/pgsql/bin/postmaster 796
GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "sparc-sun-solaris2.7"...
(no debugging symbols found)...

/home/bpm/development/perl_ext/DBD-Pg-0.91/796: No such file or
directory.
Attaching to program `/opt/pgsql/bin/postmaster', process 796
Reading symbols from /usr/lib/libgen.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libcrypt_i.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libnsl.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libsocket.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libdl.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libm.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libcurses.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libc.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libmp.so.2...(no debugging symbols
found)...done.
Reading symbols from /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1...
---Type <return> to continue, or q <return> to quit---
(no debugging symbols found)...done.
Reading symbols from /usr/lib/nss_files.so.1...(no debugging symbols
found)...
done.
Symbols already loaded for /usr/lib/libgen.so.1
Symbols already loaded for /usr/lib/libcrypt_i.so.1
Symbols already loaded for /usr/lib/libnsl.so.1
Symbols already loaded for /usr/lib/libsocket.so.1
Symbols already loaded for /usr/lib/libdl.so.1
Symbols already loaded for /usr/lib/libm.so.1
Symbols already loaded for /usr/lib/libcurses.so.1
Symbols already loaded for /usr/lib/libc.so.1
Symbols already loaded for /usr/lib/libmp.so.2
Symbols already loaded for
/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
Symbols already loaded for /usr/lib/nss_files.so.1
0xff19311c in _so_recv ()
(gdb) bt
#0  0xff19311c in _so_recv ()
#1  0xbb4d4 in pq_recvbuf ()
#2  0xbb710 in pq_getbytes ()
#3  0x13e020 in SocketBackend ()
#4  0x13e124 in ReadCommand ()
#5  0x140434 in PostgresMain ()
#6  0x11161c in DoBackend ()
#7  0x110e78 in BackendStartup ()
#8  0x10fd98 in ServerLoop ()
#9  0x10f6e0 in PostmasterMain ()
#10 0xbca58 in main ()
(gdb) c
Continuing.

Program received signal SIGBUS, Bus error.
0x19f180 in AllocSetAlloc ()
(gdb) bt
#0  0x19f180 in AllocSetAlloc ()
#1  0x19fa2c in GlobalMemoryAlloc ()
#2  0x19f7b8 in MemoryContextAlloc ()
#3  0x19fc58 in pstrdup ()
#4  0x1331c4 in inv_open ()
#5  0xb3e18 in lo_open ()
#6  0x199e38 in fmgr_c ()
#7  0x19a46c in fmgr ()
#8  0x13dc44 in HandleFunctionRequest ()
#9  0x14048c in PostgresMain ()
#10 0x11161c in DoBackend ()
#11 0x110e78 in BackendStartup ()
#12 0x10fd98 in ServerLoop ()
#13 0x10f6e0 in PostmasterMain ()
#14 0xbca58 in main ()

######## NEXT EXAMPLE ###############

I stopped/started the postmaster as:
/opt/pgsql/bin/postmaster -o "-d 3 -F -o ${PGSQLHOME}/logs/backend.log
-W 30 -S 16384" \                         -i -d 3 -p 5432 -D ${PGDATA} >
${PGSQLHOME}/logs/error.log 2>&1 &

Now I ran the examples/blobtest, attached to the backend & got the
following:

vlad: ps -ef | grep po   root   272     1  0   Apr 27 ?        0:00 /usr/lib/power/powerd    bpm   815     1  0
11:00:58pts/2    0:00 /opt/pgsql/bin/postmaster
 
-o -F -o /opt/pgsql/logs/backend.log -W 30 -S 16384 -    bpm   830   815  0 11:01:37 pts/2    0:00
/opt/pgsql/bin/postmaster
-o -F -o /opt/pgsql/logs/backend.log -W 30 -S 16384 -    bpm   833  1153  0 11:01:45 pts/10   0:00 grep po
vlad: gdb /opt/pgsql/bin/postmaster 830
GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "sparc-sun-solaris2.7"...
(no debugging symbols found)...

/opt/pgsql/logs/830: No such file or directory.
Attaching to program `/opt/pgsql/bin/postmaster', process 830
Reading symbols from /usr/lib/libgen.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libcrypt_i.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libnsl.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libsocket.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libdl.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libm.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libcurses.so.1...(no debugging symbols
found)...
done.
Reading symbols from /usr/lib/libc.so.1...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libmp.so.2...(no debugging symbols
found)...done.
Reading symbols from /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1...
---Type <return> to continue, or q <return> to quit---
(no debugging symbols found)...done.
Reading symbols from /usr/lib/nss_files.so.1...(no debugging symbols
found)...
done.
Symbols already loaded for /usr/lib/libgen.so.1
Symbols already loaded for /usr/lib/libcrypt_i.so.1
Symbols already loaded for /usr/lib/libnsl.so.1
Symbols already loaded for /usr/lib/libsocket.so.1
Symbols already loaded for /usr/lib/libdl.so.1
Symbols already loaded for /usr/lib/libm.so.1
Symbols already loaded for /usr/lib/libcurses.so.1
Symbols already loaded for /usr/lib/libc.so.1
Symbols already loaded for /usr/lib/libmp.so.2
Symbols already loaded for
/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
Symbols already loaded for /usr/lib/nss_files.so.1
0xff195d88 in _sigsuspend ()
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x19f180 in AllocSetAlloc ()
(gdb) bt
#0  0x19f180 in AllocSetAlloc ()
#1  0x19fa2c in GlobalMemoryAlloc ()
#2  0x19f7b8 in MemoryContextAlloc ()
#3  0x5b69c in btrescan ()
#4  0x199e60 in fmgr_c ()
#5  0x19a46c in fmgr ()
#6  0x4d3a0 in index_rescan ()
#7  0x4cc70 in RelationGetIndexScan ()
#8  0x5b4d0 in btbeginscan ()
#9  0x199e8c in fmgr_c ()
#10 0x19a46c in fmgr ()
#11 0x4d2e4 in index_beginscan ()
#12 0x133624 in inv_seek ()
#13 0xb4070 in lo_lseek ()
#14 0x199e60 in fmgr_c ()
#15 0x19a46c in fmgr ()
#16 0x13dc44 in HandleFunctionRequest ()
#17 0x14048c in PostgresMain ()
#18 0x11161c in DoBackend ()
#19 0x110e78 in BackendStartup ()
#20 0x10fd98 in ServerLoop ()
#21 0x10f6e0 in PostmasterMain ()
#22 0xbca58 in main ()


I looked at src/backend/utils/mmgr/aset.c to see what was going on in
AllocSetAlloc, but I am but a mere mortal.

Thanks.


--
Brian Millett
Enterprise Consulting Group     "Heaven can not exist,
(314) 205-9030                     If the family is not eternal"
bpm@ec-group.com                   F. Ballard Washburn





pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: [HACKERS] Help/advice/suggestions on query optimizer for a large table
Next
From: Michael J Davis
Date:
Subject: Numeric data types (formerly "v6.5 Release Date ...")