[PATCH] Warn users about duplicate configuration parameters

Started by Aleksander Alekseevalmost 9 years ago8 messages
#1Aleksander Alekseev
a.alekseev@postgrespro.ru
1 attachment(s)

Hi.

Recently I've discovered that if there are multiple values of the same
parameter in postgresql.conf PostgreSQL will silently use the last one.
It looks like not the best approach to me. For instance, user can find
the first value in the config file and expect that it will be used, etc.

I suggest to warn users about duplicated parameters. Here is a
corresponding patch.

Thoughts?

--
Best regards,
Aleksander Alekseev

Attachments:

duplicate_parameteres.patchtext/x-patchDownload
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index f01b814..6aa60a4 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -304,6 +304,13 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
 			}
 			/* Now mark it as present in file */
 			record->status |= GUC_IS_IN_FILE;
+
+			/* Warn the user about duplicate configuration parameter */
+			ereport(elevel,
+				(errcode(ERRCODE_DUPLICATE_OBJECT),
+				errmsg("duplicate configuration parameter \"%s\" overrides previous value in file \"%s\" line %u",
+						item->name,
+						item->filename, item->sourceline)));
 		}
 		else if (strchr(item->name, GUC_QUALIFIER_SEPARATOR) == NULL)
 		{
#2Andres Freund
andres@anarazel.de
In reply to: Aleksander Alekseev (#1)
Re: [PATCH] Warn users about duplicate configuration parameters

On 2017-04-07 18:14:27 +0300, Aleksander Alekseev wrote:

Hi.

Recently I've discovered that if there are multiple values of the same
parameter in postgresql.conf PostgreSQL will silently use the last one.
It looks like not the best approach to me. For instance, user can find
the first value in the config file and expect that it will be used, etc.

I suggest to warn users about duplicated parameters. Here is a
corresponding patch.

Thoughts?

-1 - I frequently just override earlier parameters by adding an include
at the end of the file. Also, with postgresql.auto.conf it's even more
common to override parameters.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tatsuo Ishii
ishii@sraoss.co.jp
In reply to: Andres Freund (#2)
Re: [PATCH] Warn users about duplicate configuration parameters

Recently I've discovered that if there are multiple values of the same
parameter in postgresql.conf PostgreSQL will silently use the last one.
It looks like not the best approach to me. For instance, user can find
the first value in the config file and expect that it will be used, etc.

I suggest to warn users about duplicated parameters. Here is a
corresponding patch.

Thoughts?

-1 - I frequently just override earlier parameters by adding an include
at the end of the file. Also, with postgresql.auto.conf it's even more
common to override parameters.

-1 from me too by the same reason Andres said.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Aleksander Alekseev
a.alekseev@postgrespro.ru
In reply to: Andres Freund (#2)
Re: [PATCH] Warn users about duplicate configuration parameters

Andres, Tatsuo,

Thank you for sharing your thoughts.

-1 - I frequently just override earlier parameters by adding an
include at the end of the file. Also, with postgresql.auto.conf it's
even more common to override parameters.

-1 from me too by the same reason Andres said.

I see no problem here. After all, it's just warnings. We can even add
a GUC that disables them specially for experienced users who knows what
she or he is doing. And/or add special case for postgresql.auto.conf.

--
Best regards,
Aleksander Alekseev

#5Andres Freund
andres@anarazel.de
In reply to: Aleksander Alekseev (#4)
Re: [PATCH] Warn users about duplicate configuration parameters

On 2017-04-07 18:29:40 +0300, Aleksander Alekseev wrote:

Andres, Tatsuo,

Thank you for sharing your thoughts.

-1 - I frequently just override earlier parameters by adding an
include at the end of the file. Also, with postgresql.auto.conf it's
even more common to override parameters.

-1 from me too by the same reason Andres said.

I see no problem here. After all, it's just warnings. We can even add
a GUC that disables them specially for experienced users who knows what
she or he is doing. And/or add special case for postgresql.auto.conf.

More useless warnings make actual warnings less useful.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6David Steele
david@pgmasters.net
In reply to: Tatsuo Ishii (#3)
Re: [PATCH] Warn users about duplicate configuration parameters

On 4/7/17 11:22 AM, Tatsuo Ishii wrote:

Recently I've discovered that if there are multiple values of the same
parameter in postgresql.conf PostgreSQL will silently use the last one.
It looks like not the best approach to me. For instance, user can find
the first value in the config file and expect that it will be used, etc.

I suggest to warn users about duplicated parameters. Here is a
corresponding patch.

Thoughts?

-1 - I frequently just override earlier parameters by adding an include
at the end of the file. Also, with postgresql.auto.conf it's even more
common to override parameters.

-1 from me too by the same reason Andres said.

-1 from me for the same reason.

--
-David
david@pgmasters.net

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Euler Taveira
euler@timbira.com.br
In reply to: Aleksander Alekseev (#1)
Re: [PATCH] Warn users about duplicate configuration parameters

2017-04-07 12:14 GMT-03:00 Aleksander Alekseev <a.alekseev@postgrespro.ru>:

Recently I've discovered that if there are multiple values of the same
parameter in postgresql.conf PostgreSQL will silently use the last one.
It looks like not the best approach to me. For instance, user can find
the first value in the config file and expect that it will be used, etc.

Postgres configuration file concept is based on overriding parameter
values. It would be annoying if we emit warning for this feature. Also, it
is easier to know which file/line the parameter value came from. You can
check for duplicates with a small script.

--
Euler Taveira Timbira - http://www.
timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento
<http://www.timbira.com.br&gt;

#8David G. Johnston
david.g.johnston@gmail.com
In reply to: Aleksander Alekseev (#4)
Re: [PATCH] Warn users about duplicate configuration parameters

On Fri, Apr 7, 2017 at 8:29 AM, Aleksander Alekseev <
a.alekseev@postgrespro.ru> wrote:

Andres, Tatsuo,

Thank you for sharing your thoughts.

-1 - I frequently just override earlier parameters by adding an
include at the end of the file. Also, with postgresql.auto.conf it's
even more common to override parameters.

-1 from me too by the same reason Andres said.

I see no problem here. After all, it's just warnings. We can even add
a GUC that disables them specially for experienced users who knows what
she or he is doing. And/or add special case for postgresql.auto.conf.

​-1 for learning how the configuration system work via warning messages.

We've recently added pg_file_settings to provide a holistic view and the
docs cover the topic quite well.

David J.