Thread: TODO item: Allow more complex user/database default GUC settings

TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Hi,

There's a longstanding TODO item, in subject.  Previous discussion was
here:

http://archives.postgresql.org/pgsql-hackers/2006-09/msg02341.php

In looking what it would take to implement it, I find that it is
trivial.  The only part that looks complex is the UI for it.  Is anyone
interested in giving this patch a shot?

Implementation-side, it requires a new catalog (pg_settings), with the
following columns:

setdatabase    oid
setrole        oid
setconfig    text[]

datconfig and rolconfig are removed.

ALTER DATABASE / SET sets setdatabase to the OID of the database in
command, and setrole to 0 (InvalidOid); ALTER ROLE / SET sets setrole
and leaves setdatabase 0.

A new command allows one to set a config that applies to both database
and role.

At startup, the settings are applied in the following order:
database=value    role=0
database=0    role=value
database=value    role=value

This way, current behavior is maintained (ALTER ROLE trumps ALTER
DATABASE).

The only real work in this is figuring out what the grammar for the new
command looks like.  Maybe we could have some like

ALTER ROLE foo ALTER DATABASE bar SET config

There are of course many possible variations but this looks the most
reasonable one.  Any better ideas?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Alvaro Herrera wrote:

> Implementation-side, it requires a new catalog (pg_settings), with the
> following columns:

So, I've come up with the attached patch.  It does not have the new
command yet, so you can do ALTER USER and ALTER DATABASE and it works,
but there's no way to set user-and-database-specific settings, short of
INSERT into the catalog.  Apart from that it works nicely.

I'm just posting in case somebody has thoughts on the UI part of it.

Other things that need fixed:

- need to figure out locking for roles; this stuff must be synchronized
  with role drop
- pg_shadow and pg_roles need a join to obtain settings
- two regression tests need their expected file updated
- catalog version bump

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 25. August 2009 22:17:38 -0400 Alvaro Herrera
<alvherre@commandprompt.com> wrote:

> I'm just posting in case somebody has thoughts on the UI part of it.
>
> Other things that need fixed:
>
> - need to figure out locking for roles; this stuff must be synchronized
>   with role drop
> - pg_shadow and pg_roles need a join to obtain settings
> - two regression tests need their expected file updated
> - catalog version bump

Here's a first shot on this for my current review round. Patch needed to
re-merged into current CVS HEAD due to some merge conflicts, i've also
adjusted the regression tests (minor). On a first look, i like the patch
(especially the code for the utility commands accessing the settings is
better modularized now, which looks much nicer).

--
Thanks

    Bernd
Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Fri, Sep 18, 2009 at 4:03 PM, Bernd Helmle <mailings@oopsware.de> wrote:
>
>
> --On 25. August 2009 22:17:38 -0400 Alvaro Herrera
> <alvherre@commandprompt.com> wrote:
>
>> I'm just posting in case somebody has thoughts on the UI part of it.
>>
>> Other things that need fixed:
>>
>> - need to figure out locking for roles; this stuff must be synchronized
>>  with role drop
>> - pg_shadow and pg_roles need a join to obtain settings
>> - two regression tests need their expected file updated
>> - catalog version bump
>
> Here's a first shot on this for my current review round. Patch needed to
> re-merged into current CVS HEAD due to some merge conflicts, i've also
> adjusted the regression tests (minor). On a first look, i like the patch
> (especially the code for the utility commands accessing the settings is
> better modularized now, which looks much nicer).

So is this ready to commit, or what?

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Robert Haas escribió:

> > Here's a first shot on this for my current review round. Patch needed to
> > re-merged into current CVS HEAD due to some merge conflicts, i've also
> > adjusted the regression tests (minor). On a first look, i like the patch
> > (especially the code for the utility commands accessing the settings is
> > better modularized now, which looks much nicer).
> 
> So is this ready to commit, or what?

Not really :-(  It needs some minor tweaks to qualify as a cleanup
patch, and further extra coding for there to be an actual new feature.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 20. September 2009 22:56:53 -0400 Robert Haas <robertmhaas@gmail.com> 
wrote:

> So is this ready to commit, or what?

Not yet, see the comments Alvaro did upthread. Please note that i'm still 
reviewing this one and i hope to post results tomorrow (there wasn't plenty 
of free time over the weekend, i'm sorry).

-- 
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Mon, Sep 21, 2009 at 12:21 AM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Robert Haas escribió:
>
>> > Here's a first shot on this for my current review round. Patch needed to
>> > re-merged into current CVS HEAD due to some merge conflicts, i've also
>> > adjusted the regression tests (minor). On a first look, i like the patch
>> > (especially the code for the utility commands accessing the settings is
>> > better modularized now, which looks much nicer).
>>
>> So is this ready to commit, or what?
>
> Not really :-(  It needs some minor tweaks to qualify as a cleanup
> patch, and further extra coding for there to be an actual new feature.

So here's the followup question - do you intend to do one of those
things for this CommitFest, or should we mark this as Returned with
Feedback once Bernd posts the rest of his review?

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Robert Haas escribió:

> So here's the followup question - do you intend to do one of those
> things for this CommitFest, or should we mark this as Returned with
> Feedback once Bernd posts the rest of his review?

What feedback is it supposed to be returned with?  Precisely what I
wanted is some feedback on the general idea.  Brendan's "I like the
approach" is good, but is it enough to deter a later veto from someone
else?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Alvaro Herrera escribió:

> What feedback is it supposed to be returned with?  Precisely what I
> wanted is some feedback on the general idea.  Brendan's "I like the
> approach" is good, but is it enough to deter a later veto from someone
> else?

s/Brendan/Bernd/

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 21. September 2009 13:42:21 +0200 Bernd Helmle <mailings@oopsware.de> 
wrote:

>
>
> --On 20. September 2009 22:56:53 -0400 Robert Haas
> <robertmhaas@gmail.com> wrote:
>
>> So is this ready to commit, or what?
>
> Not yet, see the comments Alvaro did upthread. Please note that i'm still
> reviewing this one and i hope to post results tomorrow (there wasn't
> plenty of free time over the weekend, i'm sorry).
>

Here some further comments on the current patch:

- I'm not sure i like the name of the new system catalog pg_setting. Wie 
already have pg_settings, i think this can be confusing. Maybe we need a 
different name, e.g. pg_user_setting? This seems along the line with the 
other *user* system objects (e.g. pg_stat_user_tables), where only "user 
specific" objects are displayed.

- I have thought a little bit about the changes in the system views. 
pg_roles and pg_shadow (as Alvaro already mentioned), need to be adjusted 
(joined to the new catalog), to display rolconfig/useconfig. However, it's 
unclear *how* to expose those information, for example, do we want to 
expose roleconfig specific for the current database or for all databases 
the role has a specific config for ?

- The code mentions the lack of lock synchronization. Maybe i'm missing 
something obvious (its late here), but is there a reason this can't be done 
by obtaining a lock on pg_authid (not sure about the backend user 
initialization phase though) ?

- Regarding the missing UI: i go with Alvaro's proposal:

ALTER ROLE <rolename> [ALTER] DATABASE <dbname> SET <config> TO <value>;

Maybe we can make the 2nd ALTER optional.

Thoughts?


-- 
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Mon, Sep 21, 2009 at 12:23 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Robert Haas escribió:
>
>> So here's the followup question - do you intend to do one of those
>> things for this CommitFest, or should we mark this as Returned with
>> Feedback once Bernd posts the rest of his review?
>
> What feedback is it supposed to be returned with?  Precisely what I
> wanted is some feedback on the general idea.  Brendan's "I like the
> approach" is good, but is it enough to deter a later veto from someone
> else?

Well, you've hit there on one of the things that we don't always do
well.  Many a patch author has posted an idea, received no feedback,
proceeded to implementation, and then the knives come out.  On a good
day, the CommitFest process ensures that every patch gets a second
opinion, but it doesn't guarantee that a third opinion won't come
crawling out of the woodwork at a later date.  In this respect, you're
actually operating at a slight advantage relative to most of us,
because you can post your revised patch and commit it if no one
objects too strongly, whereas I (for example) have to convince one of
about two people - Tom or Peter, for nearly anything I'm likely to
develop - to take an affirmative action on my behalf.

This whole phenomenon of proposals to which no objection was made at
the outset later getting flak for one reason or another is, I think, a
source of much frustration and discourages people from putting effort
into projects they might otherwise be willing to undertake.  But I
haven't the least idea how to fix it, and I can't offer you any
guarantees with respect to the present situation either.

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Gurjeet Singh
Date:
On Tue, Sep 22, 2009 at 4:16 AM, Bernd Helmle <mailings@oopsware.de> wrote:


--On 21. September 2009 13:42:21 +0200 Bernd Helmle <mailings@oopsware.de> wrote:



--On 20. September 2009 22:56:53 -0400 Robert Haas
<robertmhaas@gmail.com> wrote:

So is this ready to commit, or what?

Not yet, see the comments Alvaro did upthread. Please note that i'm still
reviewing this one and i hope to post results tomorrow (there wasn't
plenty of free time over the weekend, i'm sorry).


Here some further comments on the current patch:

- I'm not sure i like the name of the new system catalog pg_setting. Wie already have pg_settings, i think this can be confusing. Maybe we need a different name, e.g. pg_user_setting? This seems along the line with the other *user* system objects (e.g. pg_stat_user_tables), where only "user specific" objects are displayed.

- I have thought a little bit about the changes in the system views. pg_roles and pg_shadow (as Alvaro already mentioned), need to be adjusted (joined to the new catalog), to display rolconfig/useconfig. However, it's unclear *how* to expose those information, for example, do we want to expose roleconfig specific for the current database or for all databases the role has a specific config for ?

- The code mentions the lack of lock synchronization. Maybe i'm missing something obvious (its late here), but is there a reason this can't be done by obtaining a lock on pg_authid (not sure about the backend user initialization phase though) ?

- Regarding the missing UI: i go with Alvaro's proposal:

ALTER ROLE <rolename> [ALTER] DATABASE <dbname> SET <config> TO <value>;

Maybe we can make the 2nd ALTER optional.

Thoughts?

ON instead of second ALTER looks better, and IMHO DATABASE <dbname> should be optional too:

ALTER ROLE <rolename> [ON DATABASE <dbname>] SET <config> TO <value>;

Best regards,
--
Lets call it Postgres

EnterpriseDB      http://www.enterprisedb.com

gurjeet[.singh]@EnterpriseDB.com

singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
Twitter: singh_gurjeet
Skype: singh_gurjeet

Mail sent from my BlackLaptop device

Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Gurjeet Singh <singh.gurjeet@gmail.com> writes:
> ON instead of second ALTER looks better, and IMHO DATABASE <dbname> should
> be optional too:

> ALTER ROLE <rolename> [ON DATABASE <dbname>] SET <config> TO <value>;

IN, not ON.
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Robert Haas escribi�:
>> So here's the followup question - do you intend to do one of those
>> things for this CommitFest, or should we mark this as Returned with
>> Feedback once Bernd posts the rest of his review?

> What feedback is it supposed to be returned with?  Precisely what I
> wanted is some feedback on the general idea.  Brendan's "I like the
> approach" is good, but is it enough to deter a later veto from someone
> else?

FWIW, I looked the patch over quickly, and I think it will be fine once
Bernd's comments are addressed.  In particular I agree with the
objection to the name "pg_setting" as being confusingly close to
"pg_settings".  But "pg_user_setting" isn't better.  Maybe
"pg_db_role_settings"?

As far as the lock issue goes, I don't see any reason why the catalog
change creates a reason for new/different locking than we had before.
Any attempt to make concurrent updates to the same row will generate an
error, and that seems enough to me ...
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 23. September 2009 14:10:39 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote:

> FWIW, I looked the patch over quickly, and I think it will be fine once
> Bernd's comments are addressed.  In particular I agree with the
> objection to the name "pg_setting" as being confusingly close to
> "pg_settings".  But "pg_user_setting" isn't better.  Maybe
> "pg_db_role_settings"?

Jepp, that's better, +1 from me.

I'm done with this, too, so i will mark this as "Returned with Feedback", 
if no one objects?

-- 
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Wed, Sep 23, 2009 at 3:03 PM, Bernd Helmle <mailings@oopsware.de> wrote:
>
>
> --On 23. September 2009 14:10:39 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>> FWIW, I looked the patch over quickly, and I think it will be fine once
>> Bernd's comments are addressed.  In particular I agree with the
>> objection to the name "pg_setting" as being confusingly close to
>> "pg_settings".  But "pg_user_setting" isn't better.  Maybe
>> "pg_db_role_settings"?
>
> Jepp, that's better, +1 from me.
>
> I'm done with this, too, so i will mark this as "Returned with Feedback", if
> no one objects?

It can be marked "Waiting on Author" if it's going to be reworked in
the next few days.  If no plans to rework, or if the rework doesn't
materialize, then "Returned with Feedback".

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Tom Lane escribió:
> Gurjeet Singh <singh.gurjeet@gmail.com> writes:
> > ON instead of second ALTER looks better, and IMHO DATABASE <dbname> should
> > be optional too:
> 
> > ALTER ROLE <rolename> [ON DATABASE <dbname>] SET <config> TO <value>;
> 
> IN, not ON.

This creates a parser conflict with
CREATE ROLE foo IN ROLE bar

I think it can be solved by splitting OptRoleElem in a set of
productions for ALTER and a superset of that for ALTER.  I'll go try
that.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Alvaro Herrera escribió:

> I think it can be solved by splitting OptRoleElem in a set of
> productions for ALTER and a superset of that for ALTER.  I'll go try
> that.

Right, that works.  Updated patch attached; should solve the issues
raised in the thread.  I renamed the catalog pg_db_role_setting as
suggested by Tom.

I have updated the pg_user and pg_roles definitions so that they include
the settings for the role, but only those that are not specific to any
database.

I have also added a view, whose only purpose is to convert the role and
database OIDs into names.  It's been named pg_db_role_settings, but if
anyone has a better suggestion I'm all ears.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Right, that works.  Updated patch attached; should solve the issues
> raised in the thread.  I renamed the catalog pg_db_role_setting as
> suggested by Tom.
> ...
> I have also added a view, whose only purpose is to convert the role and
> database OIDs into names.  It's been named pg_db_role_settings, but if
> anyone has a better suggestion I'm all ears.

I dislike the idea of having a catalog and a view whose names are the
same except for a plural.  It's confusing as heck, because no one will
remember which is which.

Since pg_settings is the existing user view, I think pg_db_role_settings
is a reasonable choice for the new view, but then we need a different
name for the catalog.  The only thing that comes to mind right now is
"pg_db_role_default", but I don't like it much.  Anybody have other
suggestions?
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Sep 26, 2009, at 11:59 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Alvaro Herrera <alvherre@commandprompt.com> writes:
>> Right, that works.  Updated patch attached; should solve the issues
>> raised in the thread.  I renamed the catalog pg_db_role_setting as
>> suggested by Tom.
>> ...
>> I have also added a view, whose only purpose is to convert the role  
>> and
>> database OIDs into names.  It's been named pg_db_role_settings, but  
>> if
>> anyone has a better suggestion I'm all ears.
>
> I dislike the idea of having a catalog and a view whose names are the
> same except for a plural.  It's confusing as heck, because no one will
> remember which is which.
>
> Since pg_settings is the existing user view, I think  
> pg_db_role_settings
> is a reasonable choice for the new view, but then we need a different
> name for the catalog.  The only thing that comes to mind right now is
> "pg_db_role_default", but I don't like it much.  Anybody have other
> suggestions?

The problem of having both a table and a closely related view is, IME,  
one that comes up a lot. I think you just need to pick a convention  
and stick with it.  Mine is to append "_view" to the table name.

Renaming the underlying table doesn't seem like it helps at all.

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Robert Haas escribió:

> The problem of having both a table and a closely related view is,
> IME, one that comes up a lot. I think you just need to pick a
> convention and stick with it.  Mine is to append "_view" to the
> table name.

That would make the difference clear, but since what the user normally
wants to see is the view, it seems a poor solution to make the view the
more difficult one to type (and the one that isn't tab-completed first
in psql).  I'd go with naming the view pg_db_role_setting and append
"_internal" to the catalog or something similar, except that we don't
have any catalog with such a bad name yet and I don't want to start.

Maybe name the table pg_configuration?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Sat, Sep 26, 2009 at 11:44 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Robert Haas escribió:
>
>> The problem of having both a table and a closely related view is,
>> IME, one that comes up a lot. I think you just need to pick a
>> convention and stick with it.  Mine is to append "_view" to the
>> table name.
>
> That would make the difference clear, but since what the user normally
> wants to see is the view, it seems a poor solution to make the view the
> more difficult one to type (and the one that isn't tab-completed first
> in psql).  I'd go with naming the view pg_db_role_setting and append
> "_internal" to the catalog or something similar, except that we don't
> have any catalog with such a bad name yet and I don't want to start.
>
> Maybe name the table pg_configuration?

That seems to me to be just confusing the issue.  Now the table name
and the view name are just totally different with no obvious
connection between them.  We have enough nonsense of this type already
(e.g. pg_stats vs. pg_statistic; pg_authid vs. pg_roles vs.
pg_shadow).  I think we need to settle on a system for handling
problems of this type and document it in the fine manual or perhaps a
README somewhere, and stick with it.  Inventing random unconnected
names is just craziness.

Now, if you/others don't like my _view convention; that's fine.  Just
pick something else.  Really, I don't believe the tab-completion thing
is much of a problem, you just type underscore-tab and you're there.
But I am 100% OK with whatever we pick, as long as it is something
easy to remember that we have a chance of being able to apply
consistently.

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Fri, Sep 25, 2009 at 8:05 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Alvaro Herrera escribió:
>
>> I think it can be solved by splitting OptRoleElem in a set of
>> productions for ALTER and a superset of that for ALTER.  I'll go try
>> that.
>
> Right, that works.  Updated patch attached; should solve the issues
> raised in the thread.  I renamed the catalog pg_db_role_setting as
> suggested by Tom.
>
> I have updated the pg_user and pg_roles definitions so that they include
> the settings for the role, but only those that are not specific to any
> database.
>
> I have also added a view, whose only purpose is to convert the role and
> database OIDs into names.  It's been named pg_db_role_settings, but if
> anyone has a better suggestion I'm all ears.

Bernd,

Can you review this new version and mark this as Ready for Committer
if it looks OK, or else respond with comments and set it back to
Waiting on Author?

Thanks,

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Robert Haas <robertmhaas@gmail.com> writes:
> That seems to me to be just confusing the issue.  Now the table name
> and the view name are just totally different with no obvious
> connection between them.  We have enough nonsense of this type already
> (e.g. pg_stats vs. pg_statistic; pg_authid vs. pg_roles vs.
> pg_shadow).  I think we need to settle on a system for handling
> problems of this type and document it in the fine manual or perhaps a
> README somewhere, and stick with it.  Inventing random unconnected
> names is just craziness.

Actually, to the extent that we have any convention at all, it's
to use plurals for system view names (pg_tables, pg_views, etc)
and singular for underlying catalogs (pg_index).  The only exception
to this on the catalog side is pg_auth_members, which is arguably
misnamed.  (pg_inherits is sort of an exception, but it's weird in a
different way: its name is a verb not a noun.)  The apparent exceptions
on the view side (pg_group, pg_shadow, pg_user) are actually views that
are backward compatible substitutes for former catalogs, so they are not
really intentional exceptions.

Now it's also the case that we've tended to use tech-speak names
for catalogs (eg, pg_class, pg_namespace not pg_table, pg_schema)
and so that gives us an additional degree of separation between
those names and the more user-facing names chosen for views.

What we seem to be lacking in this case is a good tech-speak
option for the underlying catalog name.  I'm still not happy
with having a catalog and a view that are exactly the same
except for "s", especially since as Alvaro notes that won't
lead to desirable tab-completion behavior.  OTOH, we have
survived with pg_index vs pg_indexes, so maybe it wouldn't
kill us.

BTW, have we thought much about the simplest possible solution,
which is to not have the view?  How badly do we need it?  Seems
like dropping the functionality into a psql \d command might be
a viable alternative.
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 27. September 2009 21:59:37 -0400 Robert Haas <robertmhaas@gmail.com>
wrote:

> Bernd,
>
> Can you review this new version and mark this as Ready for Committer
> if it looks OK, or else respond with comments and set it back to
> Waiting on Author?

Seems Alvaro forgot to include pg_db_role_setting.h, it doesn't compile
anymore with this error:

catalog.c:34:40: error: catalog/pg_db_role_setting.h: No such file or
directory
catalog.c: In function ‘IsSharedRelation’:
catalog.c:311: error: ‘DbRoleSettingRelationId’ undeclared (first use
in this function)


--
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
decibel
Date:
On Sep 27, 2009, at 9:19 PM, Tom Lane wrote:
> What we seem to be lacking in this case is a good tech-speak
> option for the underlying catalog name.  I'm still not happy
> with having a catalog and a view that are exactly the same
> except for "s", especially since as Alvaro notes that won't
> lead to desirable tab-completion behavior.  OTOH, we have
> survived with pg_index vs pg_indexes, so maybe it wouldn't
> kill us.


Another option is to revisit the set of system views (http:// 
pgfoundry.org/projects/newsysviews/). IIRC there was some other  
recent reason we wanted to do that.
-- 
Decibel!, aka Jim C. Nasby, Database Architect  decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828




Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Bernd Helmle escribió:

> Seems Alvaro forgot to include pg_db_role_setting.h, it doesn't
> compile anymore with this error:

Huh, you're right, I did :-(  Let me unpack the laptop ...

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Bernd Helmle escribió:

> Seems Alvaro forgot to include pg_db_role_setting.h, it doesn't
> compile anymore with this error:

Here they are.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 28. September 2009 19:02:34 -0400 Alvaro Herrera 
<alvherre@commandprompt.com> wrote:

>> Seems Alvaro forgot to include pg_db_role_setting.h, it doesn't
>> compile anymore with this error:
>
> Here they are.

I'll see if i can get to it tonight. I'm currently travelling, so it could 
be delayed until Thursday.

-- 
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
And here's the last necessary bit, which is pg_dump support for all
this.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> And here's the last necessary bit, which is pg_dump support for all
> this.

> +         /* Dump role/database settings */
> +         if (!tablespaces_only)
> +         {
> +             if (server_version >= 80500)
> +                 dumpDbRoleConfig(conn);
> +         }

Hmm ... I would kind of think that --roles-only should suppress this too.
Otherwise you're going to be dumping commands that might refer to
nonexistent databases.
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Tom Lane escribió:
> Alvaro Herrera <alvherre@commandprompt.com> writes:
> > And here's the last necessary bit, which is pg_dump support for all
> > this.
> 
> > +         /* Dump role/database settings */
> > +         if (!tablespaces_only)
> > +         {
> > +             if (server_version >= 80500)
> > +                 dumpDbRoleConfig(conn);
> > +         }
> 
> Hmm ... I would kind of think that --roles-only should suppress this too.
> Otherwise you're going to be dumping commands that might refer to
> nonexistent databases.

Those double negatives are confusing as hell.  I propose to add
something like this:
   do_tablespaces = true;   do_databases = true;   do_roles = true;   if (globals_only)       do_databases = false;
if(tablespaces_only)   {       do_roles = false;       do_databases = false;   }   if (roles_only)   {
do_databases= false;       do_tablespaces = false;   }
 


Then we can have the new block this way:
       /* Dump role/database settings */       if (do_databases && do_roles)       {           if (server_version >=
80500)              dumpDbRoleConfig(conn);       }
 


-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Tom Lane escribió:
> Alvaro Herrera <alvherre@commandprompt.com> writes:
> > And here's the last necessary bit, which is pg_dump support for all
> > this.
> 
> > +         /* Dump role/database settings */
> > +         if (!tablespaces_only)
> > +         {
> > +             if (server_version >= 80500)
> > +                 dumpDbRoleConfig(conn);
> > +         }
> 
> Hmm ... I would kind of think that --roles-only should suppress this too.
> Otherwise you're going to be dumping commands that might refer to
> nonexistent databases.

Hmm.  The problem I have with this idea is that the only way to dump the
per-database role settings is if you are also dumping the contents of
all databases.  Which seems like a pain to me because the usage I
usually recommend is to backup global objects with pg_dumpall -g.

I wonder if pg_dumpall should have a method for dumping database
creation and settings, excluding contents (leaving that for plain
pg_dump).

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Tom Lane escribi�:
>> Hmm ... I would kind of think that --roles-only should suppress this too.
>> Otherwise you're going to be dumping commands that might refer to
>> nonexistent databases.

> Hmm.  The problem I have with this idea is that the only way to dump the
> per-database role settings is if you are also dumping the contents of
> all databases.  Which seems like a pain to me because the usage I
> usually recommend is to backup global objects with pg_dumpall -g.

Huh?  --globals-only would still dump them, no?

> I wonder if pg_dumpall should have a method for dumping database
> creation and settings, excluding contents (leaving that for plain
> pg_dump).

Perhaps.  People keep speculating about refactoring the division of
labor between pg_dump and pg_dumpall.  I'd advise leaving that for
a separate patch though ...
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Robert Haas
Date:
On Wed, Sep 30, 2009 at 10:34 AM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> And here's the last necessary bit, which is pg_dump support for all
> this.

I think it would be helpful if you could post ONE patch with all the
changes and all the new files in the diff.  AIUI, "the" patch is now
split across three separate emails.  :-(

...Robert


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Robert Haas escribió:
> On Wed, Sep 30, 2009 at 10:34 AM, Alvaro Herrera
> <alvherre@commandprompt.com> wrote:
> > And here's the last necessary bit, which is pg_dump support for all
> > this.
>
> I think it would be helpful if you could post ONE patch with all the
> changes and all the new files in the diff.  AIUI, "the" patch is now
> split across three separate emails.  :-(

That's correct, here it is.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Tom Lane escribió:

> BTW, have we thought much about the simplest possible solution,
> which is to not have the view?  How badly do we need it?  Seems
> like dropping the functionality into a psql \d command might be
> a viable alternative.

FWIW I came up with a preliminary patch for a new psql command \dus that
shows settings.  It takes a pattern that's used to constrain on roles.
Thus there is no way to view settings for a database.  If there's a need
for that we could use another command, say \dls.

Sample output

alvherre=# \dus fo*
            List of settings
 role | database |       settings
------+----------+-----------------------
 fob  |          | log_duration=true
 foo  | alvherre | work_mem=256MB
                 : statement_timeout=10s
 foo  |          | work_mem=512MB
                 : statement_timeout=1s
(3 rows)


--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> FWIW I came up with a preliminary patch for a new psql command \dus that
> shows settings.  It takes a pattern that's used to constrain on roles.
> Thus there is no way to view settings for a database.  If there's a need
> for that we could use another command, say \dls.

Why not two pattern arguments?
\drds [ role-pattern [ db-pattern ]]

Omitted patterns are presumed to be *
        regards, tom lane


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Tom Lane escribió:
> Alvaro Herrera <alvherre@commandprompt.com> writes:
> > FWIW I came up with a preliminary patch for a new psql command \dus that
> > shows settings.  It takes a pattern that's used to constrain on roles.
> > Thus there is no way to view settings for a database.  If there's a need
> > for that we could use another command, say \dls.
>
> Why not two pattern arguments?
>
>     \drds [ role-pattern [ db-pattern ]]

Hmm, interesting idea, patch attached.  This required changing the API
of processSQLNamePattern to return a bool indicating whether a clause
was added; otherwise, when processing the second pattern it was
impossible to figure out if we needed a WHERE or not.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 30. September 2009 13:19:53 -0400 Alvaro Herrera 
<alvherre@commandprompt.com> wrote:

>> I think it would be helpful if you could post ONE patch with all the
>> changes and all the new files in the diff.  AIUI, "the" patch is now
>> split across three separate emails.  :-(
>
> That's correct, here it is.

Some additional notes:

- ALTER ROLE ... IN DATABASE is missing some documentation. If you want, i 
can work on this.

- The patch as is has still some locking problems (AlterRoleSet() has a XXX 
about that): I've managed to create dead entries for a role or a database 
in pg_db_role_setting while altering and dropping a role/database in two 
concurrent sessions.

-- 
Thanks
Bernd


Re: TODO item: Allow more complex user/database default GUC settings

From
Alvaro Herrera
Date:
Bernd Helmle escribió:
> 
> 
> --On 30. September 2009 13:19:53 -0400 Alvaro Herrera
> <alvherre@commandprompt.com> wrote:
> 
> >>I think it would be helpful if you could post ONE patch with all the
> >>changes and all the new files in the diff.  AIUI, "the" patch is now
> >>split across three separate emails.  :-(
> >
> >That's correct, here it is.
> 
> Some additional notes:
> 
> - ALTER ROLE ... IN DATABASE is missing some documentation. If you
> want, i can work on this.

Please.

> - The patch as is has still some locking problems (AlterRoleSet()
> has a XXX about that): I've managed to create dead entries for a
> role or a database in pg_db_role_setting while altering and dropping
> a role/database in two concurrent sessions.

Yeah, I was playing with that too.  I think we need a few extra
LockSharedObject calls, and not only in the new code :-(  (This troubles
me in the case of databases, because we already grab a lock on it during
connection establishing, so this could cause extra contention there.)

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 1. Oktober 2009 17:22:06 -0400 Alvaro Herrera
<alvherre@commandprompt.com> wrote:

>> - ALTER ROLE ... IN DATABASE is missing some documentation. If you
>> want, i can work on this.
>
> Please.

Here's a patch for this. I've kept it separately, so it's easier for you to
merge it into
your version.

--
Thanks

    Bernd
Attachment

Re: TODO item: Allow more complex user/database default GUC settings

From
Bernd Helmle
Date:

--On 1. Oktober 2009 17:22:06 -0400 Alvaro Herrera 
<alvherre@commandprompt.com> wrote:

>> - The patch as is has still some locking problems (AlterRoleSet()
>> has a XXX about that): I've managed to create dead entries for a
>> role or a database in pg_db_role_setting while altering and dropping
>> a role/database in two concurrent sessions.
>
> Yeah, I was playing with that too.  I think we need a few extra
> LockSharedObject calls, and not only in the new code :-(  (This troubles
> me in the case of databases, because we already grab a lock on it during
> connection establishing, so this could cause extra contention there.)

I have marked the patch as "Ready For Committer", so it can be taken by a 
committer to help to resolve the remaining locking issue. There seems no 
other issues left. If this is too hasty, i can set it back to whatever you 
think its appropriate.

-- 
Thanks
Bernd