pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_dump dependency loop with extension containing its own schema
6+ messages / 2 participants
[nested] [flat]

* pg_dump dependency loop with extension containing its own schema
@ 2012-08-11 22:55  Thom Brown <thom@linux.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Thom Brown @ 2012-08-11 22:55 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

I'm getting a dependency loop issue with pg_dump when adding a schema
to an extension where the schema being added is the same as the one
containing the extension.

CREATE EXTENSION file_fdw;
ALTER EXTENSION file_fdw ADD SCHEMA public;

$ pg_dump -f /dev/null test
pg_dump: [sorter] WARNING: could not resolve dependency loop among these items:
pg_dump: [sorter]   SCHEMA public  (ID 5 OID 2200)
pg_dump: [sorter]   EXTENSION file_fdw  (ID 170 OID 28912)

or

CREATE SCHEMA meow;
CREATE EXTENSION file_fdw WITH SCHEMA meow;
ALTER EXTENSION file_fdw ADD SCHEMA meow;

$ pg_dump -f /dev/null test
pg_dump: [sorter] WARNING: could not resolve dependency loop among these items:
pg_dump: [sorter]   SCHEMA meow  (ID 7 OID 28917)
pg_dump: [sorter]   EXTENSION file_fdw  (ID 171 OID 28918)

but not

CREATE SCHEMA meow;
CREATE EXTENSION file_fdw WITH SCHEMA meow;
ALTER EXTENSION file_fdw ADD SCHEMA public;

$ pg_dump -f /dev/null test3
$
(no errors shown)

I can produce this issue in 9.1.4 and head (as of commit
83af58f6b5657840f5924332fccecca1e3556abe).

Since this is a bug report, I'll include the necessary supporting info:
OS: Linux Mint x64
Kernel: 3.2.0-27-generic
CC version: Linaro 4.6.3-1ubuntu5
RAM: 16GB DDR3

-- 
Thom




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_dump dependency loop with extension containing its own schema
@ 2012-08-12 00:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thom Brown <thom@linux.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2012-08-12 00:06 UTC (permalink / raw)
  To: Thom Brown <thom@linux.com>; +Cc: pgsql-bugs

Thom Brown <thom@linux.com> writes:
> I'm getting a dependency loop issue with pg_dump when adding a schema
> to an extension where the schema being added is the same as the one
> containing the extension.

> CREATE EXTENSION file_fdw;
> ALTER EXTENSION file_fdw ADD SCHEMA public;

ISTM we ought to disallow that ... either the schema is inside the
extension, or vice versa, it's not sensible to say both.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_dump dependency loop with extension containing its own schema
@ 2012-08-12 07:17  Thom Brown <thom@linux.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Thom Brown @ 2012-08-12 07:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 12 August 2012 01:06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Thom Brown <thom@linux.com> writes:
>> I'm getting a dependency loop issue with pg_dump when adding a schema
>> to an extension where the schema being added is the same as the one
>> containing the extension.
>
>> CREATE EXTENSION file_fdw;
>> ALTER EXTENSION file_fdw ADD SCHEMA public;
>
> ISTM we ought to disallow that ... either the schema is inside the
> extension, or vice versa, it's not sensible to say both.

Precisely.

-- 
Thom




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_dump dependency loop with extension containing its own schema
@ 2012-08-15 13:00  Thom Brown <thom@linux.com>
  parent: Thom Brown <thom@linux.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Thom Brown @ 2012-08-15 13:00 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 12 August 2012 08:17, Thom Brown <thom@linux.com> wrote:
> On 12 August 2012 01:06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Thom Brown <thom@linux.com> writes:
>>> I'm getting a dependency loop issue with pg_dump when adding a schema
>>> to an extension where the schema being added is the same as the one
>>> containing the extension.
>>
>>> CREATE EXTENSION file_fdw;
>>> ALTER EXTENSION file_fdw ADD SCHEMA public;
>>
>> ISTM we ought to disallow that ... either the schema is inside the
>> extension, or vice versa, it's not sensible to say both.
>
> Precisely.

