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

Commit15c121b

Browse files
committed
Rewrite the FSM. Instead of relying on a fixed-size shared memory segment, the
free space information is stored in a dedicated FSM relation fork, with eachrelation (except for hash indexes; they don't use FSM).This eliminates the max_fsm_relations and max_fsm_pages GUC options; remove anytrace of them from the backend, initdb, and documentation.Rewrite contrib/pg_freespacemap to match the new FSM implementation. Alsointroduce a new variant of the get_raw_page(regclass, int4, int4) function incontrib/pageinspect that let's you to return pages from any relation fork, anda new fsm_page_contents() function to inspect the new FSM pages.
1 parent2dbc0ca commit15c121b

File tree

53 files changed

+1755
-2631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1755
-2631
lines changed

‎contrib/pageinspect/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#
33
# pageinspect Makefile
44
#
5-
# $PostgreSQL: pgsql/contrib/pageinspect/Makefile,v 1.3 2007/11/10 23:59:51 momjian Exp $
5+
# $PostgreSQL: pgsql/contrib/pageinspect/Makefile,v 1.4 2008/09/30 10:52:09 heikki Exp $
66
#
77
#-------------------------------------------------------------------------
88

99
MODULE_big= pageinspect
10-
OBJS= rawpage.o heapfuncs.o btreefuncs.o
10+
OBJS= rawpage.o heapfuncs.o btreefuncs.o fsmfuncs.o
1111
DATA_built= pageinspect.sql
1212
DATA = uninstall_pageinspect.sql
1313

‎contrib/pageinspect/fsmfuncs.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* fsmfuncs.c
4+
* Functions to investigate FSM pages
5+
*
6+
* These functions are restricted to superusers for the fear of introducing
7+
* security holes if the input checking isn't as water-tight as it should.
8+
* You'd need to be superuser to obtain a raw page image anyway, so
9+
* there's hardly any use case for using these without superuser-rights
10+
* anyway.
11+
*
12+
* Copyright (c) 2007-2008, PostgreSQL Global Development Group
13+
*
14+
* IDENTIFICATION
15+
* $PostgreSQL: pgsql/contrib/pageinspect/fsmfuncs.c,v 1.1 2008/09/30 10:52:09 heikki Exp $
16+
*
17+
*-------------------------------------------------------------------------
18+
*/
19+
20+
#include"postgres.h"
21+
#include"lib/stringinfo.h"
22+
#include"storage/fsm_internals.h"
23+
#include"utils/builtins.h"
24+
#include"miscadmin.h"
25+
#include"funcapi.h"
26+
27+
Datumfsm_page_contents(PG_FUNCTION_ARGS);
28+
29+
/*
30+
* Dumps the contents of a FSM page.
31+
*/
32+
PG_FUNCTION_INFO_V1(fsm_page_contents);
33+
34+
Datum
35+
fsm_page_contents(PG_FUNCTION_ARGS)
36+
{
37+
bytea*raw_page=PG_GETARG_BYTEA_P(0);
38+
intraw_page_size;
39+
StringInfoDatasinfo;
40+
FSMPagefsmpage;
41+
inti;
42+
43+
if (!superuser())
44+
ereport(ERROR,
45+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
46+
(errmsg("must be superuser to use raw page functions"))));
47+
48+
raw_page_size=VARSIZE(raw_page)-VARHDRSZ;
49+
fsmpage= (FSMPage)PageGetContents(VARDATA(raw_page));
50+
51+
initStringInfo(&sinfo);
52+
53+
for(i=0;i<NodesPerPage;i++)
54+
{
55+
if (fsmpage->fp_nodes[i]!=0)
56+
appendStringInfo(&sinfo,"%d: %d\n",i,fsmpage->fp_nodes[i]);
57+
}
58+
appendStringInfo(&sinfo,"fp_next_slot: %d\n",fsmpage->fp_next_slot);
59+
60+
PG_RETURN_TEXT_P(cstring_to_text(sinfo.data));
61+
}

‎contrib/pageinspect/pageinspect.sql.in

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
/* $PostgreSQL: pgsql/contrib/pageinspect/pageinspect.sql.in,v 1.4 2007/11/13 04:24:28 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pageinspect/pageinspect.sql.in,v 1.5 2008/09/30 10:52:09 heikki Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
55

66
--
77
-- get_raw_page()
88
--
9-
CREATE OR REPLACE FUNCTION get_raw_page(text, int4)
9+
CREATE OR REPLACE FUNCTION get_raw_page(text, int4, int4)
1010
RETURNS bytea
1111
AS 'MODULE_PATHNAME', 'get_raw_page'
1212
LANGUAGE C STRICT;
1313

14+
CREATE OR REPLACE FUNCTION get_raw_page(text, int4)
15+
RETURNS bytea
16+
AS $$ SELECT get_raw_page($1, 0, $2); $$
17+
LANGUAGE SQL STRICT;
18+
1419
--
1520
-- page_header()
1621
--
@@ -92,3 +97,11 @@ CREATE OR REPLACE FUNCTION bt_page_items(IN relname text, IN blkno int4,
9297
RETURNS SETOF record
9398
AS 'MODULE_PATHNAME', 'bt_page_items'
9499
LANGUAGE C STRICT;
100+
101+
--
102+
-- fsm_page_contents()
103+
--
104+
CREATE OR REPLACE FUNCTION fsm_page_contents(IN page bytea)
105+
RETURNS text
106+
AS 'MODULE_PATHNAME', 'fsm_page_contents'
107+
LANGUAGE C STRICT;

‎contrib/pageinspect/rawpage.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Copyright (c) 2007-2008, PostgreSQL Global Development Group
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.6 2008/05/12 00:00:43 alvherre Exp $
11+
* $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.7 2008/09/30 10:52:09 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,7 +41,8 @@ Datum
4141
get_raw_page(PG_FUNCTION_ARGS)
4242
{
4343
text*relname=PG_GETARG_TEXT_P(0);
44-
uint32blkno=PG_GETARG_UINT32(1);
44+
uint32forknum=PG_GETARG_UINT32(1);
45+
uint32blkno=PG_GETARG_UINT32(2);
4546

4647
Relationrel;
4748
RangeVar*relrv;
@@ -54,6 +55,11 @@ get_raw_page(PG_FUNCTION_ARGS)
5455
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5556
(errmsg("must be superuser to use raw functions"))));
5657

58+
if (forknum>MAX_FORKNUM)
59+
ereport(ERROR,
60+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
61+
errmsg("invalid fork number")));
62+
5763
relrv=makeRangeVarFromNameList(textToQualifiedNameList(relname));
5864
rel=relation_openrv(relrv,AccessShareLock);
5965

@@ -80,7 +86,7 @@ get_raw_page(PG_FUNCTION_ARGS)
8086

8187
/* Take a verbatim copy of the page */
8288

83-
buf=ReadBuffer(rel,blkno);
89+
buf=ReadBufferWithFork(rel,forknum,blkno);
8490
LockBuffer(buf,BUFFER_LOCK_SHARE);
8591

8692
memcpy(raw_page_data,BufferGetPage(buf),BLCKSZ);
Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
1-
/* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in,v 1.8 2007/11/13 04:24:28 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in,v 1.9 2008/09/30 10:52:09 heikki Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
55

66

7-
-- Register thefunctions.
8-
CREATE OR REPLACE FUNCTIONpg_freespacemap_pages()
9-
RETURNSSETOF RECORD
10-
AS 'MODULE_PATHNAME', 'pg_freespacemap_pages'
7+
-- Register theC function.
8+
CREATE OR REPLACE FUNCTIONpg_freespace(regclass, int4)
9+
RETURNSint2
10+
AS 'MODULE_PATHNAME', 'pg_freespace'
1111
LANGUAGE C;
1212

13-
CREATE OR REPLACE FUNCTION pg_freespacemap_relations()
13+
-- pg_freespace shows the recorded space avail at each block in a relation
14+
CREATE OR REPLACE FUNCTION
15+
pg_freespace(rel regclass, blkno OUT int4, avail OUT int2)
1416
RETURNS SETOF RECORD
15-
AS 'MODULE_PATHNAME', 'pg_freespacemap_relations'
16-
LANGUAGE C;
17+
AS $$
18+
SELECT blkno::int4, pg_freespace($1, blkno::int4) AS avail
19+
FROM generate_series(0, pg_relation_size($1) / current_setting('block_size')::bigint - 1) AS blkno;
20+
$$
21+
LANGUAGE SQL;
1722

1823

19-
-- Create views for convenient access.
20-
CREATE VIEW pg_freespacemap_pages AS
21-
SELECT P.* FROM pg_freespacemap_pages() AS P
22-
(reltablespace oid,
23-
reldatabase oid,
24-
relfilenode oid,
25-
relblocknumber bigint,
26-
bytes integer);
27-
28-
CREATE VIEW pg_freespacemap_relations AS
29-
SELECT P.* FROM pg_freespacemap_relations() AS P
30-
(reltablespace oid,
31-
reldatabase oid,
32-
relfilenode oid,
33-
avgrequest integer,
34-
interestingpages integer,
35-
storedpages integer,
36-
nextpage integer);
37-
38-
3924
-- Don't want these to be available to public.
40-
REVOKE ALL ON FUNCTION pg_freespacemap_pages() FROM PUBLIC;
41-
REVOKE ALL ON pg_freespacemap_pages FROM PUBLIC;
42-
43-
REVOKE ALL ON FUNCTION pg_freespacemap_relations() FROM PUBLIC;
44-
REVOKE ALL ON pg_freespacemap_relations FROM PUBLIC;
25+
REVOKE ALL ON FUNCTION pg_freespace(regclass, int4) FROM PUBLIC;
26+
REVOKE ALL ON FUNCTION pg_freespace(regclass) FROM PUBLIC;

‎doc/src/sgml/acronyms.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/acronyms.sgml,v 1.5 2008/03/18 16:05:07 mha Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/acronyms.sgml,v 1.6 2008/09/30 10:52:09 heikki Exp $ -->
22

33
<appendix id="acronyms">
44
<title>Acronyms</title>
@@ -216,7 +216,7 @@
216216
<term><acronym>FSM</acronym></term>
217217
<listitem>
218218
<para>
219-
<link linkend="runtime-config-resource-fsm">Free Space Map</link>
219+
<link linkend="storage-fsm">Free Space Map</link>
220220
</para>
221221
</listitem>
222222
</varlistentry>

‎doc/src/sgml/config.sgml

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.190 2008/08/25 19:03:37 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.191 2008/09/30 10:52:09 heikki Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -896,80 +896,6 @@ SET ENABLE_SEQSCAN TO OFF;
896896
</varlistentry>
897897

898898
</variablelist>
899-
</sect2>
900-
<sect2 id="runtime-config-resource-fsm">
901-
<title>Free Space Map</title>
902-
903-
<indexterm>
904-
<primary>free space map</primary>
905-
</indexterm>
906-
907-
<para>
908-
These parameters control the size of the shared <firstterm>free space
909-
map</> (<acronym>FSM</>), which tracks the locations of unused space in the database.
910-
An undersized free space map can cause the database to consume
911-
increasing amounts of disk space over time, because free space that
912-
is not in the map cannot be re-used; instead <productname>PostgreSQL</>
913-
will request more disk space from the operating system when it needs
914-
to store new data.
915-
The last few lines displayed by a database-wide <command>VACUUM VERBOSE</>
916-
command can help in determining if the current settings are adequate.
917-
A <literal>NOTICE</> message is also printed during such an operation
918-
if the current settings are too low.
919-
</para>
920-
921-
<para>
922-
Increasing these parameters might cause <productname>PostgreSQL</>
923-
to request more <systemitem class="osname">System V</> shared
924-
memory than your operating system's default configuration
925-
allows. See <xref linkend="sysvipc"> for information on how to
926-
adjust those parameters, if necessary.
927-
</para>
928-
929-
<variablelist>
930-
<varlistentry id="guc-max-fsm-pages" xreflabel="max_fsm_pages">
931-
<term><varname>max_fsm_pages</varname> (<type>integer</type>)</term>
932-
<indexterm>
933-
<primary><varname>max_fsm_pages</> configuration parameter</primary>
934-
</indexterm>
935-
<listitem>
936-
<para>
937-
Sets the maximum number of disk pages for which free space will
938-
be tracked in the shared free-space map. Six bytes of shared memory
939-
are consumed for each page slot. This setting must be at least
940-
16 * <varname>max_fsm_relations</varname>. The default is chosen
941-
by <application>initdb</> depending on the amount of available memory,
942-
and can range from 20k to 200k pages.
943-
This parameter can only be set at server start.
944-
</para>
945-
</listitem>
946-
</varlistentry>
947-
948-
<varlistentry id="guc-max-fsm-relations" xreflabel="max_fsm_relations">
949-
<term><varname>max_fsm_relations</varname> (<type>integer</type>)</term>
950-
<indexterm>
951-
<primary><varname>max_fsm_relations</> configuration parameter</primary>
952-
</indexterm>
953-
<listitem>
954-
<para>
955-
Sets the maximum number of relations (tables and indexes) for which
956-
free space will be tracked in the shared free-space map. Roughly
957-
seventy bytes of shared memory are consumed for each slot.
958-
The default is one thousand relations.
959-
This parameter can only be set at server start.
960-
</para>
961-
</listitem>
962-
</varlistentry>
963-
964-
</variablelist>
965-
966-
<note>
967-
<para>
968-
See the <xref linkend="sql-vacuum" endterm="sql-vacuum-title">
969-
command for information on setting this parameter.
970-
</para>
971-
</note>
972-
973899
</sect2>
974900

975901
<sect2 id="runtime-config-resource-kernel">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp