1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-20 00:42:27 +03:00
postgres/src/bin/pg_rewind/t/002_databases.pl
Stephen Frost c37b3d08ca Allow group access on PGDATA
Allow the cluster to be optionally init'd with read access for the
group.

This means a relatively non-privileged user can perform a backup of the
cluster without requiring write privileges, which enhances security.

The mode of PGDATA is used to determine whether group permissions are
enabled for directory and file creates.  This method was chosen as it's
simple and works well for the various utilities that write into PGDATA.

Changing the mode of PGDATA manually will not automatically change the
mode of all the files contained therein.  If the user would like to
enable group access on an existing cluster then changing the mode of all
the existing files will be required.  Note that pg_upgrade will
automatically change the mode of all migrated files if the new cluster
is init'd with the -g option.

Tests are included for the backend and all the utilities which operate
on the PG data directory to ensure that the correct mode is set based on
the data directory permissions.

Author: David Steele <david@pgmasters.net>
Reviewed-By: Michael Paquier, with discussion amongst many others.
Discussion: https://postgr.es/m/ad346fe6-b23e-59f1-ecb7-0e08390ad629%40pgmasters.net
2018-04-07 17:45:39 -04:00

62 lines
1.3 KiB
Perl

use strict;
use warnings;
use TestLib;
use Test::More tests => 6;
use RewindTest;
sub run_test
{
my $test_mode = shift;
RewindTest::setup_cluster($test_mode, ['-g']);
RewindTest::start_master();
# Create a database in master.
master_psql('CREATE DATABASE inmaster');
RewindTest::create_standby($test_mode);
# Create another database, the creation is replicated to the standby
master_psql('CREATE DATABASE beforepromotion');
RewindTest::promote_standby();
# Create databases in the old master and the new promoted standby.
master_psql('CREATE DATABASE master_afterpromotion');
standby_psql('CREATE DATABASE standby_afterpromotion');
# The clusters are now diverged.
RewindTest::run_pg_rewind($test_mode);
# Check that the correct databases are present after pg_rewind.
check_query(
'SELECT datname FROM pg_database ORDER BY 1',
qq(beforepromotion
inmaster
postgres
standby_afterpromotion
template0
template1
),
'database names');
# Permissions on PGDATA should have group permissions
SKIP:
{
skip "unix-style permissions not supported on Windows", 1 if ($windows_os);
ok(check_mode_recursive($node_master->data_dir(), 0750, 0640),
'check PGDATA permissions');
}
RewindTest::clean_rewind_test();
}
# Run the test in both modes.
run_test('local');
run_test('remote');
exit(0);