diff options
author | Robert Haas <rhaas@postgresql.org> | 2022-02-02 13:50:33 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2022-02-02 13:50:33 -0500 |
commit | 8e2b6d45a033287da7c8f63062129ea02d86d831 (patch) | |
tree | 5646b26b11d68619f3b494a3b15b8177c53bd349 /src | |
parent | 87669de72c2249e6aec84b8c27fdc3ffb7284e13 (diff) | |
download | postgresql-8e2b6d45a033287da7c8f63062129ea02d86d831.tar.gz postgresql-8e2b6d45a033287da7c8f63062129ea02d86d831.zip |
Fix server crash bug in 'server' backup target.
When this code executed as superuser it appeared to work because no
system catalog lookups happened, but otherwise it crashes because there
is no transaction environment. Fix that.
Report and code change by me. Test case by Dagfinn Ilmari Mannsåker.
Discussion: http://postgr.es/m/CA+TgmobiKLXne-2AVzYyWRiO8=rChBQ=7ywoxp=2SmcFw=oDDw@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/basebackup_server.c | 3 | ||||
-rw-r--r-- | src/bin/pg_basebackup/t/010_pg_basebackup.pl | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/replication/basebackup_server.c b/src/backend/replication/basebackup_server.c index 18b0e11d903..a8786296686 100644 --- a/src/backend/replication/basebackup_server.c +++ b/src/backend/replication/basebackup_server.c @@ -10,6 +10,7 @@ */ #include "postgres.h" +#include "access/xact.h" #include "catalog/pg_authid.h" #include "miscadmin.h" #include "replication/basebackup.h" @@ -67,10 +68,12 @@ bbsink_server_new(bbsink *next, char *pathname) sink->base.bbs_next = next; /* Replication permission is not sufficient in this case. */ + StartTransactionCommand(); if (!is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser or a member of the pg_write_server_files role to create server backup"))); + CommitTransactionCommand(); /* * It's not a good idea to store your backups in the same directory that diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index a827be5e592..2283a8c42d5 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -10,7 +10,7 @@ use File::Path qw(rmtree); use Fcntl qw(:seek); use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; -use Test::More tests => 143; +use Test::More; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -521,6 +521,15 @@ $node->command_ok( ok(-f "$tempdir/backuponserver/base.tar", 'backup tar was created'); rmtree("$tempdir/backuponserver"); +$node->command_ok( + [qw(createuser --replication --role=pg_write_server_files backupuser)], + 'create backup user'); +$node->command_ok( + [ @pg_basebackup_defs, '-U', 'backupuser', '--target', "server:$real_tempdir/backuponserver", '-X', 'none' ], + 'backup target server'); +ok(-f "$tempdir/backuponserver/base.tar", 'backup tar was created as non-superuser'); +rmtree("$tempdir/backuponserver"); + $node->command_fails( [ @pg_basebackup_defs, '-D', @@ -768,3 +777,5 @@ SKIP: rmtree("$tempdir/backup_gzip2"); rmtree("$tempdir/backup_gzip3"); } + +done_testing(); |