Skip to content

Commit eeed012

Browse files
committed
Merge branch 'PGPRO9_6' into PGPROEE9_6
Import upstream patches up do 06/02/17
2 parents cef538d + e6ea61b commit eeed012

File tree

26 files changed

+739
-664
lines changed

26 files changed

+739
-664
lines changed

doc/src/sgml/ref/create_database.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
258258
The <literal>CONNECTION LIMIT</> option is only enforced approximately;
259259
if two new sessions start at about the same time when just one
260260
connection <quote>slot</> remains for the database, it is possible that
261-
both will fail. Also, the limit is not enforced against superusers.
261+
both will fail. Also, the limit is not enforced against superusers or
262+
background worker processes.
262263
</para>
263264
</refsect1>
264265

doc/src/sgml/ref/create_role.sgml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ CREATE ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replac
199199
<listitem>
200200
<para>
201201
If role can log in, this specifies how many concurrent connections
202-
the role can make. -1 (the default) means no limit.
202+
the role can make. -1 (the default) means no limit. Note that only
203+
normal connections are counted towards this limit. Neither prepared
204+
transactions nor background worker connections are counted towards
205+
this limit.
203206
</para>
204207
</listitem>
205208
</varlistentry>

src/backend/access/transam/twophase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ MarkAsPreparing(TransactionId xid, const char *gid,
420420
proc->backendId = InvalidBackendId;
421421
proc->databaseId = databaseid;
422422
proc->roleId = owner;
423+
proc->isBackgroundWorker = false;
423424
proc->lwWaiting = false;
424425
proc->lwWaitMode = 0;
425426
proc->waitLock = NULL;

src/backend/optimizer/plan/createplan.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,6 +5639,16 @@ materialize_finished_plan(Plan *subplan)
56395639

56405640
matplan = (Plan *) make_material(subplan);
56415641

5642+
/*
5643+
* XXX horrid kluge: if there are any initPlans attached to the subplan,
5644+
* move them up to the Material node, which is now effectively the top
5645+
* plan node in its query level. This prevents failure in
5646+
* SS_finalize_plan(), which see for comments. We don't bother adjusting
5647+
* the subplan's cost estimate for this.
5648+
*/
5649+
matplan->initPlan = subplan->initPlan;
5650+
subplan->initPlan = NIL;
5651+
56425652
/* Set cost data */
56435653
cost_material(&matpath,
56445654
subplan->startup_cost,

src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
305305
if (cursorOptions & CURSOR_OPT_SCROLL)
306306
{
307307
if (!ExecSupportsBackwardScan(top_plan))
308-
{
309-
Plan *sub_plan = top_plan;
310-
311-
top_plan = materialize_finished_plan(sub_plan);
312-
313-
/*
314-
* XXX horrid kluge: if there are any initPlans attached to the
315-
* formerly-top plan node, move them up to the Material node. This
316-
* prevents failure in SS_finalize_plan, which see for comments.
317-
* We don't bother adjusting the sub_plan's cost estimate for
318-
* this.
319-
*/
320-
top_plan->initPlan = sub_plan->initPlan;
321-
sub_plan->initPlan = NIL;
322-
}
308+
top_plan = materialize_finished_plan(top_plan);
323309
}
324310

325311
/*

src/backend/storage/ipc/procarray.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,38 @@ CountDBBackends(Oid databaseid)
28332833
return count;
28342834
}
28352835

2836+
/*
2837+
* CountDBConnections --- counts database backends ignoring any background
2838+
* worker processes
2839+
*/
2840+
int
2841+
CountDBConnections(Oid databaseid)
2842+
{
2843+
ProcArrayStruct *arrayP = procArray;
2844+
int count = 0;
2845+
int index;
2846+
2847+
LWLockAcquire(ProcArrayLock, LW_SHARED);
2848+
2849+
for (index = 0; index < arrayP->numProcs; index++)
2850+
{
2851+
int pgprocno = arrayP->pgprocnos[index];
2852+
volatile PGPROC *proc = &allProcs[pgprocno];
2853+
2854+
if (proc->pid == 0)
2855+
continue; /* do not count prepared xacts */
2856+
if (proc->isBackgroundWorker)
2857+
continue; /* do not count background workers */
2858+
if (!OidIsValid(databaseid) ||
2859+
proc->databaseId == databaseid)
2860+
count++;
2861+
}
2862+
2863+
LWLockRelease(ProcArrayLock);
2864+
2865+
return count;
2866+
}
2867+
28362868
/*
28372869
* CancelDBBackends --- cancel backends that are using specified database
28382870
*/
@@ -2892,6 +2924,8 @@ CountUserBackends(Oid roleid)
28922924

28932925
if (proc->pid == 0)
28942926
continue; /* do not count prepared xacts */
2927+
if (proc->isBackgroundWorker)
2928+
continue; /* do not count background workers */
28952929
if (proc->roleId == roleid)
28962930
count++;
28972931
}

src/backend/storage/lmgr/proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ InitProcess(void)
375375
MyProc->backendId = InvalidBackendId;
376376
MyProc->databaseId = InvalidOid;
377377
MyProc->roleId = InvalidOid;
378+
MyProc->isBackgroundWorker = IsBackgroundWorker;
378379
MyPgXact->delayChkpt = false;
379380
MyPgXact->vacuumFlags = 0;
380381
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
@@ -548,6 +549,7 @@ InitAuxiliaryProcess(void)
548549
MyProc->backendId = InvalidBackendId;
549550
MyProc->databaseId = InvalidOid;
550551
MyProc->roleId = InvalidOid;
552+
MyProc->isBackgroundWorker = IsBackgroundWorker;
551553
MyPgXact->delayChkpt = false;
552554
MyPgXact->vacuumFlags = 0;
553555
MyProc->lwWaiting = false;

src/backend/utils/init/postinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ CheckMyDatabase(const char *name, bool am_superuser)
351351
*/
352352
if (dbform->datconnlimit >= 0 &&
353353
!am_superuser &&
354-
CountDBBackends(MyDatabaseId) > dbform->datconnlimit)
354+
CountDBConnections(MyDatabaseId) > dbform->datconnlimit)
355355
ereport(FATAL,
356356
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
357357
errmsg("too many connections for database \"%s\"",

src/backend/utils/mb/Unicode/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ GENERICMAPS = $(ISO8859MAPS) $(WINMAPS) \
4242
johab_to_utf8.map utf8_to_johab.map \
4343
uhc_to_utf8.map utf8_to_uhc.map \
4444
gbk_to_utf8.map utf8_to_gbk.map \
45-
koi8r_to_utf8.map utf8_to_koi8r.map
45+
koi8r_to_utf8.map utf8_to_koi8r.map \
46+
koi8u_to_utf8.map utf8_to_koi8u.map
4647

4748
SPECIALMAPS = euc_cn_to_utf8.map utf8_to_euc_cn.map \
4849
euc_jp_to_utf8.map utf8_to_euc_jp.map \

src/bin/pg_dump/dumputils.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,12 @@ buildACLCommands(const char *name, const char *subname,
368368
*/
369369
bool
370370
buildDefaultACLCommands(const char *type, const char *nspname,
371-
const char *acls, const char *owner,
371+
const char *acls, const char *racls,
372+
const char *initacls, const char *initracls,
373+
const char *owner,
372374
int remoteVersion,
373375
PQExpBuffer sql)
374376
{
375-
bool result;
376377
PQExpBuffer prefix;
377378

378379
prefix = createPQExpBuffer();
@@ -388,14 +389,22 @@ buildDefaultACLCommands(const char *type, const char *nspname,
388389
if (nspname)
389390
appendPQExpBuffer(prefix, "IN SCHEMA %s ", fmtId(nspname));
390391

391-
result = buildACLCommands("", NULL,
392-
type, acls, "", owner,
393-
prefix->data, remoteVersion,
394-
sql);
392+
if (strlen(initacls) != 0 || strlen(initracls) != 0)
393+
{
394+
appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
395+
if (!buildACLCommands("", NULL, type, initacls, initracls, owner,
396+
prefix->data, remoteVersion, sql))
397+
return false;
398+
appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
399+
}
400+
401+
if (!buildACLCommands("", NULL, type, acls, racls, owner,
402+
prefix->data, remoteVersion, sql))
403+
return false;
395404

396405
destroyPQExpBuffer(prefix);
397406

398-
return result;
407+
return true;
399408
}
400409

401410
/*

src/bin/pg_dump/dumputils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ extern bool buildACLCommands(const char *name, const char *subname,
4141
const char *owner, const char *prefix, int remoteVersion,
4242
PQExpBuffer sql);
4343
extern bool buildDefaultACLCommands(const char *type, const char *nspname,
44-
const char *acls, const char *owner,
44+
const char *acls, const char *racls,
45+
const char *initacls, const char *initracls,
46+
const char *owner,
4547
int remoteVersion,
4648
PQExpBuffer sql);
4749
extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,

src/bin/pg_dump/pg_dump.c

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9105,6 +9105,9 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
91059105
int i_defaclnamespace;
91069106
int i_defaclobjtype;
91079107
int i_defaclacl;
9108+
int i_rdefaclacl;
9109+
int i_initdefaclacl;
9110+
int i_initrdefaclacl;
91089111
int i,
91099112
ntups;
91109113

@@ -9119,13 +9122,50 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
91199122
/* Make sure we are in proper schema */
91209123
selectSourceSchema(fout, "pg_catalog");
91219124

9122-
appendPQExpBuffer(query, "SELECT oid, tableoid, "
9123-
"(%s defaclrole) AS defaclrole, "
9124-
"defaclnamespace, "
9125-
"defaclobjtype, "
9126-
"defaclacl "
9127-
"FROM pg_default_acl",
9128-
username_subquery);
9125+
if (fout->remoteVersion >= 90600)
9126+
{
9127+
PQExpBuffer acl_subquery = createPQExpBuffer();
9128+
PQExpBuffer racl_subquery = createPQExpBuffer();
9129+
PQExpBuffer initacl_subquery = createPQExpBuffer();
9130+
PQExpBuffer initracl_subquery = createPQExpBuffer();
9131+
9132+
buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
9133+
initracl_subquery, "defaclacl", "defaclrole",
9134+
"CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
9135+
dopt->binary_upgrade);
9136+
9137+
appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "
9138+
"(%s d.defaclrole) AS defaclrole, "
9139+
"d.defaclnamespace, "
9140+
"d.defaclobjtype, "
9141+
"%s AS defaclacl, "
9142+
"%s AS rdefaclacl, "
9143+
"%s AS initdefaclacl, "
9144+
"%s AS initrdefaclacl "
9145+
"FROM pg_default_acl d "
9146+
"LEFT JOIN pg_init_privs pip ON "
9147+
"(d.oid = pip.objoid "
9148+
"AND pip.classoid = 'pg_default_acl'::regclass "
9149+
"AND pip.objsubid = 0) ",
9150+
username_subquery,
9151+
acl_subquery->data,
9152+
racl_subquery->data,
9153+
initacl_subquery->data,
9154+
initracl_subquery->data);
9155+
}
9156+
else
9157+
{
9158+
appendPQExpBuffer(query, "SELECT oid, tableoid, "
9159+
"(%s defaclrole) AS defaclrole, "
9160+
"defaclnamespace, "
9161+
"defaclobjtype, "
9162+
"defaclacl, "
9163+
"NULL AS rdefaclacl, "
9164+
"NULL AS initdefaclacl, "
9165+
"NULL AS initrdefaclacl "
9166+
"FROM pg_default_acl",
9167+
username_subquery);
9168+
}
91299169

91309170
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
91319171

@@ -9140,6 +9180,9 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
91409180
i_defaclnamespace = PQfnumber(res, "defaclnamespace");
91419181
i_defaclobjtype = PQfnumber(res, "defaclobjtype");
91429182
i_defaclacl = PQfnumber(res, "defaclacl");
9183+
i_rdefaclacl = PQfnumber(res, "rdefaclacl");
9184+
i_initdefaclacl = PQfnumber(res, "initdefaclacl");
9185+
i_initrdefaclacl = PQfnumber(res, "initrdefaclacl");
91439186

91449187
for (i = 0; i < ntups; i++)
91459188
{
@@ -9161,6 +9204,9 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
91619204
daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole));
91629205
daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
91639206
daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
9207+
daclinfo[i].rdefaclacl = pg_strdup(PQgetvalue(res, i, i_rdefaclacl));
9208+
daclinfo[i].initdefaclacl = pg_strdup(PQgetvalue(res, i, i_initdefaclacl));
9209+
daclinfo[i].initrdefaclacl = pg_strdup(PQgetvalue(res, i, i_initrdefaclacl));
91649210

91659211
/* Decide whether we want to dump it */
91669212
selectDumpableDefaultACL(&(daclinfo[i]), dopt);
@@ -14770,6 +14816,9 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
1477014816
daclinfo->dobj.namespace != NULL ?
1477114817
daclinfo->dobj.namespace->dobj.name : NULL,
1477214818
daclinfo->defaclacl,
14819+
daclinfo->rdefaclacl,
14820+
daclinfo->initdefaclacl,
14821+
daclinfo->initrdefaclacl,
1477314822
daclinfo->defaclrole,
1477414823
fout->remoteVersion,
1477514824
q))

src/bin/pg_dump/pg_dump.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ typedef struct _defaultACLInfo
527527
char *defaclrole;
528528
char defaclobjtype;
529529
char *defaclacl;
530+
char *rdefaclacl;
531+
char *initdefaclacl;
532+
char *initrdefaclacl;
530533
} DefaultACLInfo;
531534

532535
typedef struct _blobInfo

src/include/storage/proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ struct PGPROC
102102
Oid databaseId; /* OID of database this backend is using */
103103
Oid roleId; /* OID of role using this backend */
104104

105+
bool isBackgroundWorker; /* true if background worker. */
106+
105107
/*
106108
* While in hot standby mode, shows that a conflict signal has been sent
107109
* for the current transaction. Set/cleared while holding ProcArrayLock,

src/include/storage/procarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ extern pid_t CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReaso
7474

7575
extern bool MinimumActiveBackends(int min);
7676
extern int CountDBBackends(Oid databaseid);
77+
extern int CountDBConnections(Oid databaseid);
7778
extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending);
7879
extern int CountUserBackends(Oid roleid);
7980
extern bool CountOtherDBBackends(Oid databaseId,

0 commit comments

Comments
 (0)