On Wed, Oct 20, 2021 at 09:19:51AM -0300, Alvaro Herrera wrote: > Ouch ... this means that pg_shdepends contents are broken for databases > created with 14.0? hmm ... yes.
Yes, it means so :( I have fixed the issue for now, and monitored the rest of the tree. Another issue is that we have zero coverage for this area of the code when creating a database from a template and copying over shared dependencies: https://coverage.postgresql.org/src/backend/catalog/pg_shdepend.c.gcov.html It is easy enough to get an error on the new database with pg_describe_object(). Your part about adding a shared dependency with a table on a given role is simple enough, as well. While looking for a place where to put such a test, 020_createdb.pl felt like a natural place and we don't have any coverage for the case of TEMPLATE with createdb. So I would like to suggest something like the attached for HEAD. -- Michael
diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl
index 3db2f13ae2..5e03ac8937 100644
--- a/src/bin/scripts/t/020_createdb.pl
+++ b/src/bin/scripts/t/020_createdb.pl
@@ -6,7 +6,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 22;
+use Test::More tests => 25;
program_help_ok('createdb');
program_version_ok('createdb');
@@ -28,6 +28,28 @@ $node->issues_sql_like(
$node->command_fails([ 'createdb', 'foobar1' ],
'fails if database already exists');
+# Check use of templates with shared dependencies copied from the template.
+my ($ret, $stdout, $stderr) = $node->psql(
+ 'foobar2',
+ 'CREATE ROLE role_foobar;
+CREATE TABLE tab_foobar (id int);
+ALTER TABLE tab_foobar owner to role_foobar;');
+$node->issues_sql_like(
+ [ 'createdb', '-l', 'C', '-T', 'foobar2', 'foobar3' ],
+ qr/statement: CREATE DATABASE foobar3 TEMPLATE foobar2/,
+ 'create database with template');
+($ret, $stdout, $stderr) = $node->psql(
+ 'foobar3',
+ "SELECT pg_describe_object(classid, objid, objsubid) AS obj,
+ pg_describe_object(refclassid, refobjid, 0) AS refobj
+ FROM pg_shdepend s JOIN pg_database d ON (d.oid = s.dbid)
+ WHERE d.datname = 'foobar3';", on_error_die => 1);
+chomp($stdout);
+like(
+ $stdout,
+ qr/^tab_foobar|role role_foobar$/,
+ 'shared dependencies copied over to target database');
+
# Check quote handling with incorrect option values.
$node->command_checks_all(
[ 'createdb', '--encoding', "foo'; SELECT '1", 'foobar2' ],
signature.asc
Description: PGP signature
