diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
new file mode 100644
index 2e147d9..182293e
*** a/contrib/pgbench/pgbench.c
--- b/contrib/pgbench/pgbench.c
*************** int			fillfactor = 100;
*** 125,130 ****
--- 125,135 ----
  int			unlogged_tables = 0;
  
  /*
+  * create foreign key contraints on the tables
+  */
+ int			foreign_key = 0;
+ 
+ /*
   * tablespace selection
   */
  char	   *tablespace = NULL;
*************** usage(const char *progname)
*** 349,354 ****
--- 354,361 ----
  		   "               create tables in the specified tablespace\n"
  		   "  --unlogged-tables\n"
  		   "               create tables as unlogged tables\n"
+ 		   "  --foreign-keys\n"
+ 		   "               create foreign key constraints between tables\n"
  		   "\nBenchmarking options:\n"
  		"  -c NUM       number of concurrent database clients (default: 1)\n"
  		   "  -C           establish new connection for each transaction\n"
*************** init(void)
*** 1274,1282 ****
  	};
  	struct ddlinfo DDLs[] = {
  		{
! 			"pgbench_branches",
! 			"bid int not null,bbalance int,filler char(88)",
! 			1
  		},
  		{
  			"pgbench_tellers",
--- 1281,1289 ----
  	};
  	struct ddlinfo DDLs[] = {
  		{
! 			"pgbench_history",
! 			"tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
! 			0
  		},
  		{
  			"pgbench_tellers",
*************** init(void)
*** 1289,1297 ****
  			1
  		},
  		{
! 			"pgbench_history",
! 			"tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
! 			0
  		}
  	};
  	static char *DDLAFTERs[] = {
--- 1296,1304 ----
  			1
  		},
  		{
! 			"pgbench_branches",
! 			"bid int not null,bbalance int,filler char(88)",
! 			1
  		}
  	};
  	static char *DDLAFTERs[] = {
*************** init(void)
*** 1299,1304 ****
--- 1306,1318 ----
  		"alter table pgbench_tellers add primary key (tid)",
  		"alter table pgbench_accounts add primary key (aid)"
  	};
+ 	static char *DDLKEYs[] = {
+ 		"alter table pgbench_tellers add foreign key (bid) references pgbench_branches",
+ 		"alter table pgbench_accounts add foreign key (bid) references pgbench_branches",
+ 		"alter table pgbench_history add foreign key (bid) references pgbench_branches",
+ 		"alter table pgbench_history add foreign key (tid) references pgbench_tellers",
+ 		"alter table pgbench_history add foreign key (aid) references pgbench_accounts",
+ 	};
  
  	PGconn	   *con;
  	PGresult   *res;
*************** init(void)
*** 1420,1425 ****
--- 1434,1448 ----
  
  		executeStatement(con, buffer);
  	}
+ 	
+ 
+ 	if (foreign_key) {
+ 		fprintf(stderr, "set foreign key...\n");
+ 		for (i = 0; i < lengthof(DDLKEYs); i++)
+ 		{
+ 			executeStatement(con, DDLKEYs[i]);
+ 		}
+ 	}
  
  	/* vacuum */
  	fprintf(stderr, "vacuum...");
*************** main(int argc, char **argv)
*** 1864,1869 ****
--- 1887,1893 ----
  			{"index-tablespace", required_argument, NULL, 3},
  			{"tablespace", required_argument, NULL, 2},
  			{"unlogged-tables", no_argument, &unlogged_tables, 1},
+ 			{"foreign-keys", no_argument, &foreign_key, 1},
  			{NULL, 0, NULL, 0}
  	};
  
diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml
new file mode 100644
index 16ac69f..226ccc3
*** a/doc/src/sgml/pgbench.sgml
--- b/doc/src/sgml/pgbench.sgml
*************** pgbench <optional> <replaceable>options<
*** 209,214 ****
--- 209,223 ----
        </listitem>
       </varlistentry>
  
+      <varlistentry>
+       <term><option>--foreign-keys</option></term>
+       <listitem>
+        <para>
+         Create foreign key contraints between the standard tables
+        </para>
+       </listitem>
+      </varlistentry>
+ 
      </variablelist>
     </para>
  