Suggested changes attached. (not really confident about it though)

-- 
Thom

Attachments:

extension_schema_dependency_loop.patch (application/octet-stream, 2.3K) download diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index f1948f4..b80f083 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -2192,6 +2192,7 @@ AlterExtensionNamespace(List *names, const char *newschema) Oid extensionOid; Oid nspOid; Oid oldNspOid = InvalidOid; + Oid extensionOfSchema; AclResult aclresult; Relation extRel; ScanKeyData key[2]; @@ -2327,6 +2328,23 @@ AlterExtensionNamespace(List *names, const char *newschema) get_namespace_name(oldNspOid)))); } + /* + * If the schema is a member of the extension, disallow moving the extension + * into that schema. This would otherwise cause a dependency loop. + */ + extensionOfSchema = getExtensionOfObject(NamespaceRelationId, nspOid); + + if(OidIsValid(extensionOfSchema)) + { + if(extensionOfSchema == extensionOid) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + + errmsg("cannot move extension \"%s\" to schema \"%s\" as the extension contains the schema", + NameStr(extForm->extname), + get_namespace_name(nspOid)))); + } + systable_endscan(depScan); relation_close(depRel, AccessShareLock); @@ -2649,6 +2667,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) ObjectAddress object; Relation relation; Oid oldExtension; + Oid extensionSchemaOid; extension.classId = ExtensionRelationId; extension.objectId = get_extension_oid(stmt->extname, false); @@ -2690,6 +2709,22 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) get_extension_name(oldExtension)))); /* + * Prevent schemas being added to an extension if that schema contains + * the extension. This would otherwise cause a dependency loop. + */ + if(stmt->objtype == OBJECT_SCHEMA) + { + extensionSchemaOid = get_extension_schema(extension.objectId); + + if(extensionSchemaOid == object.objectId) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("cannot add schema \"%s\" to extension \"%s\" as the schema contains the extension", + get_namespace_name(object.objectId), + get_extension_name(extension.objectId)))); + } + + /* * OK, add the dependency. */ recordDependencyOn(&object, &extension, DEPENDENCY_EXTENSION);
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: pg_dump dependency loop with extension containing its own schema
@ 2012-08-15 15:30  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thom Brown <thom@linux.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2012-08-15 15:30 UTC (permalink / raw)
  To: Thom Brown <thom@linux.com>; +Cc: pgsql-bugs

Thom Brown <thom@linux.com> writes:
> On 12 August 2012 08:17, Thom Brown <thom@linux.com> wrote:
>> On 12 August 2012 01:06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> ISTM we ought to disallow that ... either the schema is inside the
>>> extension, or vice versa, it's not sensible to say both.

>> Precisely.

> Suggested changes attached. (not really confident about it though)

Applied with minor editorialization.  Thanks!

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_dump dependency loop with extension containing its own schema
@ 2012-08-15 15:51  Thom Brown <thom@linux.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Thom Brown @ 2012-08-15 15:51 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 15 August 2012 16:30, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Thom Brown <thom@linux.com> writes:
>> On 12 August 2012 08:17, Thom Brown <thom@linux.com> wrote:
>>> On 12 August 2012 01:06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> ISTM we ought to disallow that ... either the schema is inside the
>>>> extension, or vice versa, it's not sensible to say both.
>
>>> Precisely.
>
>> Suggested changes attached. (not really confident about it though)
>
> Applied with minor editorialization.  Thanks!

Cheers Tom.

-- 
Thom




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2012-08-15 15:51 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-08-11 22:55 pg_dump dependency loop with extension containing its own schema Thom Brown <thom@linux.com>
2012-08-12 00:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-08-12 07:17   ` Thom Brown <thom@linux.com>
2012-08-15 13:00     ` Thom Brown <thom@linux.com>
2012-08-15 15:30       ` Tom Lane <tgl@sss.pgh.pa.us>
2012-08-15 15:51         ` Thom Brown <thom@linux.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox