summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/main.yml1
-rw-r--r--ChangeLog8
-rw-r--r--Makefile7
-rw-r--r--README.md26
-rw-r--r--expected/downgrade.out29
-rw-r--r--expected/pgfincore.out33
-rw-r--r--expected/upgrade.out10
-rw-r--r--pgfincore--1.4--1.5.sql24
-rw-r--r--pgfincore--1.5--1.4.sql9
-rw-r--r--pgfincore.c79
-rw-r--r--pgfincore.control2
-rw-r--r--sql/downgrade.sql11
-rw-r--r--sql/pgfincore.sql14
-rw-r--r--sql/upgrade.sql13
14 files changed, 258 insertions, 8 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c758e84..439158c 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -19,7 +19,6 @@ jobs:
- 13
- 12
- 11
- - 10
name: 🐘 PostgreSQL ${{ matrix.pg }}
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
diff --git a/ChangeLog b/ChangeLog
index 64db3b9..5ada581 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-07-25 Cédric Villemain <cedric.villemain@data-bene.io>
+ * . . - Drop support for PostgreSQL 10
+ - 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()
+
2026-06-17 Christoph Berg <myon@debian.org>
* 1.4.0 - support PostgreSQL 18 and 19 (Bradford D. Boyle, Devrim Gunduz)
- Fix off-by-one access at the end of the vec array (Robert Pang)
diff --git a/Makefile b/Makefile
index 896da69..56f7d3e 100644
--- a/Makefile
+++ b/Makefile
@@ -7,9 +7,12 @@ DATA = pgfincore--1.2.2--1.4.sql \
pgfincore--1.2.4--1.4.sql \
pgfincore--1.3.1--1.4.sql \
pgfincore--1.3--1.4.sql \
- pgfincore--1.4.sql
+ pgfincore--1.4.sql \
+ pgfincore--1.4--1.5.sql \
+ pgfincore--1.5--1.4.sql
-REGRESS = pgfincore
+REGRESS = downgrade upgrade \
+ pgfincore
PG_CONFIG = pg_config
diff --git a/README.md b/README.md
index a847d9c..3f57a3c 100644
--- a/README.md
+++ b/README.md
@@ -217,6 +217,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 memory page size in bytes
+
+:: vm_physical_pages() RETURNS bigint
+
+ Returns total number of physical pages in system memory
+
## DOCUMENTATION
### pgsysconf
@@ -338,14 +358,12 @@ For example:
## REQUIREMENTS
- * PgFincore needs mincore() or fincore() and POSIX_FADVISE
+ * PgFincore requires sysconf(), mincore() or fincore(), and POSIX_FADVISE.
+ * PostgreSQL >= 11
## LIMITATIONS
* PgFincore has a limited mode when POSIX_FADVISE is not provided by the platform.
-
- * PgFincore needs PostgreSQL >= 10
-
* PgFincore does not work on windows.
## SEE ALSO
diff --git a/expected/downgrade.out b/expected/downgrade.out
new file mode 100644
index 0000000..4d9c03e
--- /dev/null
+++ b/expected/downgrade.out
@@ -0,0 +1,29 @@
+CREATE EXTENSION pgfincore VERSION "1.5";
+ALTER EXTENSION pgfincore UPDATE TO "1.4";
+-- those require version "1.5"
+SELECT pg_page_size();
+ERROR: function pg_page_size() does not exist
+LINE 1: SELECT pg_page_size();
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+SELECT pg_segment_size();
+ERROR: function pg_segment_size() does not exist
+LINE 1: SELECT pg_segment_size();
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+SELECT vm_page_size();
+ERROR: function vm_page_size() does not exist
+LINE 1: SELECT vm_page_size();
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+SELECT FROM vm_physical_pages();
+ERROR: function vm_physical_pages() does not exist
+LINE 1: SELECT FROM vm_physical_pages();
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+SELECT FROM vm_available_pages();
+ERROR: function vm_available_pages() does not exist
+LINE 1: SELECT FROM vm_available_pages();
+ ^
+HINT: No function matches the given name and argument types. You might need to add explicit type casts.
+DROP EXTENSION pgfincore;
diff --git a/expected/pgfincore.out b/expected/pgfincore.out
index d1425ec..0ca128c 100644
--- a/expected/pgfincore.out
+++ b/expected/pgfincore.out
@@ -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)
+
diff --git a/expected/upgrade.out b/expected/upgrade.out
new file mode 100644
index 0000000..1d8ca0a
--- /dev/null
+++ b/expected/upgrade.out
@@ -0,0 +1,10 @@
+CREATE EXTENSION pgfincore VERSION "1.4";
+DROP EXTENSION pgfincore;
+CREATE EXTENSION pgfincore VERSION "1.5";
+DROP EXTENSION pgfincore;
+CREATE EXTENSION pgfincore VERSION "1.4";
+ALTER EXTENSION pgfincore UPDATE TO "1.5";
+DROP EXTENSION pgfincore;
+CREATE EXTENSION pgfincore VERSION "1.4";
+ALTER EXTENSION pgfincore UPDATE;
+DROP EXTENSION pgfincore;
diff --git a/pgfincore--1.4--1.5.sql b/pgfincore--1.4--1.5.sql
new file mode 100644
index 0000000..334b027
--- /dev/null
+++ b/pgfincore--1.4--1.5.sql
@@ -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 VOLATILE;
+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() RETURNS bigint
+AS '$libdir/pgfincore' LANGUAGE C STABLE;
+COMMENT ON FUNCTION vm_physical_pages()
+IS 'Returns number of pages in system memory';
diff --git a/pgfincore--1.5--1.4.sql b/pgfincore--1.5--1.4.sql
new file mode 100644
index 0000000..b6dde8f
--- /dev/null
+++ b/pgfincore--1.5--1.4.sql
@@ -0,0 +1,9 @@
+DROP FUNCTION pg_page_size();
+
+DROP FUNCTION pg_segment_size();
+
+DROP FUNCTION vm_available_pages();
+
+DROP FUNCTION vm_page_size();
+
+DROP FUNCTION vm_physical_pages();
diff --git a/pgfincore.c b/pgfincore.c
index a27fc09..2f5772f 100644
--- a/pgfincore.c
+++ b/pgfincore.c
@@ -1115,3 +1115,82 @@ pgfincore_drawer(PG_FUNCTION_ARGS)
*r = '\0';
PG_RETURN_CSTRING(result);
}
+
+/*
+ * PostgreSQL informations
+ */
+PG_FUNCTION_INFO_V1(pg_page_size);
+PG_FUNCTION_INFO_V1(pg_segment_size);
+
+/* 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());
+}
+
+/*
+ * sysconf informations
+ */
+PG_FUNCTION_INFO_V1(vm_available_pages);
+PG_FUNCTION_INFO_V1(vm_page_size);
+PG_FUNCTION_INFO_V1(vm_physical_pages);
+
+/* 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 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 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());
+}
diff --git a/pgfincore.control b/pgfincore.control
index 9c50ddd..223ea53 100644
--- a/pgfincore.control
+++ b/pgfincore.control
@@ -1,6 +1,6 @@
# pgfincore extension
comment = 'examine and manage the os buffer cache'
-default_version = '1.4'
+default_version = '1.5'
module_pathname = '$libdir/pgfincore'
directory = pgfincore
relocatable = true
diff --git a/sql/downgrade.sql b/sql/downgrade.sql
new file mode 100644
index 0000000..6820959
--- /dev/null
+++ b/sql/downgrade.sql
@@ -0,0 +1,11 @@
+CREATE EXTENSION pgfincore VERSION "1.5";
+ALTER EXTENSION pgfincore UPDATE TO "1.4";
+
+-- those require version "1.5"
+SELECT pg_page_size();
+SELECT pg_segment_size();
+SELECT vm_page_size();
+SELECT FROM vm_physical_pages();
+SELECT FROM vm_available_pages();
+
+DROP EXTENSION pgfincore;
diff --git a/sql/pgfincore.sql b/sql/pgfincore.sql
index 3371cd1..dd3bf31 100644
--- a/sql/pgfincore.sql
+++ b/sql/pgfincore.sql
@@ -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();
+
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
new file mode 100644
index 0000000..537ab0f
--- /dev/null
+++ b/sql/upgrade.sql
@@ -0,0 +1,13 @@
+CREATE EXTENSION pgfincore VERSION "1.4";
+DROP EXTENSION pgfincore;
+
+CREATE EXTENSION pgfincore VERSION "1.5";
+DROP EXTENSION pgfincore;
+
+CREATE EXTENSION pgfincore VERSION "1.4";
+ALTER EXTENSION pgfincore UPDATE TO "1.5";
+DROP EXTENSION pgfincore;
+
+CREATE EXTENSION pgfincore VERSION "1.4";
+ALTER EXTENSION pgfincore UPDATE;
+DROP EXTENSION pgfincore;