Is it recommended to install extensions into pg_catalog schema?
Since objects in pg_catalog
schema are implicitly in the search_path
(docs), would it be recommended to install extensions in that schema?
postgresql postgresql-9.4 best-practices postgresql-extensions
add a comment |
Since objects in pg_catalog
schema are implicitly in the search_path
(docs), would it be recommended to install extensions in that schema?
postgresql postgresql-9.4 best-practices postgresql-extensions
add a comment |
Since objects in pg_catalog
schema are implicitly in the search_path
(docs), would it be recommended to install extensions in that schema?
postgresql postgresql-9.4 best-practices postgresql-extensions
Since objects in pg_catalog
schema are implicitly in the search_path
(docs), would it be recommended to install extensions in that schema?
postgresql postgresql-9.4 best-practices postgresql-extensions
postgresql postgresql-9.4 best-practices postgresql-extensions
edited Sep 28 '16 at 12:40
Erwin Brandstetter
93.7k9181294
93.7k9181294
asked Jul 17 '15 at 18:37
zam6akzam6ak
219211
219211
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Don't install extensions to pg_catalog
(unless that's their default: very few extensions are designed that way), because you don't mess with system catalog, ever. @Chris demonstrates one reason why. There are others.
However, the "public" schema is in no way special. It's just the default schema that's pre-installed in standard distributions so we can get started right away. Some DB admins don't use the "public" schema at all, some even delete it.
CREATE EXTENSION
is not affiliated to the "public" schema. It installs into the current schema unless instructed otherwise - except some extensions have a pre-set schema (like PGQ / Londiste). The documentation:
schema_name
The name of the schema in which to install the extension's objects,
given that the extension allows its contents to be relocated. The
named schema must already exist. If not specified, and the extension's
control file does not specify a schema either, the current default
object creation schema is used.
Remember that the extension itself is not considered to be within any
schema: extensions have unqualified names that must be unique
database-wide. But objects belonging to the extension can be within schemas.
Bold emphasis mine.
Decide how to manage users, schemas and the search_path
:
- How does the search_path influence identifier resolution and the “current schema”
Then decide where to install extensions. You can install to any schema of your choice and include that schema in the default search_path
for all users or just for some or no users at all (so that qualified references are required). It all depends on what you want to achieve.
Whatever you do, stay consistent.
I like to install extensions (that allow it) in a dedicated "extensions" schema, which I include in the default search_path
after "public" (and "$user" - if you use that). Helps with a clean separation of my own public functions and other public objects. My setting in postgresql.conf
:
search_path = "$user",public,extensions
Or:
search_path = public,extensions
And I install extensions with:
CREATE EXTENSION some_extension SCHEMA extensions;
One thing to note: This way you can "hide" (unqualified) objects in the extensions
schema behind objects of the same name (and parameters) in the public
schema.
Related:
- Best way to install hstore on multiple schemas in a Postgres database?
- How can I fake inet_client_addr() for unit tests in PostgreSQL?
ok isplpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog
– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
plv8 installs itself topg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?
– jpmc26
Jun 23 '16 at 17:07
add a comment |
Installing extensions into pg_catalog
are, as far as I'm aware, not advised. You should use the default public
schema, which is also in the search_path
by default.
Why?
As an example, I will work with the pageinspect
extension which I've already created within the public
schema. All functions are, by default, accessible to all schemas in the database if they are located in the public
schema.
Now, I try moving it to the pg_catalog
schema, using
ALTER EXTENSION pageinspect SET SCHEMA pg_catalog;
and it works just fine.
But...
Try to move it again, back to the public
schema using
ALTER EXTENSION pageinspect SET SCHEMA public;
and it won't permit it, yielding the following error
ERROR: cannot remove dependency on schema pg_catalog because it is a system object
SQL state: 0A000
Uh oh! Well, that's OK that it won't let me move it. I can just get it back into the public
schema by dropping it and re-creating, right?...
DROP EXTENSION pageinspect;
CREATE EXTENSION pageinspect;
OK, good. Back in it's right place in the public
schema, and the functions are still accessible to all schemas in the database.
TL,DR; Just use the default public
schema for extensions.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f107389%2fis-it-recommended-to-install-extensions-into-pg-catalog-schema%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Don't install extensions to pg_catalog
(unless that's their default: very few extensions are designed that way), because you don't mess with system catalog, ever. @Chris demonstrates one reason why. There are others.
However, the "public" schema is in no way special. It's just the default schema that's pre-installed in standard distributions so we can get started right away. Some DB admins don't use the "public" schema at all, some even delete it.
CREATE EXTENSION
is not affiliated to the "public" schema. It installs into the current schema unless instructed otherwise - except some extensions have a pre-set schema (like PGQ / Londiste). The documentation:
schema_name
The name of the schema in which to install the extension's objects,
given that the extension allows its contents to be relocated. The
named schema must already exist. If not specified, and the extension's
control file does not specify a schema either, the current default
object creation schema is used.
Remember that the extension itself is not considered to be within any
schema: extensions have unqualified names that must be unique
database-wide. But objects belonging to the extension can be within schemas.
Bold emphasis mine.
Decide how to manage users, schemas and the search_path
:
- How does the search_path influence identifier resolution and the “current schema”
Then decide where to install extensions. You can install to any schema of your choice and include that schema in the default search_path
for all users or just for some or no users at all (so that qualified references are required). It all depends on what you want to achieve.
Whatever you do, stay consistent.
I like to install extensions (that allow it) in a dedicated "extensions" schema, which I include in the default search_path
after "public" (and "$user" - if you use that). Helps with a clean separation of my own public functions and other public objects. My setting in postgresql.conf
:
search_path = "$user",public,extensions
Or:
search_path = public,extensions
And I install extensions with:
CREATE EXTENSION some_extension SCHEMA extensions;
One thing to note: This way you can "hide" (unqualified) objects in the extensions
schema behind objects of the same name (and parameters) in the public
schema.
Related:
- Best way to install hstore on multiple schemas in a Postgres database?
- How can I fake inet_client_addr() for unit tests in PostgreSQL?
ok isplpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog
– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
plv8 installs itself topg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?
– jpmc26
Jun 23 '16 at 17:07
add a comment |
Don't install extensions to pg_catalog
(unless that's their default: very few extensions are designed that way), because you don't mess with system catalog, ever. @Chris demonstrates one reason why. There are others.
However, the "public" schema is in no way special. It's just the default schema that's pre-installed in standard distributions so we can get started right away. Some DB admins don't use the "public" schema at all, some even delete it.
CREATE EXTENSION
is not affiliated to the "public" schema. It installs into the current schema unless instructed otherwise - except some extensions have a pre-set schema (like PGQ / Londiste). The documentation:
schema_name
The name of the schema in which to install the extension's objects,
given that the extension allows its contents to be relocated. The
named schema must already exist. If not specified, and the extension's
control file does not specify a schema either, the current default
object creation schema is used.
Remember that the extension itself is not considered to be within any
schema: extensions have unqualified names that must be unique
database-wide. But objects belonging to the extension can be within schemas.
Bold emphasis mine.
Decide how to manage users, schemas and the search_path
:
- How does the search_path influence identifier resolution and the “current schema”
Then decide where to install extensions. You can install to any schema of your choice and include that schema in the default search_path
for all users or just for some or no users at all (so that qualified references are required). It all depends on what you want to achieve.
Whatever you do, stay consistent.
I like to install extensions (that allow it) in a dedicated "extensions" schema, which I include in the default search_path
after "public" (and "$user" - if you use that). Helps with a clean separation of my own public functions and other public objects. My setting in postgresql.conf
:
search_path = "$user",public,extensions
Or:
search_path = public,extensions
And I install extensions with:
CREATE EXTENSION some_extension SCHEMA extensions;
One thing to note: This way you can "hide" (unqualified) objects in the extensions
schema behind objects of the same name (and parameters) in the public
schema.
Related:
- Best way to install hstore on multiple schemas in a Postgres database?
- How can I fake inet_client_addr() for unit tests in PostgreSQL?
ok isplpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog
– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
plv8 installs itself topg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?
– jpmc26
Jun 23 '16 at 17:07
add a comment |
Don't install extensions to pg_catalog
(unless that's their default: very few extensions are designed that way), because you don't mess with system catalog, ever. @Chris demonstrates one reason why. There are others.
However, the "public" schema is in no way special. It's just the default schema that's pre-installed in standard distributions so we can get started right away. Some DB admins don't use the "public" schema at all, some even delete it.
CREATE EXTENSION
is not affiliated to the "public" schema. It installs into the current schema unless instructed otherwise - except some extensions have a pre-set schema (like PGQ / Londiste). The documentation:
schema_name
The name of the schema in which to install the extension's objects,
given that the extension allows its contents to be relocated. The
named schema must already exist. If not specified, and the extension's
control file does not specify a schema either, the current default
object creation schema is used.
Remember that the extension itself is not considered to be within any
schema: extensions have unqualified names that must be unique
database-wide. But objects belonging to the extension can be within schemas.
Bold emphasis mine.
Decide how to manage users, schemas and the search_path
:
- How does the search_path influence identifier resolution and the “current schema”
Then decide where to install extensions. You can install to any schema of your choice and include that schema in the default search_path
for all users or just for some or no users at all (so that qualified references are required). It all depends on what you want to achieve.
Whatever you do, stay consistent.
I like to install extensions (that allow it) in a dedicated "extensions" schema, which I include in the default search_path
after "public" (and "$user" - if you use that). Helps with a clean separation of my own public functions and other public objects. My setting in postgresql.conf
:
search_path = "$user",public,extensions
Or:
search_path = public,extensions
And I install extensions with:
CREATE EXTENSION some_extension SCHEMA extensions;
One thing to note: This way you can "hide" (unqualified) objects in the extensions
schema behind objects of the same name (and parameters) in the public
schema.
Related:
- Best way to install hstore on multiple schemas in a Postgres database?
- How can I fake inet_client_addr() for unit tests in PostgreSQL?
Don't install extensions to pg_catalog
(unless that's their default: very few extensions are designed that way), because you don't mess with system catalog, ever. @Chris demonstrates one reason why. There are others.
However, the "public" schema is in no way special. It's just the default schema that's pre-installed in standard distributions so we can get started right away. Some DB admins don't use the "public" schema at all, some even delete it.
CREATE EXTENSION
is not affiliated to the "public" schema. It installs into the current schema unless instructed otherwise - except some extensions have a pre-set schema (like PGQ / Londiste). The documentation:
schema_name
The name of the schema in which to install the extension's objects,
given that the extension allows its contents to be relocated. The
named schema must already exist. If not specified, and the extension's
control file does not specify a schema either, the current default
object creation schema is used.
Remember that the extension itself is not considered to be within any
schema: extensions have unqualified names that must be unique
database-wide. But objects belonging to the extension can be within schemas.
Bold emphasis mine.
Decide how to manage users, schemas and the search_path
:
- How does the search_path influence identifier resolution and the “current schema”
Then decide where to install extensions. You can install to any schema of your choice and include that schema in the default search_path
for all users or just for some or no users at all (so that qualified references are required). It all depends on what you want to achieve.
Whatever you do, stay consistent.
I like to install extensions (that allow it) in a dedicated "extensions" schema, which I include in the default search_path
after "public" (and "$user" - if you use that). Helps with a clean separation of my own public functions and other public objects. My setting in postgresql.conf
:
search_path = "$user",public,extensions
Or:
search_path = public,extensions
And I install extensions with:
CREATE EXTENSION some_extension SCHEMA extensions;
One thing to note: This way you can "hide" (unqualified) objects in the extensions
schema behind objects of the same name (and parameters) in the public
schema.
Related:
- Best way to install hstore on multiple schemas in a Postgres database?
- How can I fake inet_client_addr() for unit tests in PostgreSQL?
edited 1 min ago
answered Jul 18 '15 at 2:01
Erwin BrandstetterErwin Brandstetter
93.7k9181294
93.7k9181294
ok isplpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog
– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
plv8 installs itself topg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?
– jpmc26
Jun 23 '16 at 17:07
add a comment |
ok isplpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog
– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
plv8 installs itself topg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?
– jpmc26
Jun 23 '16 at 17:07
ok is
plpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog– zam6ak
Jul 20 '15 at 13:18
ok is
plpgsql
extension then somehow an exception to this rule? Every install I have seen has this extension in pg_catalog– zam6ak
Jul 20 '15 at 13:18
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:
In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
@zam6ak: Yes, plpgsql is a bit of a special case: Quoting the manual:
In PostgreSQL 9.0 and later, PL/pgSQL is installed by default. However it is still a loadable module, so especially security-conscious administrators could choose to remove it.
– Erwin Brandstetter
Jul 20 '15 at 13:40
1
1
plv8 installs itself to
pg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?– jpmc26
Jun 23 '16 at 17:07
plv8 installs itself to
pg_catalog
, too. (It throws an error if you try to change it.) Is this maybe a standard for installing procedural language extensions for functions?– jpmc26
Jun 23 '16 at 17:07
add a comment |
Installing extensions into pg_catalog
are, as far as I'm aware, not advised. You should use the default public
schema, which is also in the search_path
by default.
Why?
As an example, I will work with the pageinspect
extension which I've already created within the public
schema. All functions are, by default, accessible to all schemas in the database if they are located in the public
schema.
Now, I try moving it to the pg_catalog
schema, using
ALTER EXTENSION pageinspect SET SCHEMA pg_catalog;
and it works just fine.
But...
Try to move it again, back to the public
schema using
ALTER EXTENSION pageinspect SET SCHEMA public;
and it won't permit it, yielding the following error
ERROR: cannot remove dependency on schema pg_catalog because it is a system object
SQL state: 0A000
Uh oh! Well, that's OK that it won't let me move it. I can just get it back into the public
schema by dropping it and re-creating, right?...
DROP EXTENSION pageinspect;
CREATE EXTENSION pageinspect;
OK, good. Back in it's right place in the public
schema, and the functions are still accessible to all schemas in the database.
TL,DR; Just use the default public
schema for extensions.
add a comment |
Installing extensions into pg_catalog
are, as far as I'm aware, not advised. You should use the default public
schema, which is also in the search_path
by default.
Why?
As an example, I will work with the pageinspect
extension which I've already created within the public
schema. All functions are, by default, accessible to all schemas in the database if they are located in the public
schema.
Now, I try moving it to the pg_catalog
schema, using
ALTER EXTENSION pageinspect SET SCHEMA pg_catalog;
and it works just fine.
But...
Try to move it again, back to the public
schema using
ALTER EXTENSION pageinspect SET SCHEMA public;
and it won't permit it, yielding the following error
ERROR: cannot remove dependency on schema pg_catalog because it is a system object
SQL state: 0A000
Uh oh! Well, that's OK that it won't let me move it. I can just get it back into the public
schema by dropping it and re-creating, right?...
DROP EXTENSION pageinspect;
CREATE EXTENSION pageinspect;
OK, good. Back in it's right place in the public
schema, and the functions are still accessible to all schemas in the database.
TL,DR; Just use the default public
schema for extensions.
add a comment |
Installing extensions into pg_catalog
are, as far as I'm aware, not advised. You should use the default public
schema, which is also in the search_path
by default.
Why?
As an example, I will work with the pageinspect
extension which I've already created within the public
schema. All functions are, by default, accessible to all schemas in the database if they are located in the public
schema.
Now, I try moving it to the pg_catalog
schema, using
ALTER EXTENSION pageinspect SET SCHEMA pg_catalog;
and it works just fine.
But...
Try to move it again, back to the public
schema using
ALTER EXTENSION pageinspect SET SCHEMA public;
and it won't permit it, yielding the following error
ERROR: cannot remove dependency on schema pg_catalog because it is a system object
SQL state: 0A000
Uh oh! Well, that's OK that it won't let me move it. I can just get it back into the public
schema by dropping it and re-creating, right?...
DROP EXTENSION pageinspect;
CREATE EXTENSION pageinspect;
OK, good. Back in it's right place in the public
schema, and the functions are still accessible to all schemas in the database.
TL,DR; Just use the default public
schema for extensions.
Installing extensions into pg_catalog
are, as far as I'm aware, not advised. You should use the default public
schema, which is also in the search_path
by default.
Why?
As an example, I will work with the pageinspect
extension which I've already created within the public
schema. All functions are, by default, accessible to all schemas in the database if they are located in the public
schema.
Now, I try moving it to the pg_catalog
schema, using
ALTER EXTENSION pageinspect SET SCHEMA pg_catalog;
and it works just fine.
But...
Try to move it again, back to the public
schema using
ALTER EXTENSION pageinspect SET SCHEMA public;
and it won't permit it, yielding the following error
ERROR: cannot remove dependency on schema pg_catalog because it is a system object
SQL state: 0A000
Uh oh! Well, that's OK that it won't let me move it. I can just get it back into the public
schema by dropping it and re-creating, right?...
DROP EXTENSION pageinspect;
CREATE EXTENSION pageinspect;
OK, good. Back in it's right place in the public
schema, and the functions are still accessible to all schemas in the database.
TL,DR; Just use the default public
schema for extensions.
answered Jul 17 '15 at 21:27
ChrisChris
1,999917
1,999917
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f107389%2fis-it-recommended-to-install-extensions-into-pg-catalog-schema%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown