Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1516ad

Browse files
committed
pgbench: Simplify some port, host, user and dbname assignments
Using pgbench in an environment with both PGPORT and PGUSER set wouldhave caused the generation of a debug log with an incorrect databasename due to an oversight in412893b. Not specifying user, port and/ordatabase using the option switches, without their respective environmentvariables, generated a log entry with empty strings, which wasrather useless.This commit fixes this set of issues by simplifying the logic grabbingthe connection information, removing a set of getenv() calls thatemulated what libpq already does. The faulty debug log now directlyuses the information from the libpq connection, and it gets generatedafter the connection to the backend is completed, not before it (in theevent of a failure libpq would complain with more information about theconnection attempt so the log is not really useful before anyway).Author: Kota MiyakeReviewed-by: Fujii Masao, Michael PaquierDiscussion:https://postgr.es/m/026b3ae6fc339a18394d053c32a4463d@oss.nttdata.com
1 parent0ce4cd0 commitf1516ad

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include"common/int.h"
6161
#include"common/logging.h"
6262
#include"common/string.h"
63+
#include"common/username.h"
6364
#include"fe_utils/cancel.h"
6465
#include"fe_utils/conditional.h"
6566
#include"getopt_long.h"
@@ -240,10 +241,10 @@ boolis_connect;/* establish connection for each transaction */
240241
boolreport_per_command;/* report per-command latencies */
241242
intmain_pid;/* main process id used in log filename */
242243

243-
char*pghost="";
244-
char*pgport="";
245-
char*login=NULL;
246-
char*dbName;
244+
constchar*pghost=NULL;
245+
constchar*pgport=NULL;
246+
constchar*username=NULL;
247+
constchar*dbName=NULL;
247248
char*logfile_prefix=NULL;
248249
constchar*progname;
249250

@@ -1191,7 +1192,7 @@ doConnect(void)
11911192
keywords[1]="port";
11921193
values[1]=pgport;
11931194
keywords[2]="user";
1194-
values[2]=login;
1195+
values[2]=username;
11951196
keywords[3]="password";
11961197
values[3]=password;
11971198
keywords[4]="dbname";
@@ -5483,13 +5484,6 @@ main(int argc, char **argv)
54835484
}
54845485
}
54855486

5486-
if ((env=getenv("PGHOST"))!=NULL&&*env!='\0')
5487-
pghost=env;
5488-
if ((env=getenv("PGPORT"))!=NULL&&*env!='\0')
5489-
pgport=env;
5490-
elseif ((env=getenv("PGUSER"))!=NULL&&*env!='\0')
5491-
login=env;
5492-
54935487
state= (CState*)pg_malloc0(sizeof(CState));
54945488

54955489
/* set random seed early, because it may be used while parsing scripts. */
@@ -5610,7 +5604,7 @@ main(int argc, char **argv)
56105604
}
56115605
break;
56125606
case'U':
5613-
login=pg_strdup(optarg);
5607+
username=pg_strdup(optarg);
56145608
break;
56155609
case'l':
56165610
benchmarking_option_set= true;
@@ -5860,10 +5854,10 @@ main(int argc, char **argv)
58605854
{
58615855
if ((env=getenv("PGDATABASE"))!=NULL&&*env!='\0')
58625856
dbName=env;
5863-
elseif (login!=NULL&&*login!='\0')
5864-
dbName=login;
5857+
elseif ((env=getenv("PGUSER"))!=NULL&&*env!='\0')
5858+
dbName=env;
58655859
else
5866-
dbName="";
5860+
dbName=get_user_name_or_exit(progname);
58675861
}
58685862

58695863
if (optind<argc)
@@ -6026,16 +6020,16 @@ main(int argc, char **argv)
60266020
initRandomState(&state[i].cs_func_rs);
60276021
}
60286022

6029-
pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s",
6030-
pghost,pgport,nclients,
6031-
duration <=0 ?"nxacts" :"duration",
6032-
duration <=0 ?nxacts :duration,dbName);
6033-
60346023
/* opening connection... */
60356024
con=doConnect();
60366025
if (con==NULL)
60376026
exit(1);
60386027

6028+
pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s",
6029+
PQhost(con),PQport(con),nclients,
6030+
duration <=0 ?"nxacts" :"duration",
6031+
duration <=0 ?nxacts :duration,PQdb(con));
6032+
60396033
if (internal_script_used)
60406034
GetTableInfo(con,scale_given);
60416035

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp