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

Commitc173b6c

Browse files
committed
Merge branch 'REL9_5_STABLE' into PGPRO9_5
Conflicts:doc/src/sgml/ddl.sgmldoc/src/sgml/maintenance.sgml
2 parentsa1fc603 +caad70c commitc173b6c

File tree

11 files changed

+132
-55
lines changed

11 files changed

+132
-55
lines changed

‎doc/src/sgml/ddl.sgml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ CREATE POLICY account_managers ON accounts TO managers
16291629

16301630
<programlisting>
16311631
CREATE POLICY user_policy ON users
1632-
USING (user = current_user);
1632+
USING (user_name = current_user);
16331633
</programlisting>
16341634

16351635
<para>
@@ -1642,7 +1642,7 @@ CREATE POLICY user_policy ON users
16421642
<programlisting>
16431643
CREATE POLICY user_policy ON users
16441644
USING (true)
1645-
WITH CHECK (user = current_user);
1645+
WITH CHECK (user_name = current_user);
16461646
</programlisting>
16471647

16481648
<para>
@@ -1662,7 +1662,7 @@ CREATE POLICY user_policy ON users
16621662
<programlisting>
16631663
-- Simple passwd-file based example
16641664
CREATE TABLE passwd (
1665-
username text UNIQUE NOT NULL,
1665+
user_name text UNIQUE NOT NULL,
16661666
pwhash text,
16671667
uid int PRIMARY KEY,
16681668
gid int NOT NULL,
@@ -1696,17 +1696,17 @@ CREATE POLICY all_view ON passwd FOR SELECT USING (true);
16961696
-- Normal users can update their own records, but
16971697
-- limit which shells a normal user is allowed to set
16981698
CREATE POLICY user_mod ON passwd FOR UPDATE
1699-
USING (current_user =username)
1699+
USING (current_user =user_name)
17001700
WITH CHECK (
1701-
current_user =username AND
1701+
current_user =user_name AND
17021702
shell IN ('/bin/bash','/bin/sh','/bin/dash','/bin/zsh','/bin/tcsh')
17031703
);
17041704

17051705
-- Allow admin all normal rights
17061706
GRANT SELECT, INSERT, UPDATE, DELETE ON passwd TO admin;
17071707
-- Users only get select access on public columns
17081708
GRANT SELECT
1709-
(username, uid, gid, real_name, home_phone, extra_info, home_dir, shell)
1709+
(user_name, uid, gid, real_name, home_phone, extra_info, home_dir, shell)
17101710
ON passwd TO public;
17111711
-- Allow users to update certain columns
17121712
GRANT UPDATE
@@ -1725,38 +1725,38 @@ GRANT UPDATE
17251725
postgres=&gt; set role admin;
17261726
SET
17271727
postgres=&gt; table passwd;
1728-
username | pwhash | uid | gid | real_name | home_phone | extra_info | home_dir | shell
1729-
----------+--------+-----+-----+-----------+--------------+------------+-------------+-----------
1730-
admin | xxx | 0 | 0 | Admin | 111-222-3333 | | /root | /bin/dash
1731-
bob | xxx | 1 | 1 | Bob | 123-456-7890 | | /home/bob | /bin/zsh
1732-
alice | xxx | 2 | 1 | Alice | 098-765-4321 | | /home/alice | /bin/zsh
1728+
user_name | pwhash | uid | gid | real_name | home_phone | extra_info | home_dir | shell
1729+
-----------+--------+-----+-----+-----------+--------------+------------+-------------+-----------
1730+
admin| xxx | 0 | 0 | Admin | 111-222-3333 | | /root | /bin/dash
1731+
bob| xxx | 1 | 1 | Bob | 123-456-7890 | | /home/bob | /bin/zsh
1732+
alice| xxx | 2 | 1 | Alice | 098-765-4321 | | /home/alice | /bin/zsh
17331733
(3 rows)
17341734

17351735
-- Test what Alice is able to do
17361736
postgres=&gt; set role alice;
17371737
SET
17381738
postgres=&gt; table passwd;
17391739
ERROR: permission denied for relation passwd
1740-
postgres=&gt; selectusername,real_name,home_phone,extra_info,home_dir,shell from passwd;
1741-
username | real_name | home_phone | extra_info | home_dir | shell
1742-
----------+-----------+--------------+------------+-------------+-----------
1743-
admin | Admin | 111-222-3333 | | /root | /bin/dash
1744-
bob | Bob | 123-456-7890 | | /home/bob | /bin/zsh
1745-
alice | Alice | 098-765-4321 | | /home/alice | /bin/zsh
1740+
postgres=&gt; selectuser_name,real_name,home_phone,extra_info,home_dir,shell from passwd;
1741+
user_name | real_name | home_phone | extra_info | home_dir | shell
1742+
-----------+-----------+--------------+------------+-------------+-----------
1743+
admin| Admin | 111-222-3333 | | /root | /bin/dash
1744+
bob| Bob | 123-456-7890 | | /home/bob | /bin/zsh
1745+
alice| Alice | 098-765-4321 | | /home/alice | /bin/zsh
17461746
(3 rows)
17471747

1748-
postgres=&gt; update passwd setusername = 'joe';
1748+
postgres=&gt; update passwd setuser_name = 'joe';
17491749
ERROR: permission denied for relation passwd
17501750
-- Alice is allowed to change her own real_name, but no others
17511751
postgres=&gt; update passwd set real_name = 'Alice Doe';
17521752
UPDATE 1
1753-
postgres=&gt; update passwd set real_name = 'John Doe' whereusername = 'admin';
1753+
postgres=&gt; update passwd set real_name = 'John Doe' whereuser_name = 'admin';
17541754
UPDATE 0
17551755
postgres=&gt; update passwd set shell = '/bin/xx';
17561756
ERROR: new row violates WITH CHECK OPTION for "passwd"
17571757
postgres=&gt; delete from passwd;
17581758
ERROR: permission denied for relation passwd
1759-
postgres=&gt; insert into passwd (username) values ('xxx');
1759+
postgres=&gt; insert into passwd (user_name) values ('xxx');
17601760
ERROR: permission denied for relation passwd
17611761
-- Alice can change her own password; RLS silently prevents updating other rows
17621762
postgres=&gt; update passwd set pwhash = 'abc';
@@ -2055,7 +2055,7 @@ DROP SCHEMA myschema CASCADE;
20552055
(since this is one of the ways to restrict the activities of your
20562056
users to well-defined namespaces). The syntax for that is:
20572057
<programlisting>
2058-
CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATION <replaceable>username</replaceable>;
2058+
CREATE SCHEMA <replaceable>schema_name</replaceable> AUTHORIZATION <replaceable>user_name</replaceable>;
20592059
</programlisting>
20602060
You can even omit the schema name, in which case the schema name
20612061
will be the same as the user name. See <xref
@@ -2344,7 +2344,7 @@ REVOKE CREATE ON SCHEMA public FROM PUBLIC;
23442344
implements only the basic schema support specified in the
23452345
standard. Therefore, many users consider qualified names to
23462346
really consist of
2347-
<literal><replaceable>username</>.<replaceable>tablename</></literal>.
2347+
<literal><replaceable>user_name</>.<replaceable>table_name</></literal>.
23482348
This is how <productname>&productname;</productname> will effectively
23492349
behave if you create a per-user schema for every user.
23502350
</para>

‎doc/src/sgml/maintenance.sgml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@
386386
</indexterm>
387387

388388
<para>
389-
<productname>&productname;</productname>'s MVCC transaction semantics
389+
<productname>&productname;</productname>'s
390+
<link linkend="mvcc-intro">MVCC</link> transaction semantics
390391
depend on being able to compare transaction ID (<acronym>XID</>)
391392
numbers: a row version with an insertion XID greater than the current
392393
transaction's XID is <quote>in the future</> and should not be visible
@@ -404,13 +405,10 @@
404405
<para>
405406
The reason that periodic vacuuming solves the problem is that
406407
<command>VACUUM</> will mark rows as <emphasis>frozen</>, indicating that
407-
they were inserted by a transaction which committed sufficiently far in
408-
the past that the effects of the inserting transaction is certain to be
409-
visible, from an MVCC perspective, to all current and future transactions.
410-
<productname>&productname;</> reserves a special XID,
411-
<literal>FrozenTransactionId</>, which does not follow the normal XID
412-
comparison rules and is always considered older
413-
than every normal XID. Normal XIDs are
408+
they were inserted by a transaction that committed sufficiently far in
409+
the past that the effects of the inserting transaction are certain to be
410+
visible to all current and future transactions.
411+
Normal XIDs are
414412
compared using modulo-2<superscript>32</> arithmetic. This means
415413
that for every normal XID, there are two billion XIDs that are
416414
<quote>older</> and two billion that are <quote>newer</>; another
@@ -420,16 +418,40 @@
420418
the next two billion transactions, no matter which normal XID we are
421419
talking about. If the row version still exists after more than two billion
422420
transactions, it will suddenly appear to be in the future. To
423-
prevent this, frozen row versions are treated as if the inserting XID were
421+
prevent this, <productname>PostgreSQL</> reserves a special XID,
422+
<literal>FrozenTransactionId</>, which does not follow the normal XID
423+
comparison rules and is always considered older
424+
than every normal XID.
425+
Frozen row versions are treated as if the inserting XID were
424426
<literal>FrozenTransactionId</>, so that they will appear to be
425427
<quote>in the past</> to all normal transactions regardless of wraparound
426428
issues, and so such row versions will be valid until deleted, no matter
427429
how long that is.
428430
</para>
429431

432+
<note>
433+
<para>
434+
In <productname>PostgreSQL</> versions before 9.4, freezing was
435+
implemented by actually replacing a row's insertion XID
436+
with <literal>FrozenTransactionId</>, which was visible in the
437+
row's <structname>xmin</> system column. Newer versions just set a flag
438+
bit, preserving the row's original <structname>xmin</> for possible
439+
forensic use. However, rows with <structname>xmin</> equal
440+
to <literal>FrozenTransactionId</> (2) may still be found
441+
in databases <application>pg_upgrade</>'d from pre-9.4 versions.
442+
</para>
443+
<para>
444+
Also, system catalogs may contain rows with <structname>xmin</> equal
445+
to <literal>BootstrapTransactionId</> (1), indicating that they were
446+
inserted during the first phase of <application>initdb</>.
447+
Like <literal>FrozenTransactionId</>, this special XID is treated as
448+
older than every normal XID.
449+
</para>
450+
</note>
451+
430452
<para>
431453
<xref linkend="guc-vacuum-freeze-min-age">
432-
controls how old an XID value has to be beforeits row version will be
454+
controls how old an XID value has to be beforerows bearing that XID will be
433455
frozen. Increasing this setting may avoid unnecessary work if the
434456
rows that would otherwise be frozen will soon be modified again,
435457
but decreasing this setting increases

‎src/backend/access/heap/heapam.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,6 +5403,17 @@ heap_lock_updated_tuple_rec(Relation rel, ItemPointer tid, TransactionId xid,
54035403
returnHeapTupleMayBeUpdated;
54045404
}
54055405

5406+
/*
5407+
* Also check Xmin: if this tuple was created by an aborted
5408+
* (sub)transaction, then we already locked the last live one in the
5409+
* chain, thus we're done, so return success.
5410+
*/
5411+
if (TransactionIdDidAbort(HeapTupleHeaderGetXmin(mytup.t_data)))
5412+
{
5413+
UnlockReleaseBuffer(buf);
5414+
returnHeapTupleMayBeUpdated;
5415+
}
5416+
54065417
old_infomask=mytup.t_data->t_infomask;
54075418
old_infomask2=mytup.t_data->t_infomask2;
54085419
xmax=HeapTupleHeaderGetRawXmax(mytup.t_data);

‎src/backend/commands/vacuumlazy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
14841484
return;
14851485
}
14861486

