Fix a typo in pg_rotate_logfile
Hi,
I happened to notice a typo in pg_rotate_logfile in ipc/signalfuncs.c
- the hint message wrongly mentions that pg_logfile_rotate is part of
the core; which is actually not. pg_logfile_rotate is an adminpack's
1.0 SQL function dropped in 2.0. The core defines pg_rotate_logfile
SQL function instead, so use that. Here's a patch to fix the typo.
--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachments:
v1-0001-Fix-a-typo-in-pg_rotate_logfile.patchapplication/x-patch; name=v1-0001-Fix-a-typo-in-pg_rotate_logfile.patchDownload
From 18854ba341d892750fc75b9988ba107fe44e7c63 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Mon, 12 Feb 2024 13:30:31 +0000
Subject: [PATCH v1] Fix a typo in pg_rotate_logfile
---
src/backend/storage/ipc/signalfuncs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index 81d1a59659..c05a2af48b 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -284,7 +284,7 @@ pg_rotate_logfile(PG_FUNCTION_ARGS)
errmsg("must be superuser to rotate log files with adminpack 1.0"),
/* translator: %s is a SQL function name */
errhint("Consider using %s, which is part of core, instead.",
- "pg_logfile_rotate()")));
+ "pg_rotate_logfile()")));
if (!Logging_collector)
{
--
2.34.1
On 12 Feb 2024, at 21:32, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
I happened to notice a typo in pg_rotate_logfile in ipc/signalfuncs.c
- the hint message wrongly mentions that pg_logfile_rotate is part of
the core; which is actually not. pg_logfile_rotate is an adminpack's
1.0 SQL function dropped in 2.0. The core defines pg_rotate_logfile
SQL function instead, so use that. Here's a patch to fix the typo.
Nice catch! This needs to be backpatched all the way down to 12 as that
function wen't away a long time ago (it was marked as deprecated all the way
back in 9.1).
--
Daniel Gustafsson
On Mon, Feb 12, 2024 at 09:39:06PM +0100, Daniel Gustafsson wrote:
On 12 Feb 2024, at 21:32, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
I happened to notice a typo in pg_rotate_logfile in ipc/signalfuncs.c
- the hint message wrongly mentions that pg_logfile_rotate is part of
the core; which is actually not. pg_logfile_rotate is an adminpack's
1.0 SQL function dropped in 2.0. The core defines pg_rotate_logfile
SQL function instead, so use that. Here's a patch to fix the typo.Nice catch! This needs to be backpatched all the way down to 12 as that
function wen't away a long time ago (it was marked as deprecated all the way
back in 9.1).
This is a bit strange because, with this patch, the HINT suggests using a
function with the same name as the one it lives in. IIUC this is because
adminpack's pg_logfile_rotate() uses pg_rotate_logfile(), while core's
pg_rotate_logfile() uses pg_rotate_logfile_v2(). I suppose trying to
rename these might be more trouble than it's worth at this point, though...
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
On 12 Feb 2024, at 21:46, Nathan Bossart <nathandbossart@gmail.com> wrote:
On Mon, Feb 12, 2024 at 09:39:06PM +0100, Daniel Gustafsson wrote:
On 12 Feb 2024, at 21:32, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
I happened to notice a typo in pg_rotate_logfile in ipc/signalfuncs.c
- the hint message wrongly mentions that pg_logfile_rotate is part of
the core; which is actually not. pg_logfile_rotate is an adminpack's
1.0 SQL function dropped in 2.0. The core defines pg_rotate_logfile
SQL function instead, so use that. Here's a patch to fix the typo.Nice catch! This needs to be backpatched all the way down to 12 as that
function wen't away a long time ago (it was marked as deprecated all the way
back in 9.1).This is a bit strange because, with this patch, the HINT suggests using a
function with the same name as the one it lives in. IIUC this is because
adminpack's pg_logfile_rotate() uses pg_rotate_logfile(), while core's
pg_rotate_logfile() uses pg_rotate_logfile_v2(). I suppose trying to
rename these might be more trouble than it's worth at this point, though...
Yeah, I doubt that's worth the churn.
On that note though, we might want to consider just dropping it altogether in
v17 (while fixing the incorrect hint in backbranches)? I can't imagine
adminpack 1.0 being in heavy use today, and skimming pgAdmin code it seems it's
only used in pgAdmin3 and not 4. Maybe it's time to simply drop old code?
--
Daniel Gustafsson
On Tue, Feb 13, 2024 at 2:29 AM Daniel Gustafsson <daniel@yesql.se> wrote:
On that note though, we might want to consider just dropping it altogether in
v17 (while fixing the incorrect hint in backbranches)? I can't imagine
adminpack 1.0 being in heavy use today, and skimming pgAdmin code it seems it's
only used in pgAdmin3 and not 4. Maybe it's time to simply drop old code?
https://codesearch.debian.net/search?q=pg_logfile_rotate&literal=1
shows no users for it though. There's pgadmin3 using it
https://github.com/search?q=repo%3Apgadmin-org%2Fpgadmin3%20pg_logfile_rotate&type=code,
however the repo is archived. Surprisingly, core has to maintain the
old code needed for adminpack 1.0 - pg_rotate_logfile_old SQL function
and pg_rotate_logfile function in signalfuncs.c. These things could
have been moved to adminpack.c back then and pointed CREATE FUNCTION
pg_catalog.pg_logfile_rotate() to use it from adminpack.c. If we
decide to remove adminpack 1.0 version completely, the 1.0 functions
pg_file_read, pg_file_length and pg_logfile_rotate will also go away
making adminpack code simpler.
Having said that, it's good to hear from others, preferably from
pgadmin developers - added Dave Page (dpage@pgadmin.org) in here for
inputs.
--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Hi
On Mon, 12 Feb 2024 at 21:31, Bharath Rupireddy <
bharath.rupireddyforpostgres@gmail.com> wrote:
On Tue, Feb 13, 2024 at 2:29 AM Daniel Gustafsson <daniel@yesql.se> wrote:
On that note though, we might want to consider just dropping it
altogether in
v17 (while fixing the incorrect hint in backbranches)? I can't imagine
adminpack 1.0 being in heavy use today, and skimming pgAdmin code itseems it's
only used in pgAdmin3 and not 4. Maybe it's time to simply drop old code?
https://codesearch.debian.net/search?q=pg_logfile_rotate&literal=1
shows no users for it though. There's pgadmin3 using ithttps://github.com/search?q=repo%3Apgadmin-org%2Fpgadmin3%20pg_logfile_rotate&type=code
,
however the repo is archived. Surprisingly, core has to maintain the
old code needed for adminpack 1.0 - pg_rotate_logfile_old SQL function
and pg_rotate_logfile function in signalfuncs.c. These things could
have been moved to adminpack.c back then and pointed CREATE FUNCTION
pg_catalog.pg_logfile_rotate() to use it from adminpack.c. If we
decide to remove adminpack 1.0 version completely, the 1.0 functions
pg_file_read, pg_file_length and pg_logfile_rotate will also go away
making adminpack code simpler.Having said that, it's good to hear from others, preferably from
pgadmin developers - added Dave Page (dpage@pgadmin.org) in here for
inputs.
As it happens we're currently implementing a redesigned version of that
functionality from pgAdmin III in pgAdmin 4. However, we are not using
adminpack for it.
FWIW, the reason for the weird naming is that originally all the
functionality for reading/managing files was added entirely as the
adminpack extension. It was only later that some of the functionality was
moved into core, and renamed along the way (everyone likes blue for their
bikeshed right?). The old functions (albeit, rewritten to use the new core
functions) were kept in adminpack for backwards compatibility.
That said, pgAdmin III has been out of support for many years, and as far
as I know, it (and similarly old versions of EDB's PEM which was based on
it) were the only consumers of adminpack. I would not be sad to see it
removed entirely - except for the fact that I fondly remember being invited
to join -core immediately after a heated discussion with Tom about it!
--
Dave Page
pgAdmin: https://www.pgadmin.org
PostgreSQL: https://www.postgresql.org
EDB: https://www.enterprisedb.com
On 14 Feb 2024, at 11:35, Dave Page <dpage@pgadmin.org> wrote:
That said, pgAdmin III has been out of support for many years, and as far as I know, it (and similarly old versions of EDB's PEM which was based on it) were the only consumers of adminpack. I would not be sad to see it removed entirely
Searching on Github and Debian Codesearch I cannot find any reference to anyone
using any function from adminpack. With pgAdminIII being EOL it might be to
remove it now rather than be on the hook to maintain it for another 5 years
until v17 goes EOL. It'll still be around for years in V16->.
If anyone still uses pgAdminIII then I have a hard time believing they are
diligently updating to the latest major version of postgres..
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).
--
Daniel Gustafsson
Attachments:
v1-0001-Remove-the-adminpack-extension.patchapplication/octet-stream; name=v1-0001-Remove-the-adminpack-extension.patch; x-unix-mode=0644Download
From b10285838529f0d2ce385f05ff1e3dd6f189f499 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <dgustafsson@postgresql.org>
Date: Wed, 14 Feb 2024 11:48:34 +0100
Subject: [PATCH v1] Remove the adminpack extension
The adminpack extension was only used to support pgAdmin III, which
in turn was declared EOL many years ago. Removing the extension also
allows us to remove functions from core as well which were only used
to support old version of adminpack.
Discussion: https://postgr.es/m/CALj2ACUmL5TraYBUBqDZBi1C+Re8_=SekqGYqYprj_W8wygQ8w@mail.gmail.com
---
contrib/Makefile | 1 -
contrib/adminpack/.gitignore | 4 -
contrib/adminpack/Makefile | 24 -
contrib/adminpack/adminpack--1.0--1.1.sql | 6 -
contrib/adminpack/adminpack--1.0.sql | 53 --
contrib/adminpack/adminpack--1.1--2.0.sql | 51 --
contrib/adminpack/adminpack--2.0--2.1.sql | 17 -
contrib/adminpack/adminpack.c | 591 ----------------------
contrib/adminpack/adminpack.control | 6 -
contrib/adminpack/expected/adminpack.out | 172 -------
contrib/adminpack/meson.build | 35 --
contrib/adminpack/sql/adminpack.sql | 76 ---
contrib/meson.build | 1 -
doc/src/sgml/adminpack.sgml | 159 ------
doc/src/sgml/contrib.sgml | 1 -
doc/src/sgml/filelist.sgml | 1 -
src/backend/storage/ipc/signalfuncs.c | 29 +-
src/backend/utils/adt/genfile.c | 46 --
src/include/catalog/pg_proc.dat | 7 -
19 files changed, 1 insertion(+), 1279 deletions(-)
delete mode 100644 contrib/adminpack/.gitignore
delete mode 100644 contrib/adminpack/Makefile
delete mode 100644 contrib/adminpack/adminpack--1.0--1.1.sql
delete mode 100644 contrib/adminpack/adminpack--1.0.sql
delete mode 100644 contrib/adminpack/adminpack--1.1--2.0.sql
delete mode 100644 contrib/adminpack/adminpack--2.0--2.1.sql
delete mode 100644 contrib/adminpack/adminpack.c
delete mode 100644 contrib/adminpack/adminpack.control
delete mode 100644 contrib/adminpack/expected/adminpack.out
delete mode 100644 contrib/adminpack/meson.build
delete mode 100644 contrib/adminpack/sql/adminpack.sql
delete mode 100644 doc/src/sgml/adminpack.sgml
diff --git a/contrib/Makefile b/contrib/Makefile
index da4e2316a3..abd780f277 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -5,7 +5,6 @@ top_builddir = ..
include $(top_builddir)/src/Makefile.global
SUBDIRS = \
- adminpack \
amcheck \
auth_delay \
auto_explain \
diff --git a/contrib/adminpack/.gitignore b/contrib/adminpack/.gitignore
deleted file mode 100644
index 5dcb3ff972..0000000000
--- a/contrib/adminpack/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-# Generated subdirectories
-/log/
-/results/
-/tmp_check/
diff --git a/contrib/adminpack/Makefile b/contrib/adminpack/Makefile
deleted file mode 100644
index 851504f4ae..0000000000
--- a/contrib/adminpack/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-# contrib/adminpack/Makefile
-
-MODULE_big = adminpack
-OBJS = \
- $(WIN32RES) \
- adminpack.o
-
-EXTENSION = adminpack
-DATA = adminpack--1.0.sql adminpack--1.0--1.1.sql adminpack--1.1--2.0.sql\
- adminpack--2.0--2.1.sql
-PGFILEDESC = "adminpack - support functions for pgAdmin"
-
-REGRESS = adminpack
-
-ifdef USE_PGXS
-PG_CONFIG = pg_config
-PGXS := $(shell $(PG_CONFIG) --pgxs)
-include $(PGXS)
-else
-subdir = contrib/adminpack
-top_builddir = ../..
-include $(top_builddir)/src/Makefile.global
-include $(top_srcdir)/contrib/contrib-global.mk
-endif
diff --git a/contrib/adminpack/adminpack--1.0--1.1.sql b/contrib/adminpack/adminpack--1.0--1.1.sql
deleted file mode 100644
index bb581653e0..0000000000
--- a/contrib/adminpack/adminpack--1.0--1.1.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-/* contrib/adminpack/adminpack--1.0--1.1.sql */
-
--- complain if script is sourced in psql, rather than via ALTER EXTENSION
-\echo Use "ALTER EXTENSION adminpack UPDATE TO '1.1'" to load this file. \quit
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_logfile_rotate() FROM PUBLIC;
diff --git a/contrib/adminpack/adminpack--1.0.sql b/contrib/adminpack/adminpack--1.0.sql
deleted file mode 100644
index f76f5c3cdf..0000000000
--- a/contrib/adminpack/adminpack--1.0.sql
+++ /dev/null
@@ -1,53 +0,0 @@
-/* contrib/adminpack/adminpack--1.0.sql */
-
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION adminpack" to load this file. \quit
-
-/* ***********************************************
- * Administrative functions for PostgreSQL
- * *********************************************** */
-
-/* generic file access functions */
-
-CREATE FUNCTION pg_catalog.pg_file_write(text, text, bool)
-RETURNS bigint
-AS 'MODULE_PATHNAME', 'pg_file_write'
-LANGUAGE C VOLATILE STRICT;
-
-CREATE FUNCTION pg_catalog.pg_file_rename(text, text, text)
-RETURNS bool
-AS 'MODULE_PATHNAME', 'pg_file_rename'
-LANGUAGE C VOLATILE;
-
-CREATE FUNCTION pg_catalog.pg_file_rename(text, text)
-RETURNS bool
-AS 'SELECT pg_catalog.pg_file_rename($1, $2, NULL::pg_catalog.text);'
-LANGUAGE SQL VOLATILE STRICT;
-
-CREATE FUNCTION pg_catalog.pg_file_unlink(text)
-RETURNS bool
-AS 'MODULE_PATHNAME', 'pg_file_unlink'
-LANGUAGE C VOLATILE STRICT;
-
-CREATE FUNCTION pg_catalog.pg_logdir_ls()
-RETURNS setof record
-AS 'MODULE_PATHNAME', 'pg_logdir_ls'
-LANGUAGE C VOLATILE STRICT;
-
-
-/* Renaming of existing backend functions for pgAdmin compatibility */
-
-CREATE FUNCTION pg_catalog.pg_file_read(text, bigint, bigint)
-RETURNS text
-AS 'pg_read_file'
-LANGUAGE INTERNAL VOLATILE STRICT;
-
-CREATE FUNCTION pg_catalog.pg_file_length(text)
-RETURNS bigint
-AS 'SELECT size FROM pg_catalog.pg_stat_file($1)'
-LANGUAGE SQL VOLATILE STRICT;
-
-CREATE FUNCTION pg_catalog.pg_logfile_rotate()
-RETURNS int4
-AS 'pg_rotate_logfile'
-LANGUAGE INTERNAL VOLATILE STRICT;
diff --git a/contrib/adminpack/adminpack--1.1--2.0.sql b/contrib/adminpack/adminpack--1.1--2.0.sql
deleted file mode 100644
index ceaeafa378..0000000000
--- a/contrib/adminpack/adminpack--1.1--2.0.sql
+++ /dev/null
@@ -1,51 +0,0 @@
-/* contrib/adminpack/adminpack--1.1--2.0.sql */
-
--- complain if script is sourced in psql, rather than via ALTER EXTENSION
-\echo Use "ALTER EXTENSION adminpack UPDATE TO '2.0'" to load this file. \quit
-
-/* ***********************************************
- * Administrative functions for PostgreSQL
- * *********************************************** */
-
-/* generic file access functions */
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_file_write(text, text, bool)
-RETURNS bigint
-AS 'MODULE_PATHNAME', 'pg_file_write_v1_1'
-LANGUAGE C VOLATILE STRICT;
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_file_write(text, text, bool) FROM PUBLIC;
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_file_rename(text, text, text)
-RETURNS bool
-AS 'MODULE_PATHNAME', 'pg_file_rename_v1_1'
-LANGUAGE C VOLATILE;
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_file_rename(text, text, text) FROM PUBLIC;
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_file_rename(text, text)
-RETURNS bool
-AS 'SELECT pg_catalog.pg_file_rename($1, $2, NULL::pg_catalog.text);'
-LANGUAGE SQL VOLATILE STRICT;
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_file_unlink(text)
-RETURNS bool
-AS 'MODULE_PATHNAME', 'pg_file_unlink_v1_1'
-LANGUAGE C VOLATILE STRICT;
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_file_unlink(text) FROM PUBLIC;
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_logdir_ls()
-RETURNS setof record
-AS 'MODULE_PATHNAME', 'pg_logdir_ls_v1_1'
-LANGUAGE C VOLATILE STRICT;
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_logdir_ls() FROM PUBLIC;
-
-/* These functions are now in the backend and callers should update to use those */
-
-DROP FUNCTION pg_file_read(text, bigint, bigint);
-
-DROP FUNCTION pg_file_length(text);
-
-DROP FUNCTION pg_logfile_rotate();
diff --git a/contrib/adminpack/adminpack--2.0--2.1.sql b/contrib/adminpack/adminpack--2.0--2.1.sql
deleted file mode 100644
index 1c6712e816..0000000000
--- a/contrib/adminpack/adminpack--2.0--2.1.sql
+++ /dev/null
@@ -1,17 +0,0 @@
-/* contrib/adminpack/adminpack--2.0--2.1.sql */
-
--- complain if script is sourced in psql, rather than via ALTER EXTENSION
-\echo Use "ALTER EXTENSION adminpack UPDATE TO '2.1'" to load this file. \quit
-
-/* ***********************************************
- * Administrative functions for PostgreSQL
- * *********************************************** */
-
-/* generic file access functions */
-
-CREATE OR REPLACE FUNCTION pg_catalog.pg_file_sync(text)
-RETURNS void
-AS 'MODULE_PATHNAME', 'pg_file_sync'
-LANGUAGE C VOLATILE STRICT;
-
-REVOKE EXECUTE ON FUNCTION pg_catalog.pg_file_sync(text) FROM PUBLIC;
diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c
deleted file mode 100644
index 1d8b2bbe25..0000000000
--- a/contrib/adminpack/adminpack.c
+++ /dev/null
@@ -1,591 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * adminpack.c
- *
- *
- * Copyright (c) 2002-2024, PostgreSQL Global Development Group
- *
- * Author: Andreas Pflug <pgadmin@pse-consulting.de>
- *
- * IDENTIFICATION
- * contrib/adminpack/adminpack.c
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "catalog/pg_authid.h"
-#include "catalog/pg_type.h"
-#include "funcapi.h"
-#include "miscadmin.h"
-#include "postmaster/syslogger.h"
-#include "storage/fd.h"
-#include "utils/acl.h"
-#include "utils/builtins.h"
-#include "utils/datetime.h"
-
-
-#ifdef WIN32
-
-#ifdef rename
-#undef rename
-#endif
-
-#ifdef unlink
-#undef unlink
-#endif
-#endif
-
-PG_MODULE_MAGIC;
-
-PG_FUNCTION_INFO_V1(pg_file_write);
-PG_FUNCTION_INFO_V1(pg_file_write_v1_1);
-PG_FUNCTION_INFO_V1(pg_file_sync);
-PG_FUNCTION_INFO_V1(pg_file_rename);
-PG_FUNCTION_INFO_V1(pg_file_rename_v1_1);
-PG_FUNCTION_INFO_V1(pg_file_unlink);
-PG_FUNCTION_INFO_V1(pg_file_unlink_v1_1);
-PG_FUNCTION_INFO_V1(pg_logdir_ls);
-PG_FUNCTION_INFO_V1(pg_logdir_ls_v1_1);
-
-static int64 pg_file_write_internal(text *file, text *data, bool replace);
-static bool pg_file_rename_internal(text *file1, text *file2, text *file3);
-static Datum pg_logdir_ls_internal(FunctionCallInfo fcinfo);
-
-
-/*-----------------------
- * some helper functions
- */
-
-/*
- * Convert a "text" filename argument to C string, and check it's allowable.
- *
- * Filename may be absolute or relative to the DataDir, but we only allow
- * absolute paths that match DataDir.
- */
-static char *
-convert_and_check_filename(text *arg)
-{
- char *filename = text_to_cstring(arg);
-
- canonicalize_path(filename); /* filename can change length here */
-
- /*
- * Members of the 'pg_write_server_files' role are allowed to access any
- * files on the server as the PG user, so no need to do any further checks
- * here.
- */
- if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES))
- return filename;
-
- /*
- * User isn't a member of the pg_write_server_files role, so check if it's
- * allowable
- */
- if (is_absolute_path(filename))
- {
- /* Allow absolute paths if within DataDir */
- if (!path_is_prefix_of_path(DataDir, filename))
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("absolute path not allowed")));
- }
- else if (!path_is_relative_and_below_cwd(filename))
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("path must be in or below the data directory")));
-
- return filename;
-}
-
-
-/*
- * check for superuser, bark if not.
- */
-static void
-requireSuperuser(void)
-{
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("only superuser may access generic file functions")));
-}
-
-
-
-/* ------------------------------------
- * pg_file_write - old version
- *
- * The superuser() check here must be kept as the library might be upgraded
- * without the extension being upgraded, meaning that in pre-1.1 installations
- * these functions could be called by any user.
- */
-Datum
-pg_file_write(PG_FUNCTION_ARGS)
-{
- text *file = PG_GETARG_TEXT_PP(0);
- text *data = PG_GETARG_TEXT_PP(1);
- bool replace = PG_GETARG_BOOL(2);
- int64 count = 0;
-
- requireSuperuser();
-
- count = pg_file_write_internal(file, data, replace);
-
- PG_RETURN_INT64(count);
-}
-
-/* ------------------------------------
- * pg_file_write_v1_1 - Version 1.1
- *
- * As of adminpack version 1.1, we no longer need to check if the user
- * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
- * Users can then grant access to it based on their policies.
- *
- * Otherwise identical to pg_file_write (above).
- */
-Datum
-pg_file_write_v1_1(PG_FUNCTION_ARGS)
-{
- text *file = PG_GETARG_TEXT_PP(0);
- text *data = PG_GETARG_TEXT_PP(1);
- bool replace = PG_GETARG_BOOL(2);
- int64 count = 0;
-
- count = pg_file_write_internal(file, data, replace);
-
- PG_RETURN_INT64(count);
-}
-
-/* ------------------------------------
- * pg_file_write_internal - Workhorse for pg_file_write functions.
- *
- * This handles the actual work for pg_file_write.
- */
-static int64
-pg_file_write_internal(text *file, text *data, bool replace)
-{
- FILE *f;
- char *filename;
- int64 count = 0;
-
- filename = convert_and_check_filename(file);
-
- if (!replace)
- {
- struct stat fst;
-
- if (stat(filename, &fst) >= 0)
- ereport(ERROR,
- (errcode(ERRCODE_DUPLICATE_FILE),
- errmsg("file \"%s\" exists", filename)));
-
- f = AllocateFile(filename, "wb");
- }
- else
- f = AllocateFile(filename, "ab");
-
- if (!f)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open file \"%s\" for writing: %m",
- filename)));
-
- count = fwrite(VARDATA_ANY(data), 1, VARSIZE_ANY_EXHDR(data), f);
- if (count != VARSIZE_ANY_EXHDR(data) || FreeFile(f))
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not write file \"%s\": %m", filename)));
-
- return (count);
-}
-
-/* ------------------------------------
- * pg_file_sync
- *
- * We REVOKE EXECUTE on the function from PUBLIC.
- * Users can then grant access to it based on their policies.
- */
-Datum
-pg_file_sync(PG_FUNCTION_ARGS)
-{
- char *filename;
- struct stat fst;
-
- filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
-
- if (stat(filename, &fst) < 0)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not stat file \"%s\": %m", filename)));
-
- fsync_fname_ext(filename, S_ISDIR(fst.st_mode), false, ERROR);
-
- PG_RETURN_VOID();
-}
-
-/* ------------------------------------
- * pg_file_rename - old version
- *
- * The superuser() check here must be kept as the library might be upgraded
- * without the extension being upgraded, meaning that in pre-1.1 installations
- * these functions could be called by any user.
- */
-Datum
-pg_file_rename(PG_FUNCTION_ARGS)
-{
- text *file1;
- text *file2;
- text *file3;
- bool result;
-
- requireSuperuser();
-
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
- PG_RETURN_NULL();
-
- file1 = PG_GETARG_TEXT_PP(0);
- file2 = PG_GETARG_TEXT_PP(1);
-
- if (PG_ARGISNULL(2))
- file3 = NULL;
- else
- file3 = PG_GETARG_TEXT_PP(2);
-
- result = pg_file_rename_internal(file1, file2, file3);
-
- PG_RETURN_BOOL(result);
-}
-
-/* ------------------------------------
- * pg_file_rename_v1_1 - Version 1.1
- *
- * As of adminpack version 1.1, we no longer need to check if the user
- * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
- * Users can then grant access to it based on their policies.
- *
- * Otherwise identical to pg_file_write (above).
- */
-Datum
-pg_file_rename_v1_1(PG_FUNCTION_ARGS)
-{
- text *file1;
- text *file2;
- text *file3;
- bool result;
-
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
- PG_RETURN_NULL();
-
- file1 = PG_GETARG_TEXT_PP(0);
- file2 = PG_GETARG_TEXT_PP(1);
-
- if (PG_ARGISNULL(2))
- file3 = NULL;
- else
- file3 = PG_GETARG_TEXT_PP(2);
-
- result = pg_file_rename_internal(file1, file2, file3);
-
- PG_RETURN_BOOL(result);
-}
-
-/* ------------------------------------
- * pg_file_rename_internal - Workhorse for pg_file_rename functions.
- *
- * This handles the actual work for pg_file_rename.
- */
-static bool
-pg_file_rename_internal(text *file1, text *file2, text *file3)
-{
- char *fn1,
- *fn2,
- *fn3;
- int rc;
-
- fn1 = convert_and_check_filename(file1);
- fn2 = convert_and_check_filename(file2);
-
- if (file3 == NULL)
- fn3 = NULL;
- else
- fn3 = convert_and_check_filename(file3);
-
- if (access(fn1, W_OK) < 0)
- {
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("file \"%s\" is not accessible: %m", fn1)));
-
- return false;
- }
-
- if (fn3 && access(fn2, W_OK) < 0)
- {
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("file \"%s\" is not accessible: %m", fn2)));
-
- return false;
- }
-
- rc = access(fn3 ? fn3 : fn2, W_OK);
- if (rc >= 0 || errno != ENOENT)
- {
- ereport(ERROR,
- (errcode(ERRCODE_DUPLICATE_FILE),
- errmsg("cannot rename to target file \"%s\"",
- fn3 ? fn3 : fn2)));
- }
-
- if (fn3)
- {
- if (rename(fn2, fn3) != 0)
- {
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not rename \"%s\" to \"%s\": %m",
- fn2, fn3)));
- }
- if (rename(fn1, fn2) != 0)
- {
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not rename \"%s\" to \"%s\": %m",
- fn1, fn2)));
-
- if (rename(fn3, fn2) != 0)
- {
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not rename \"%s\" back to \"%s\": %m",
- fn3, fn2)));
- }
- else
- {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_FILE),
- errmsg("renaming \"%s\" to \"%s\" was reverted",
- fn2, fn3)));
- }
- }
- }
- else if (rename(fn1, fn2) != 0)
- {
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not rename \"%s\" to \"%s\": %m", fn1, fn2)));
- }
-
- return true;
-}
-
-
-/* ------------------------------------
- * pg_file_unlink - old version
- *
- * The superuser() check here must be kept as the library might be upgraded
- * without the extension being upgraded, meaning that in pre-1.1 installations
- * these functions could be called by any user.
- */
-Datum
-pg_file_unlink(PG_FUNCTION_ARGS)
-{
- char *filename;
-
- requireSuperuser();
-
- filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
-
- if (access(filename, W_OK) < 0)
- {
- if (errno == ENOENT)
- PG_RETURN_BOOL(false);
- else
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("file \"%s\" is not accessible: %m", filename)));
- }
-
- if (unlink(filename) < 0)
- {
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not unlink file \"%s\": %m", filename)));
-
- PG_RETURN_BOOL(false);
- }
- PG_RETURN_BOOL(true);
-}
-
-
-/* ------------------------------------
- * pg_file_unlink_v1_1 - Version 1.1
- *
- * As of adminpack version 1.1, we no longer need to check if the user
- * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
- * Users can then grant access to it based on their policies.
- *
- * Otherwise identical to pg_file_unlink (above).
- */
-Datum
-pg_file_unlink_v1_1(PG_FUNCTION_ARGS)
-{
- char *filename;
-
- filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
-
- if (access(filename, W_OK) < 0)
- {
- if (errno == ENOENT)
- PG_RETURN_BOOL(false);
- else
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("file \"%s\" is not accessible: %m", filename)));
- }
-
- if (unlink(filename) < 0)
- {
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not unlink file \"%s\": %m", filename)));
-
- PG_RETURN_BOOL(false);
- }
- PG_RETURN_BOOL(true);
-}
-
-/* ------------------------------------
- * pg_logdir_ls - Old version
- *
- * The superuser() check here must be kept as the library might be upgraded
- * without the extension being upgraded, meaning that in pre-1.1 installations
- * these functions could be called by any user.
- */
-Datum
-pg_logdir_ls(PG_FUNCTION_ARGS)
-{
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("only superuser can list the log directory")));
-
- return (pg_logdir_ls_internal(fcinfo));
-}
-
-/* ------------------------------------
- * pg_logdir_ls_v1_1 - Version 1.1
- *
- * As of adminpack version 1.1, we no longer need to check if the user
- * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
- * Users can then grant access to it based on their policies.
- *
- * Otherwise identical to pg_logdir_ls (above).
- */
-Datum
-pg_logdir_ls_v1_1(PG_FUNCTION_ARGS)
-{
- return (pg_logdir_ls_internal(fcinfo));
-}
-
-static Datum
-pg_logdir_ls_internal(FunctionCallInfo fcinfo)
-{
- ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- bool randomAccess;
- TupleDesc tupdesc;
- Tuplestorestate *tupstore;
- AttInMetadata *attinmeta;
- DIR *dirdesc;
- struct dirent *de;
- MemoryContext oldcontext;
-
- if (strcmp(Log_filename, "postgresql-%Y-%m-%d_%H%M%S.log") != 0)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("the log_filename parameter must equal 'postgresql-%%Y-%%m-%%d_%%H%%M%%S.log'")));
-
- /* check to see if caller supports us returning a tuplestore */
- if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("set-valued function called in context that cannot accept a set")));
- if (!(rsinfo->allowedModes & SFRM_Materialize))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("materialize mode required, but it is not allowed in this context")));
-
- /* The tupdesc and tuplestore must be created in ecxt_per_query_memory */
- oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory);
-
- tupdesc = CreateTemplateTupleDesc(2);
- TupleDescInitEntry(tupdesc, (AttrNumber) 1, "starttime",
- TIMESTAMPOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 2, "filename",
- TEXTOID, -1, 0);
-
- randomAccess = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0;
- tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);
- rsinfo->returnMode = SFRM_Materialize;
- rsinfo->setResult = tupstore;
- rsinfo->setDesc = tupdesc;
-
- MemoryContextSwitchTo(oldcontext);
-
- attinmeta = TupleDescGetAttInMetadata(tupdesc);
-
- dirdesc = AllocateDir(Log_directory);
- while ((de = ReadDir(dirdesc, Log_directory)) != NULL)
- {
- char *values[2];
- HeapTuple tuple;
- char timestampbuf[32];
- char *field[MAXDATEFIELDS];
- char lowstr[MAXDATELEN + 1];
- int dtype;
- int nf,
- ftype[MAXDATEFIELDS];
- fsec_t fsec;
- int tz = 0;
- struct pg_tm date;
- DateTimeErrorExtra extra;
-
- /*
- * Default format: postgresql-YYYY-MM-DD_HHMMSS.log
- */
- if (strlen(de->d_name) != 32
- || strncmp(de->d_name, "postgresql-", 11) != 0
- || de->d_name[21] != '_'
- || strcmp(de->d_name + 28, ".log") != 0)
- continue;
-
- /* extract timestamp portion of filename */
- strcpy(timestampbuf, de->d_name + 11);
- timestampbuf[17] = '\0';
-
- /* parse and decode expected timestamp to verify it's OK format */
- if (ParseDateTime(timestampbuf, lowstr, MAXDATELEN, field, ftype, MAXDATEFIELDS, &nf))
- continue;
-
- if (DecodeDateTime(field, ftype, nf,
- &dtype, &date, &fsec, &tz, &extra))
- continue;
-
- /* Seems the timestamp is OK; prepare and return tuple */
-
- values[0] = timestampbuf;
- values[1] = psprintf("%s/%s", Log_directory, de->d_name);
-
- tuple = BuildTupleFromCStrings(attinmeta, values);
-
- tuplestore_puttuple(tupstore, tuple);
- }
-
- FreeDir(dirdesc);
- return (Datum) 0;
-}
diff --git a/contrib/adminpack/adminpack.control b/contrib/adminpack/adminpack.control
deleted file mode 100644
index ae35d22156..0000000000
--- a/contrib/adminpack/adminpack.control
+++ /dev/null
@@ -1,6 +0,0 @@
-# adminpack extension
-comment = 'administrative functions for PostgreSQL'
-default_version = '2.1'
-module_pathname = '$libdir/adminpack'
-relocatable = false
-schema = pg_catalog
diff --git a/contrib/adminpack/expected/adminpack.out b/contrib/adminpack/expected/adminpack.out
deleted file mode 100644
index f419a5ea1d..0000000000
--- a/contrib/adminpack/expected/adminpack.out
+++ /dev/null
@@ -1,172 +0,0 @@
-CREATE EXTENSION adminpack;
--- create new file
-SELECT pg_file_write('test_file1', 'test1', false);
- pg_file_write
----------------
- 5
-(1 row)
-
-SELECT pg_read_file('test_file1');
- pg_read_file
---------------
- test1
-(1 row)
-
--- append
-SELECT pg_file_write('test_file1', 'test1', true);
- pg_file_write
----------------
- 5
-(1 row)
-
-SELECT pg_read_file('test_file1');
- pg_read_file
---------------
- test1test1
-(1 row)
-
--- error, already exists
-SELECT pg_file_write('test_file1', 'test1', false);
-ERROR: file "test_file1" exists
-SELECT pg_read_file('test_file1');
- pg_read_file
---------------
- test1test1
-(1 row)
-
--- disallowed file paths for non-superusers and users who are
--- not members of pg_write_server_files
-CREATE ROLE regress_adminpack_user1;
-GRANT pg_read_all_settings TO regress_adminpack_user1;
-GRANT EXECUTE ON FUNCTION pg_file_write(text,text,bool) TO regress_adminpack_user1;
-SET ROLE regress_adminpack_user1;
-SELECT pg_file_write('../test_file0', 'test0', false);
-ERROR: path must be in or below the data directory
-SELECT pg_file_write('/tmp/test_file0', 'test0', false);
-ERROR: absolute path not allowed
-SELECT pg_file_write(current_setting('data_directory') || '/test_file4', 'test4', false);
- pg_file_write
----------------
- 5
-(1 row)
-
-SELECT pg_file_write(current_setting('data_directory') || '/../test_file4', 'test4', false);
-ERROR: absolute path not allowed
-RESET ROLE;
-REVOKE EXECUTE ON FUNCTION pg_file_write(text,text,bool) FROM regress_adminpack_user1;
-REVOKE pg_read_all_settings FROM regress_adminpack_user1;
-DROP ROLE regress_adminpack_user1;
--- sync
-SELECT pg_file_sync('test_file1'); -- sync file
- pg_file_sync
---------------
-
-(1 row)
-
-SELECT pg_file_sync('pg_stat'); -- sync directory
- pg_file_sync
---------------
-
-(1 row)
-
-SELECT pg_file_sync('test_file2'); -- not there
-ERROR: could not stat file "test_file2": No such file or directory
--- rename file
-SELECT pg_file_rename('test_file1', 'test_file2');
- pg_file_rename
-----------------
- t
-(1 row)
-
-SELECT pg_read_file('test_file1'); -- not there
-ERROR: could not open file "test_file1" for reading: No such file or directory
-SELECT pg_read_file('test_file2');
- pg_read_file
---------------
- test1test1
-(1 row)
-
--- error
-SELECT pg_file_rename('test_file1', 'test_file2');
-WARNING: file "test_file1" is not accessible: No such file or directory
- pg_file_rename
-----------------
- f
-(1 row)
-
--- rename file and archive
-SELECT pg_file_write('test_file3', 'test3', false);
- pg_file_write
----------------
- 5
-(1 row)
-
-SELECT pg_file_rename('test_file2', 'test_file3', 'test_file3_archive');
- pg_file_rename
-----------------
- t
-(1 row)
-
-SELECT pg_read_file('test_file2'); -- not there
-ERROR: could not open file "test_file2" for reading: No such file or directory
-SELECT pg_read_file('test_file3');
- pg_read_file
---------------
- test1test1
-(1 row)
-
-SELECT pg_read_file('test_file3_archive');
- pg_read_file
---------------
- test3
-(1 row)
-
--- unlink
-SELECT pg_file_unlink('test_file1'); -- does not exist
- pg_file_unlink
-----------------
- f
-(1 row)
-
-SELECT pg_file_unlink('test_file2'); -- does not exist
- pg_file_unlink
-----------------
- f
-(1 row)
-
-SELECT pg_file_unlink('test_file3');
- pg_file_unlink
-----------------
- t
-(1 row)
-
-SELECT pg_file_unlink('test_file3_archive');
- pg_file_unlink
-----------------
- t
-(1 row)
-
-SELECT pg_file_unlink('test_file4');
- pg_file_unlink
-----------------
- t
-(1 row)
-
--- superuser checks
-CREATE USER regress_adminpack_user1;
-SET ROLE regress_adminpack_user1;
-SELECT pg_file_write('test_file0', 'test0', false);
-ERROR: permission denied for function pg_file_write
-SELECT pg_file_sync('test_file0');
-ERROR: permission denied for function pg_file_sync
-SELECT pg_file_rename('test_file0', 'test_file0');
-ERROR: permission denied for function pg_file_rename
-CONTEXT: SQL function "pg_file_rename" statement 1
-SELECT pg_file_unlink('test_file0');
-ERROR: permission denied for function pg_file_unlink
-SELECT pg_logdir_ls();
-ERROR: permission denied for function pg_logdir_ls
-RESET ROLE;
-DROP USER regress_adminpack_user1;
--- no further tests for pg_logdir_ls() because it depends on the
--- server's logging setup
diff --git a/contrib/adminpack/meson.build b/contrib/adminpack/meson.build
deleted file mode 100644
index e5bcc9d99b..0000000000
--- a/contrib/adminpack/meson.build
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (c) 2022-2024, PostgreSQL Global Development Group
-
-adminpack_sources = files(
- 'adminpack.c',
-)
-
-if host_system == 'windows'
- adminpack_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
- '--NAME', 'adminpack',
- '--FILEDESC', 'adminpack - support functions for pgAdmin',])
-endif
-
-adminpack = shared_module('adminpack',
- adminpack_sources,
- kwargs: contrib_mod_args,
-)
-contrib_targets += adminpack
-
-install_data(
- 'adminpack.control',
- 'adminpack--1.0.sql',
- 'adminpack--1.0--1.1.sql',
- 'adminpack--1.1--2.0.sql',
- 'adminpack--2.0--2.1.sql',
- kwargs: contrib_data_args,
-)
-
-tests += {
- 'name': 'adminpack',
- 'sd': meson.current_source_dir(),
- 'bd': meson.current_build_dir(),
- 'regress': {
- 'sql': ['adminpack'],
- },
-}
diff --git a/contrib/adminpack/sql/adminpack.sql b/contrib/adminpack/sql/adminpack.sql
deleted file mode 100644
index 5776c9af0d..0000000000
--- a/contrib/adminpack/sql/adminpack.sql
+++ /dev/null
@@ -1,76 +0,0 @@
-CREATE EXTENSION adminpack;
-
--- create new file
-SELECT pg_file_write('test_file1', 'test1', false);
-SELECT pg_read_file('test_file1');
-
--- append
-SELECT pg_file_write('test_file1', 'test1', true);
-SELECT pg_read_file('test_file1');
-
--- error, already exists
-SELECT pg_file_write('test_file1', 'test1', false);
-SELECT pg_read_file('test_file1');
-
--- disallowed file paths for non-superusers and users who are
--- not members of pg_write_server_files
-CREATE ROLE regress_adminpack_user1;
-
-GRANT pg_read_all_settings TO regress_adminpack_user1;
-GRANT EXECUTE ON FUNCTION pg_file_write(text,text,bool) TO regress_adminpack_user1;
-
-SET ROLE regress_adminpack_user1;
-SELECT pg_file_write('../test_file0', 'test0', false);
-SELECT pg_file_write('/tmp/test_file0', 'test0', false);
-SELECT pg_file_write(current_setting('data_directory') || '/test_file4', 'test4', false);
-SELECT pg_file_write(current_setting('data_directory') || '/../test_file4', 'test4', false);
-RESET ROLE;
-REVOKE EXECUTE ON FUNCTION pg_file_write(text,text,bool) FROM regress_adminpack_user1;
-REVOKE pg_read_all_settings FROM regress_adminpack_user1;
-DROP ROLE regress_adminpack_user1;
-
--- sync
-SELECT pg_file_sync('test_file1'); -- sync file
-SELECT pg_file_sync('pg_stat'); -- sync directory
-SELECT pg_file_sync('test_file2'); -- not there
-
--- rename file
-SELECT pg_file_rename('test_file1', 'test_file2');
-SELECT pg_read_file('test_file1'); -- not there
-SELECT pg_read_file('test_file2');
-
--- error
-SELECT pg_file_rename('test_file1', 'test_file2');
-
--- rename file and archive
-SELECT pg_file_write('test_file3', 'test3', false);
-SELECT pg_file_rename('test_file2', 'test_file3', 'test_file3_archive');
-SELECT pg_read_file('test_file2'); -- not there
-SELECT pg_read_file('test_file3');
-SELECT pg_read_file('test_file3_archive');
-
-
--- unlink
-SELECT pg_file_unlink('test_file1'); -- does not exist
-SELECT pg_file_unlink('test_file2'); -- does not exist
-SELECT pg_file_unlink('test_file3');
-SELECT pg_file_unlink('test_file3_archive');
-SELECT pg_file_unlink('test_file4');
-
-
--- superuser checks
-CREATE USER regress_adminpack_user1;
-SET ROLE regress_adminpack_user1;
-
-SELECT pg_file_write('test_file0', 'test0', false);
-SELECT pg_file_sync('test_file0');
-SELECT pg_file_rename('test_file0', 'test_file0');
-SELECT pg_file_unlink('test_file0');
-SELECT pg_logdir_ls();
-
-RESET ROLE;
-DROP USER regress_adminpack_user1;
-
-
--- no further tests for pg_logdir_ls() because it depends on the
--- server's logging setup
diff --git a/contrib/meson.build b/contrib/meson.build
index c12dc906ca..14a8906865 100644
--- a/contrib/meson.build
+++ b/contrib/meson.build
@@ -12,7 +12,6 @@ contrib_doc_args = {
'install_dir': contrib_doc_dir,
}
-subdir('adminpack')
subdir('amcheck')
subdir('auth_delay')
subdir('auto_explain')
diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml
deleted file mode 100644
index 04f3b52379..0000000000
--- a/doc/src/sgml/adminpack.sgml
+++ /dev/null
@@ -1,159 +0,0 @@
-<!-- doc/src/sgml/adminpack.sgml -->
-
-<sect1 id="adminpack" xreflabel="adminpack">
- <title>adminpack — pgAdmin support toolpack</title>
-
- <indexterm zone="adminpack">
- <primary>adminpack</primary>
- </indexterm>
-
- <para>
- <filename>adminpack</filename> provides a number of support functions which
- <application>pgAdmin</application> and other administration and management tools can
- use to provide additional functionality, such as remote management
- of server log files.
- Use of all these functions is only allowed to database superusers by default, but may be
- allowed to other users by using the <command>GRANT</command> command.
- </para>
-
- <para>
- The functions shown in <xref linkend="functions-adminpack-table"/> provide
- write access to files on the machine hosting the server. (See also the
- functions in <xref linkend="functions-admin-genfile-table"/>, which
- provide read-only access.)
- Only files within the database cluster directory can be accessed, unless the
- user is a superuser or given privileges of one of the
- <literal>pg_read_server_files</literal> or
- <literal>pg_write_server_files</literal> roles, as appropriate for the
- function, but either a relative or absolute path is allowable.
- </para>
-
- <table id="functions-adminpack-table">
- <title><filename>adminpack</filename> Functions</title>
- <tgroup cols="1">
- <thead>
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- Function
- </para>
- <para>
- Description
- </para></entry>
- </row>
- </thead>
-
- <tbody>
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- <function>pg_catalog.pg_file_write</function> ( <parameter>filename</parameter> <type>text</type>, <parameter>data</parameter> <type>text</type>, <parameter>append</parameter> <type>boolean</type> )
- <returnvalue>bigint</returnvalue>
- </para>
- <para>
- Writes, or appends to, a text file.
- </para></entry>
- </row>
-
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- <function>pg_catalog.pg_file_sync</function> ( <parameter>filename</parameter> <type>text</type> )
- <returnvalue>void</returnvalue>
- </para>
- <para>
- Flushes a file or directory to disk.
- </para></entry>
- </row>
-
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- <function>pg_catalog.pg_file_rename</function> ( <parameter>oldname</parameter> <type>text</type>, <parameter>newname</parameter> <type>text</type> <optional>, <parameter>archivename</parameter> <type>text</type> </optional> )
- <returnvalue>boolean</returnvalue>
- </para>
- <para>
- Renames a file.
- </para></entry>
- </row>
-
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- <function>pg_catalog.pg_file_unlink</function> ( <parameter>filename</parameter> <type>text</type> )
- <returnvalue>boolean</returnvalue>
- </para>
- <para>
- Removes a file.
- </para></entry>
- </row>
-
- <row>
- <entry role="func_table_entry"><para role="func_signature">
- <function>pg_catalog.pg_logdir_ls</function> ()
- <returnvalue>setof record</returnvalue>
- </para>
- <para>
- Lists the log files in the <varname>log_directory</varname> directory.
- </para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <indexterm>
- <primary>pg_file_write</primary>
- </indexterm>
- <para>
- <function>pg_file_write</function> writes the specified <parameter>data</parameter> into
- the file named by <parameter>filename</parameter>. If <parameter>append</parameter> is
- false, the file must not already exist. If <parameter>append</parameter> is true,
- the file can already exist, and will be appended to if so.
- Returns the number of bytes written.
- </para>
-
- <indexterm>
- <primary>pg_file_sync</primary>
- </indexterm>
- <para>
- <function>pg_file_sync</function> fsyncs the specified file or directory
- named by <parameter>filename</parameter>. An error is thrown
- on failure (e.g., the specified file is not present). Note that
- <xref linkend="guc-data-sync-retry"/> has no effect on this function,
- and therefore a PANIC-level error will not be raised even on failure to
- flush database files.
- </para>
-
- <indexterm>
- <primary>pg_file_rename</primary>
- </indexterm>
- <para>
- <function>pg_file_rename</function> renames a file. If <parameter>archivename</parameter>
- is omitted or NULL, it simply renames <parameter>oldname</parameter>
- to <parameter>newname</parameter> (which must not already exist).
- If <parameter>archivename</parameter> is provided, it first
- renames <parameter>newname</parameter> to <parameter>archivename</parameter> (which must
- not already exist), and then renames <parameter>oldname</parameter>
- to <parameter>newname</parameter>. In event of failure of the second rename step,
- it will try to rename <parameter>archivename</parameter> back
- to <parameter>newname</parameter> before reporting the error.
- Returns true on success, false if the source file(s) are not present or
- not writable; other cases throw errors.
- </para>
-
- <indexterm>
- <primary>pg_file_unlink</primary>
- </indexterm>
- <para>
- <function>pg_file_unlink</function> removes the specified file.
- Returns true on success, false if the specified file is not present
- or the <function>unlink()</function> call fails; other cases throw errors.
- </para>
-
- <indexterm>
- <primary>pg_logdir_ls</primary>
- </indexterm>
- <para>
- <function>pg_logdir_ls</function> returns the start timestamps and path
- names of all the log files in the <xref linkend="guc-log-directory"/>
- directory. The <xref linkend="guc-log-filename"/> parameter must have its
- default setting (<literal>postgresql-%Y-%m-%d_%H%M%S.log</literal>) to use this
- function.
- </para>
-
-</sect1>
diff --git a/doc/src/sgml/contrib.sgml b/doc/src/sgml/contrib.sgml
index ab7e38b52a..44639a8dca 100644
--- a/doc/src/sgml/contrib.sgml
+++ b/doc/src/sgml/contrib.sgml
@@ -127,7 +127,6 @@ CREATE EXTENSION <replaceable>extension_name</replaceable>;
component for details.
</para>
- &adminpack;
&amcheck;
&auth-delay;
&auto-explain;
diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml
index bb4926b887..e0dca81cb2 100644
--- a/doc/src/sgml/filelist.sgml
+++ b/doc/src/sgml/filelist.sgml
@@ -113,7 +113,6 @@
<!-- contrib information -->
<!ENTITY contrib SYSTEM "contrib.sgml">
-<!ENTITY adminpack SYSTEM "adminpack.sgml">
<!ENTITY amcheck SYSTEM "amcheck.sgml">
<!ENTITY auth-delay SYSTEM "auth-delay.sgml">
<!ENTITY auto-explain SYSTEM "auto-explain.sgml">
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index 81d1a59659..402954930d 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -270,33 +270,6 @@ pg_reload_conf(PG_FUNCTION_ARGS)
}
-/*
- * Rotate log file
- *
- * This function is kept to support adminpack 1.0.
- */
-Datum
-pg_rotate_logfile(PG_FUNCTION_ARGS)
-{
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("must be superuser to rotate log files with adminpack 1.0"),
- /* translator: %s is a SQL function name */
- errhint("Consider using %s, which is part of core, instead.",
- "pg_logfile_rotate()")));
-
- if (!Logging_collector)
- {
- ereport(WARNING,
- (errmsg("rotation not possible because log collection not active")));
- PG_RETURN_BOOL(false);
- }
-
- SendPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE);
- PG_RETURN_BOOL(true);
-}
-
/*
* Rotate log file
*
@@ -304,7 +277,7 @@ pg_rotate_logfile(PG_FUNCTION_ARGS)
* GRANT system.
*/
Datum
-pg_rotate_logfile_v2(PG_FUNCTION_ARGS)
+pg_rotate_logfile(PG_FUNCTION_ARGS)
{
if (!Logging_collector)
{
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index ca19903ac6..0d82557417 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -227,52 +227,6 @@ read_text_file(const char *filename, int64 seek_offset, int64 bytes_to_read,
return NULL;
}
-/*
- * Read a section of a file, returning it as text
- *
- * This function is kept to support adminpack 1.0.
- */
-Datum
-pg_read_file(PG_FUNCTION_ARGS)
-{
- text *filename_t = PG_GETARG_TEXT_PP(0);
- int64 seek_offset = 0;
- int64 bytes_to_read = -1;
- bool missing_ok = false;
- char *filename;
- text *result;
-
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("must be superuser to read files with adminpack 1.0"),
- /* translator: %s is a SQL function name */
- errhint("Consider using %s, which is part of core, instead.",
- "pg_read_file()")));
-
- /* handle optional arguments */
- if (PG_NARGS() >= 3)
- {
- seek_offset = PG_GETARG_INT64(1);
- bytes_to_read = PG_GETARG_INT64(2);
-
- if (bytes_to_read < 0)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("requested length cannot be negative")));
- }
- if (PG_NARGS() >= 4)
- missing_ok = PG_GETARG_BOOL(3);
-
- filename = convert_and_check_filename(filename_t);
-
- result = read_text_file(filename, seek_offset, bytes_to_read, missing_ok);
- if (result)
- PG_RETURN_TEXT_P(result);
- else
- PG_RETURN_NULL();
-}
-
/*
* Read a section of a file, returning it as text
*
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 9c120fc2b7..291ed876fc 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -6545,9 +6545,6 @@
proargtypes => '', prosrc => 'pg_reload_conf' },
{ oid => '2622', descr => 'rotate log file',
proname => 'pg_rotate_logfile', provolatile => 'v', prorettype => 'bool',
- proargtypes => '', prosrc => 'pg_rotate_logfile_v2' },
-{ oid => '4099', descr => 'rotate log file - old version for adminpack 1.0',
- proname => 'pg_rotate_logfile_old', provolatile => 'v', prorettype => 'bool',
proargtypes => '', prosrc => 'pg_rotate_logfile' },
{ oid => '3800', descr => 'current logging collector file location',
proname => 'pg_current_logfile', proisstrict => 'f', provolatile => 'v',
@@ -6578,10 +6575,6 @@
proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
proargtypes => 'text int8 int8 bool',
prosrc => 'pg_read_file_off_len_missing' },
-{ oid => '4100',
- descr => 'read text from a file - old version for adminpack 1.0',
- proname => 'pg_read_file_old', provolatile => 'v', prorettype => 'text',
- proargtypes => 'text int8 int8', prosrc => 'pg_read_file' },
{ oid => '3826', descr => 'read text from a file',
proname => 'pg_read_file', provolatile => 'v', prorettype => 'text',
proargtypes => 'text', prosrc => 'pg_read_file_all' },
--
2.32.1 (Apple Git-133)
Daniel Gustafsson <daniel@yesql.se> writes:
On 14 Feb 2024, at 11:35, Dave Page <dpage@pgadmin.org> wrote:
That said, pgAdmin III has been out of support for many years, and as far as I know, it (and similarly old versions of EDB's PEM which was based on it) were the only consumers of adminpack. I would not be sad to see it removed entirely
Searching on Github and Debian Codesearch I cannot find any reference to anyone
using any function from adminpack. With pgAdminIII being EOL it might be to
remove it now rather than be on the hook to maintain it for another 5 years
until v17 goes EOL. It'll still be around for years in V16->.
Works for me.
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).
I don't see any references you missed, so +1.
regards, tom lane
On Wed, Feb 14, 2024 at 10:04:49AM -0500, Tom Lane wrote:
Daniel Gustafsson <daniel@yesql.se> writes:
On 14 Feb 2024, at 11:35, Dave Page <dpage@pgadmin.org> wrote:
That said, pgAdmin III has been out of support for many years, and as
far as I know, it (and similarly old versions of EDB's PEM which was
based on it) were the only consumers of adminpack. I would not be sad
to see it removed entirelySearching on Github and Debian Codesearch I cannot find any reference to anyone
using any function from adminpack. With pgAdminIII being EOL it might be to
remove it now rather than be on the hook to maintain it for another 5 years
until v17 goes EOL. It'll still be around for years in V16->.Works for me.
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).I don't see any references you missed, so +1.
Seems reasonable to me, too.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
On 14 Feb 2024, at 19:51, Nathan Bossart <nathandbossart@gmail.com> wrote:
On Wed, Feb 14, 2024 at 10:04:49AM -0500, Tom Lane wrote:
Daniel Gustafsson <daniel@yesql.se> writes:
On 14 Feb 2024, at 11:35, Dave Page <dpage@pgadmin.org> wrote:
That said, pgAdmin III has been out of support for many years, and as
far as I know, it (and similarly old versions of EDB's PEM which was
based on it) were the only consumers of adminpack. I would not be sad
to see it removed entirelySearching on Github and Debian Codesearch I cannot find any reference to anyone
using any function from adminpack. With pgAdminIII being EOL it might be to
remove it now rather than be on the hook to maintain it for another 5 years
until v17 goes EOL. It'll still be around for years in V16->.Works for me.
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).I don't see any references you missed, so +1.
Seems reasonable to me, too.
Thanks! I'll put this in the next CF to keep it open for comments a bit
longer, but will close it early in the CF.
--
Daniel Gustafsson
On Thu, Feb 15, 2024 at 2:18 AM Daniel Gustafsson <daniel@yesql.se> wrote:
Searching on Github and Debian Codesearch I cannot find any reference to anyone
using any function from adminpack. With pgAdminIII being EOL it might be to
remove it now rather than be on the hook to maintain it for another 5 years
until v17 goes EOL. It'll still be around for years in V16->.Works for me.
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).I don't see any references you missed, so +1.
Seems reasonable to me, too.
Thanks! I'll put this in the next CF to keep it open for comments a bit
longer, but will close it early in the CF.
LGTM.
--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
On 14 Feb 2024, at 21:48, Daniel Gustafsson <daniel@yesql.se> wrote:
On 14 Feb 2024, at 19:51, Nathan Bossart <nathandbossart@gmail.com> wrote:
On Wed, Feb 14, 2024 at 10:04:49AM -0500, Tom Lane wrote:Daniel Gustafsson <daniel@yesql.se> writes:
Attached is a diff to show what it would look like to remove adminpack (catalog
version bump omitted on purpose to avoid conflicts until commit).I don't see any references you missed, so +1.
Seems reasonable to me, too.
Thanks! I'll put this in the next CF to keep it open for comments a bit
longer, but will close it early in the CF.
This has now been pushed, adminpack has left the building.
--
Daniel Gustafsson