Skip to content

Commit

Permalink
Add new sysconf and pg information functions
Browse files Browse the repository at this point in the history
- Add function pg_page_size()
- Add function pg_segment_size()
- Add function vm_available_pages()
- Add function vm_page_size()
- Add function vm_physical_pages()

Also some README edition and preparing release 1.4.0
  • Loading branch information
c2main committed Dec 15, 2024
1 parent d57986f commit b070d97
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 24 deletions.
14 changes: 13 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
15/12/2024 Cédric Villemain <[email protected]>
* 1.4.0 - Add GHA test for PostgreSQL 17
- Drop support for PostgreSQL < 12
- Add function pg_page_size()
- Add function pg_segment_size()
- Add function vm_available_pages()
- Add function vm_page_size()
- Add function vm_physical_pages()

21/09/2023 Cédric Villemain <[email protected]>
* 1.3.1 - drop support for upgrading from "unpackaged"

21/09/2023 Cédric Villemain <[email protected]>
* 1.3 - added support for PostgreSQL 16
- drop support for PostgreSQL < 9.4
2019-10-29 Cédric Villemain <[email protected]>

29/10/2019 Cédric Villemain <[email protected]>
* 1.2.2 - Fix bad errno usage

22/09/2017 Cédric Villemain <[email protected]>
* 1.2.1 - Fix check on NULL input for drawer function

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
EXTENSION = pgfincore
EXTVERSION = 1.3.1
EXTVERSION = 1.4.0

MODULES = $(EXTENSION)
MODULEDIR = $(EXTENSION)
DOCS = README.md
DATA = $(EXTENSION)--1.2--1.3.1.sql \
$(EXTENSION)--$(EXTVERSION).sql
DATA = $(EXTENSION)--1.3.1.sql \
$(EXTENSION)--1.3.1--1.4.0.sql

REGRESS = $(EXTENSION)

Expand Down
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,34 @@ You can grab the latest code with git:

git clone git://git.postgresql.org/git/pgfincore.git
or
git://github.com/pgfincore/pgfincore.git
or
git://github.com/klando/pgfincore.git

And the project is on pgfoundry : http://pgfoundry.org/projects/pgfincore

## INSTALL

* PgFincore is packaged for *RPM* at http://yum.postgresql.org/
* PgFincore is packaged for *debian* at http://pgapt.debian.net/
* PgFincore extension is available on some large SQL cloud providers.

From source code:

make clean
make
su
make install

For PostgreSQL >= 9.1, log in your database and:
Log in your database and:

mydb=# CREATE EXTENSION pgfincore;

For other release, create the functions from the sql script (it should be in
your contrib directory):

psql mydb -f pgfincore.sql

PgFincore is also shipped with Debian scripts to build your own package:

aptitude install debhelper postgresql-server-dev-all postgresql-server-dev-9.1
# or postgresql-server-dev-8.4|postgresql-server-dev-9.0
# or postgresql-server-dev-8.4|postgresql-server-dev-9.0
make deb
dpkg -i ../postgresql-9.1-pgfincore_1.1.1-1_amd64.deb

PgFincore is packaged for *RPM* at http://yum.postgresql.org/
PgFincore is packaged for *debian* at http://pgapt.debian.net/




## EXAMPLES

Here are some examples of usage. If you want more details go to Documentation_
Expand Down Expand Up @@ -217,6 +210,26 @@ Executing a snapshot and a restore is very simple:
OUT group_dirty bigint)
RETURNS setof record

:: pg_page_size() RETURNS bigint

Returns PostgreSQL page size in bytes

:: pg_segment_size() RETURNS int

Returns PostgreSQL segment size in blocks

:: vm_available_pages() RETURNS bigint

Returns current number of available pages in system memory

:: vm_page_size() RETURNS bigint

Returns system page size in bytes

:: vm_physical_pages() RETURNS bigint

Returns total number of physical pages in system memory

## DOCUMENTATION

### pgsysconf
Expand Down Expand Up @@ -338,14 +351,12 @@ For example:

## REQUIREMENTS

* PgFincore needs mincore() or fincore() and POSIX_FADVISE
* PgFincore requires sysconf(), mincore() or fincore(), and POSIX_FADVISE.
* PostgreSQL >= 9.3

## LIMITATIONS

* PgFincore has a limited mode when POSIX_FADVISE is not provided by the platform.

* PgFincore needs PostgreSQL >= 8.3

* PgFincore does not work on windows.

## SEE ALSO
Expand Down
33 changes: 33 additions & 0 deletions expected/pgfincore.out
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,36 @@ select NULL || pgfincore_drawer(databit) from pgfincore('test','main',true);

(1 row)

--
-- System/PostgreSQL info
--
-- assume most systems have same defaults
-- it's possible to add another output file
-- to manage larger PostgreSQL and or system page size.
SELECT pg_page_size();
pg_page_size
--------------
8192
(1 row)

SELECT pg_segment_size();
pg_segment_size
-----------------
131072
(1 row)

SELECT vm_page_size();
vm_page_size
--------------
4096
(1 row)

-- no output for the following:
SELECT FROM vm_physical_pages();
--
(1 row)

SELECT FROM vm_available_pages();
--
(1 row)

Empty file removed pgfincore--1.2--1.3.1.sql
Empty file.
24 changes: 24 additions & 0 deletions pgfincore--1.3.1--1.4.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE FUNCTION pg_page_size() RETURNS bigint
AS '$libdir/pgfincore' LANGUAGE C STABLE;
COMMENT ON FUNCTION pg_page_size()
IS 'Returns PostgreSQL page size in bytes';

CREATE FUNCTION pg_segment_size() RETURNS bigint
AS '$libdir/pgfincore' LANGUAGE C STABLE;
COMMENT ON FUNCTION pg_segment_size()
IS 'Returns PostgreSQL segment size in blocks';

CREATE FUNCTION vm_available_pages() RETURNS bigint
AS '$libdir/pgfincore' LANGUAGE C STABLE;
COMMENT ON FUNCTION vm_available_pages()
IS 'Returns current number of free pages in system memory';

CREATE FUNCTION vm_page_size() RETURNS bigint
AS '$libdir/pgfincore' LANGUAGE C STABLE;
COMMENT ON FUNCTION vm_page_size()
IS 'Returns system page size in bytes';

CREATE FUNCTION vm_physical_pages(OUT sys_pages_free bigint)
AS '$libdir/pgfincore' LANGUAGE C STABLE;
COMMENT ON FUNCTION vm_physical_pages()
IS 'Returns number of pages in system memory';
71 changes: 71 additions & 0 deletions pgfincore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,3 +1111,74 @@ pgfincore_drawer(PG_FUNCTION_ARGS)
*r = '\0';
PG_RETURN_CSTRING(result);
}

/*
* sysconf and PostgreSQL informations
*/
PG_FUNCTION_INFO_V1(pg_page_size);
PG_FUNCTION_INFO_V1(pg_segment_size);
PG_FUNCTION_INFO_V1(vm_available_pages);
PG_FUNCTION_INFO_V1(vm_page_size);
PG_FUNCTION_INFO_V1(vm_physical_pages);

/* PostgreSQL Page size */
static inline size_t pg_PageSize()
{
return BLCKSZ;
}
Datum
pg_page_size(PG_FUNCTION_ARGS)
{
PG_RETURN_UINT64(pg_PageSize());
}

/* PostgreSQL Segment size */
static inline uint32 pg_SegmentSize()
{
return RELSEG_SIZE;
}
Datum
pg_segment_size(PG_FUNCTION_ARGS)
{
PG_RETURN_UINT32(pg_SegmentSize());
}

/* System Page size */
static size_t _sc_pagesize = 0;
static inline size_t vm_PageSize()
{
if (_sc_pagesize == 0)
_sc_pagesize = sysconf(_SC_PAGESIZE);
return ((size_t) _sc_pagesize);
}
Datum
vm_page_size(PG_FUNCTION_ARGS)
{
PG_RETURN_UINT64(vm_PageSize());
}

/* System number of available pages */
static inline size_t vm_AvPhysPages()
{
return (size_t) sysconf(_SC_AVPHYS_PAGES);
}
Datum
vm_available_pages(PG_FUNCTION_ARGS)
{
PG_RETURN_UINT64(vm_AvPhysPages());
}

/* System number of physical pages */
static size_t _sc_phys_pages = 0;
static inline size_t vm_PhysPages()
{
if (_sc_phys_pages == 0)
_sc_phys_pages = sysconf(_SC_PHYS_PAGES);
return _sc_phys_pages;
}
Datum
vm_physical_pages(PG_FUNCTION_ARGS)
{
PG_RETURN_UINT64(vm_PhysPages());
}

2 changes: 1 addition & 1 deletion pgfincore.control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pgfincore extension
comment = 'examine and manage the os buffer cache'
default_version = '1.3.1'
default_version = '1.4.0'
module_pathname = '$libdir/pgfincore'
directory = pgfincore
relocatable = true
14 changes: 14 additions & 0 deletions sql/pgfincore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ select from pgfadvise_normal('test');
-- tests drawers
--
select NULL || pgfincore_drawer(databit) from pgfincore('test','main',true);

--
-- System/PostgreSQL info
--
-- assume most systems have same defaults
-- it's possible to add another output file
-- to manage larger PostgreSQL and or system page size.
SELECT pg_page_size();
SELECT pg_segment_size();
SELECT vm_page_size();
-- no output for the following:
SELECT FROM vm_physical_pages();
SELECT FROM vm_available_pages();

0 comments on commit b070d97

Please sign in to comment.