1487-
pg_usleep(VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL);
1487+
pg_usleep(VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL*1000L);
14881488
}
14891489

14901490
/*

‎src/backend/storage/ipc/dsm_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
*
4343
* IDENTIFICATION
44-
* src/backend/storage/ipc/dsm.c
44+
* src/backend/storage/ipc/dsm_impl.c
4545
*
4646
*-------------------------------------------------------------------------
4747
*/

‎src/backend/storage/smgr/md.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
918918
v=v->mdfd_chain;
919919
Assert(ov!=reln->md_fd[forknum]);/* we never drop the 1st
920920
* segment */
921+
FileClose(ov->mdfd_vfd);
921922
pfree(ov);
922923
}
923924
elseif (priorblocks+ ((BlockNumber)RELSEG_SIZE)>nblocks)

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,27 +577,17 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
577577
MemSet(values,0,sizeof(values));
578578
MemSet(nulls,0,sizeof(nulls));
579579

580-
if (pid!=-1)
581-
{
582-
/* Skip any which are not the one we're looking for. */
583-
PgBackendStatus*be=pgstat_fetch_stat_beentry(curr_backend);
584-
585-
if (!be||be->st_procpid!=pid)
586-
continue;
587-
588-
}
589-
590580
/* Get the next one in the list */
591581
local_beentry=pgstat_fetch_stat_local_beentry(curr_backend);
592582
if (!local_beentry)
593-
continue;
594-
595-
beentry=&local_beentry->backendStatus;
596-
if (!beentry)
597583
{
598584
inti;
599585

600-
for (i=0;i<sizeof(nulls) /sizeof(nulls[0]);i++)
586+
/* Ignore missing entries if looking for specific PID */
587+
if (pid!=-1)
588+
continue;
589+
590+
for (i=0;i<lengthof(nulls);i++)
601591
nulls[i]= true;
602592

603593
nulls[5]= false;
@@ -607,6 +597,12 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
607597
continue;
608598
}
609599

600+
beentry=&local_beentry->backendStatus;
601+
602+
/* If looking for specific PID, ignore all the others */
603+
if (pid!=-1&&beentry->st_procpid!=pid)
604+
continue;
605+
610606
/* Values available to all callers */
611607
values[0]=ObjectIdGetDatum(beentry->st_databaseid);
612608
values[1]=Int32GetDatum(beentry->st_procpid);

‎src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,8 @@ dumpDatabase(Archive *fout)
24442444
appendPQExpBufferStr(creaQry," LC_CTYPE = ");
24452445
appendStringLiteralAH(creaQry,ctype,fout);
24462446
}
2447-
if (strlen(tablespace)>0&&strcmp(tablespace,"pg_default")!=0)
2447+
if (strlen(tablespace)>0&&strcmp(tablespace,"pg_default")!=0&&
2448+
!dopt->outputNoTablespaces)
24482449
appendPQExpBuffer(creaQry," TABLESPACE = %s",
24492450
fmtId(tablespace));
24502451
appendPQExpBufferStr(creaQry,";\n");

‎src/include/utils/elog.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,13 @@ extern intgetinternalerrposition(void);
204204
#else/* !HAVE__BUILTIN_CONSTANT_P */
205205
#defineelog(elevel, ...) \
206206
do { \
207-
intelevel_; \
208207
elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
209-
elevel_ = (elevel); \
210-
elog_finish(elevel_, __VA_ARGS__); \
211-
if (elevel_ >= ERROR) \
212-
pg_unreachable(); \
208+
{ \
209+
const int elevel_ = (elevel); \
210+
elog_finish(elevel_, __VA_ARGS__); \
211+
if (elevel_ >= ERROR) \
212+
pg_unreachable(); \
213+
} \
213214
} while(0)
214215
#endif/* HAVE__BUILTIN_CONSTANT_P */
215216
#else/* !HAVE__VA_ARGS */

‎src/test/regress/expected/combocid.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,30 @@ SELECT ctid,cmin,* FROM combocidtest;
140140
(0,6) | 0 | 444
141141
(3 rows)
142142

143+
-- test for bug reported in
144+
-- CABRT9RC81YUf1=jsmWopcKJEro=VoeG2ou6sPwyOUTx_qteRsg@mail.gmail.com
145+
CREATE TABLE IF NOT EXISTS testcase(
146+
id int PRIMARY KEY,
147+
balance numeric
148+
);
149+
INSERT INTO testcase VALUES (1, 0);
150+
BEGIN;
151+
SELECT * FROM testcase WHERE testcase.id = 1 FOR UPDATE;
152+
id | balance
153+
----+---------
154+
1 | 0
155+
(1 row)
156+
157+
UPDATE testcase SET balance = balance + 400 WHERE id=1;
158+
SAVEPOINT subxact;
159+
UPDATE testcase SET balance = balance - 100 WHERE id=1;
160+
ROLLBACK TO SAVEPOINT subxact;
161+
-- should return one tuple
162+
SELECT * FROM testcase WHERE id = 1 FOR UPDATE;
163+
id | balance
164+
----+---------
165+
1 | 400
166+
(1 row)
167+
168+
ROLLBACK;
169+
DROP TABLE testcase;

‎src/test/regress/sql/combocid.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,21 @@ SELECT ctid,cmin,* FROM combocidtest;
9191
COMMIT;
9292

9393
SELECT ctid,cmin,*FROM combocidtest;
94+
95+
-- test for bug reported in
96+
-- CABRT9RC81YUf1=jsmWopcKJEro=VoeG2ou6sPwyOUTx_qteRsg@mail.gmail.com
97+
CREATETABLEIF NOT EXISTS testcase(
98+
idintPRIMARY KEY,
99+
balancenumeric
100+
);
101+
INSERT INTO testcaseVALUES (1,0);
102+
BEGIN;
103+
SELECT*FROM testcaseWHEREtestcase.id=1 FORUPDATE;
104+
UPDATE testcaseSET balance= balance+400WHERE id=1;
105+
SAVEPOINT subxact;
106+
UPDATE testcaseSET balance= balance-100WHERE id=1;
107+
ROLLBACK TO SAVEPOINT subxact;
108+
-- should return one tuple
109+
SELECT*FROM testcaseWHERE id=1 FORUPDATE;
110+
ROLLBACK;
111+
DROPTABLE testcase;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp