diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 64b043b48a..68a0f1a698 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -1014,6 +1014,14 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
        <entry>an integer between <literal>1</> and <literal>10</></>
       </row>
       <row>
+        <entry><literal><function>random_zipfian(<replaceable>lb</>, <replaceable>ub</>, <replaceable>parameter</>)</></></>
+        <entry>integer</>
+        <entry> Zipfian-distributed random integer in <literal>[lb, ub]</>,
+              see below</>
+        <entry><literal>random_zipfian(1, 10, 1.2)</></>
+        <entry>an integer between <literal>1</> and <literal>10</></>
+      </row>
+      <row>
        <entry><literal><function>sqrt(<replaceable>x</>)</></></>
        <entry>double</>
        <entry>square root</>
@@ -1045,7 +1053,7 @@ f(x) = exp(-parameter * (x - min) / (max - min + 1)) / (1 - exp(-parameter))
 </literallayout>
       Then value <replaceable>i</> between <replaceable>min</> and
       <replaceable>max</> inclusive is drawn with probability:
-      <literal>f(x) - f(x + 1)</>.
+      <literal>f(i) - f(i + 1)</>.
      </para>
 
      <para>
@@ -1094,6 +1102,21 @@ f(x) = PHI(2.0 * parameter * (x - mu) / (max - min + 1)) /
       of the Box-Muller transform.
      </para>
     </listitem>
+    <listitem>
+        <para>
+          For Zipfian distribution, <replaceable>parameter</> 
+          defines how skewed the distribution. A physical sense of this parameter
+          is following: probability of <literal>i</>th element <literal>f(i) = (1 / (i ^ parameter)) /
+          (H(N, parameter))</> where <literal>N</> is number of elements and <literal>H(N, parameter)</>
+          is <literal>N</>th generalized harmonic number. 
+        </para>
+        <para>
+          Intuitively, the larger the <replaceable>parameter</>, the more
+          frequently value values to the beginning of the interval are drawn. 
+          The closer to 0 <replaceable>parameter</> is, 
+          the flatter (more uniform) the access distribution.
+        </para>
+    </listitem>
    </itemizedlist>
 
   <para>
diff --git a/src/bin/pgbench/exprparse.y b/src/bin/pgbench/exprparse.y
index b3a2d9bfd3..25d5ad48e5 100644
--- a/src/bin/pgbench/exprparse.y
+++ b/src/bin/pgbench/exprparse.y
@@ -191,6 +191,9 @@ static const struct
 	{
 		"random_exponential", 3, PGBENCH_RANDOM_EXPONENTIAL
 	},
+	{
+		"random_zipfian", 3, PGBENCH_RANDOM_ZIPFIAN
+	},
 	/* keep as last array element */
 	{
 		NULL, 0, 0
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 4d364a1db4..6126d9a21d 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -93,6 +93,8 @@ static int	pthread_join(pthread_t th, void **thread_return);
 #define LOG_STEP_SECONDS	5	/* seconds between log messages */
 #define DEFAULT_NXACTS	10		/* default nxacts */
 
+#define ZIPF_CACHE_SIZE	15		/* cache cells number */
+
 #define MIN_GAUSSIAN_PARAM		2.0 /* minimum parameter for gauss */
 
 int			nxacts = 0;			/* number of transactions per client */
@@ -334,6 +336,29 @@ typedef struct
 } CState;
 
 /*
+ * Cache cell for zipfian_random call
+ */
+typedef struct
+{
+	double		zetan;			/* zeta(n) */
+	double		theta;			/* theta parameter of previous execution */
+	int64		nitems;			/* n(ub - lb + 1) parameter of previous
+								 * execution */
+	double		alpha;
+	double		beta;
+	double		eta;
+} ZipfData;
+
+/*
+ * Zipf cache for zeta values
+ */
+typedef struct
+{
+	int			cells_inited;
+	ZipfData   *cells;
+} ZipfCache;
+
+/*
  * Thread state
  */
 typedef struct
@@ -345,6 +370,7 @@ typedef struct
 	unsigned short random_state[3]; /* separate randomness for each thread */
 	int64		throttle_trigger;	/* previous/next throttling (us) */
 	FILE	   *logfile;		/* where to log, or NULL */
+	ZipfCache	zipf_cache;
 
 	/* per thread collected stats */
 	instr_time	start_time;		/* thread start time */
@@ -737,6 +763,87 @@ getPoissonRand(TState *thread, int64 center)
 	return (int64) (-log(uniform) * ((double) center) + 0.5);
 }
 
+/* helper function for getZipfianRand */
+static double
+zipfZeta(int64 n, double theta)
+{
+	int			i;
+	double		ans = 0.0;
+
+	for (i = n; i > 1; i--)
+		ans += pow(i, -theta);
+	return ans + 1;
+}
+
+/* helper function for getZipfianRand. Computes random variable in range 1..n */
+static int64
+zipfn(double uniform_random, ZipfData * zipf, int64 n, double theta)
+{
+	double		uz = uniform_random * zipf->zetan;
+
+	if (uz < 1.)
+		return 1;
+	if (uz < 1 + zipf->beta)
+		return 2;
+	return 1 + (int64) (n * pow(zipf->eta * uniform_random - zipf->eta + 1., zipf->alpha));
+}
+
+/* set zeta value and other parameters to cache cell */
+static void
+zipfSetCacheCell(ZipfData * cell, int64 n, double theta)
+{
+	double		zipf_zeta2;
+
+	cell->nitems = n;
+	cell->theta = theta;
+
+	zipf_zeta2 = zipfZeta(2, theta);
+	cell->zetan = zipfZeta(n, theta);
+
+	cell->alpha = 1. / (1 - theta);
+	cell->beta = pow(0.5, theta);
+	cell->eta = (1. - pow(2. / n, 1 - theta)) / (1. - zipf_zeta2 / cell->zetan);
+}
+
+static ZipfData *
+zipfFindOrCreateCacheCell(ZipfCache * cache, int64 n, double theta)
+{
+	int			i;
+	ZipfData   *cell;
+
+	if (!cache->cells)
+		cache->cells = (ZipfData *) pg_malloc(sizeof(ZipfData) * ZIPF_CACHE_SIZE);
+
+	/* search cached zeta for given parameters */
+	for (i = 0; i < cache->cells_inited; i++)
+	{
+		cell = &cache->cells[i];
+		if (cell->nitems == n && cell->theta == theta)
+			return &cache->cells[i];
+	}
+
+	/* create new one if it is not exist */
+	if (cache->cells_inited != ZIPF_CACHE_SIZE)
+		i = cache->cells_inited++;
+	else
+		i = pg_lrand48() % ZIPF_CACHE_SIZE;
+
+	zipfSetCacheCell(&cache->cells[i], n, theta);
+
+	return &cache->cells[i];
+}
+
+/* random number generator: zipfian distribution from min to max inclusive */
+static int64
+getZipfianRand(TState *thread, int64 min, int64 max, double theta)
+{
+	int64		n = max - min + 1;
+	ZipfData   *cell = zipfFindOrCreateCacheCell(&thread->zipf_cache, n, theta);
+	double		uniform = pg_erand48(thread->random_state);
+
+	return min + zipfn(uniform, cell, n, theta) - 1;
+}
+
 /*
  * Initialize the given SimpleStats struct to all zeroes
  */
@@ -1567,6 +1674,7 @@ evalFunc(TState *thread, CState *st,
 		case PGBENCH_RANDOM:
 		case PGBENCH_RANDOM_EXPONENTIAL:
 		case PGBENCH_RANDOM_GAUSSIAN:
+		case PGBENCH_RANDOM_ZIPFIAN:
 			{
 				int64		imin,
 							imax;
@@ -1617,6 +1725,18 @@ evalFunc(TState *thread, CState *st,
 						setIntValue(retval,
 									getGaussianRand(thread, imin, imax, param));
 					}
+					else if (func == PGBENCH_RANDOM_ZIPFIAN)
+					{
+						if (param <= 0 || param == 1)
+						{
+							fprintf(stderr,
+									"zipfian parameter must be greater than zero and can not be 1"
+									" (got %f)\n", param);
+							return false;
+						}
+						setIntValue(retval,
+									getZipfianRand(thread, imin, imax, param));
+					}
 					else		/* exponential */
 					{
 						if (param <= 0.0)
@@ -4264,6 +4384,8 @@ main(int argc, char **argv)
 		thread->random_state[2] = random();
 		thread->logfile = NULL; /* filled in later */
 		thread->latency_late = 0;
+		thread->zipf_cache.cells = NULL;	/* filled in later */
+		thread->zipf_cache.cells_inited = 0;
 		initStats(&thread->stats, 0);
 
 		nclients_dealt += thread->nstate;
diff --git a/src/bin/pgbench/pgbench.h b/src/bin/pgbench/pgbench.h
index abc13e9463..1a29f1260c 100644
--- a/src/bin/pgbench/pgbench.h
+++ b/src/bin/pgbench/pgbench.h
@@ -75,7 +75,8 @@ typedef enum PgBenchFunction
 	PGBENCH_SQRT,
 	PGBENCH_RANDOM,
 	PGBENCH_RANDOM_GAUSSIAN,
-	PGBENCH_RANDOM_EXPONENTIAL
+	PGBENCH_RANDOM_EXPONENTIAL,
+	PGBENCH_RANDOM_ZIPFIAN
 } PgBenchFunction;
 
 typedef struct PgBenchExpr PgBenchExpr;
