*** a/contrib/pgbench/pgbench.c
--- b/contrib/pgbench/pgbench.c
***************
*** 2016,2021 **** process_commands(char *buf)
--- 2016,2049 ----
  	return my_commands;
  }
  
+ static char*
+ read_sql(FILE *fd)
+ {
+ 	int len = BUFSIZ;
+ 	char tmpbuf[BUFSIZ];
+ 	char *buf = NULL;
+ 
+ 	buf = (char *)palloc(BUFSIZ);
+ 
+ 	while(fgets(tmpbuf, BUFSIZ, fd) != NULL)
+ 	{
+ 
+ 		buf = strncat(buf, tmpbuf, BUFSIZ);
+ 
+ 		/* Checking wether have read a line which include new line character */
+ 		if (strchr(tmpbuf, '\n') != NULL)
+ 		{
+ 			return buf;
+ 		}
+ 
+ 		len += BUFSIZ;
+ 
+ 		buf = (char *)pg_realloc(buf, len);
+ 	}
+ 
+ 	return NULL;
+ }
+ 
  static int
  process_file(char *filename)
  {
***************
*** 2024,2030 **** process_file(char *filename)
  	Command   **my_commands;
  	FILE	   *fd;
  	int			lineno;
! 	char		buf[BUFSIZ];
  	int			alloc_num;
  
  	if (num_files >= MAX_FILES)
--- 2052,2058 ----
  	Command   **my_commands;
  	FILE	   *fd;
  	int			lineno;
! 	char	   *buf = NULL;
  	int			alloc_num;
  
  	if (num_files >= MAX_FILES)
***************
*** 2046,2055 **** process_file(char *filename)
  
  	lineno = 0;
  
! 	while (fgets(buf, sizeof(buf), fd) != NULL)
  	{
  		Command    *command;
  
  		command = process_commands(buf);
  		if (command == NULL)
  			continue;
--- 2074,2085 ----
  
  	lineno = 0;
  
! 	while( (buf = read_sql(fd)) != NULL)
  	{
  		Command    *command;
  
+ 		if (buf == NULL) break;
+ 
  		command = process_commands(buf);
  		if (command == NULL)
  			continue;
