1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Merge the last few variable.c configuration variables into the generic

GUC support.  It's now possible to set datestyle, timezone, and
client_encoding from postgresql.conf and per-database or per-user
settings.  Also, implement rollback of SET commands that occur in a
transaction that later fails.  Create a SET LOCAL var = value syntax
that sets the variable only for the duration of the current transaction.
All per previous discussions in pghackers.
This commit is contained in:
Tom Lane
2002-05-17 01:19:19 +00:00
parent fa613fa1ea
commit f0811a74b3
42 changed files with 2641 additions and 1802 deletions

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.2 2002/04/23 02:07:15 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.3 2002/05/17 01:19:16 tgl Exp $
PostgreSQL documentation
-->
@ -28,10 +28,9 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replacea
<command>ALTER DATABASE</command> is used to change the session
default of a run-time configuration variable for a
<productname>PostgreSQL</productname> database. Whenever a new
session is subsequently started in that database, <literal>SET
<replaceable>variable</replaceable> TO
<replaceable>value</replaceable></literal> is effectively executed
before the start of the session. The database-specific default
session is subsequently started in that database, the specified
value becomes the session default value.
The database-specific default
overrides whatever setting is present in <filename>postgresql.conf</>
or has been received from the postmaster.
</para>
@ -64,7 +63,8 @@ ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replacea
configuration variable to the given value. If
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
or, equivalently, <literal>RESET</literal> is used, the
database-specific variable setting is removed and the default
database-specific variable setting is removed and the system-wide
default
setting will be inherited in new sessions. Use <literal>RESET
ALL</literal> to clear all settings.
</para>

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.21 2002/03/22 19:20:36 petere Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.22 2002/05/17 01:19:16 tgl Exp $
PostgreSQL documentation
-->
@ -48,14 +48,13 @@ ALTER USER <replaceable class="PARAMETER">username</replaceable> RESET <replacea
</para>
<para>
The second and the third variant change a user's session default of
The second and the third variant change a user's session default for
a specified configuration variable. Whenever the user subsequently
starts a new session, <literal>SET
<replaceable>variable</replaceable> TO
<replaceable>value</replaceable></literal> is effectively executed
before the start of the session. Ordinary users can change their
own session defaults. Superusers can change anyone's session
defaults.
starts a new session, the specified value becomes the session default,
overriding whatever setting is present in <filename>postgresql.conf</>
or has been received from the postmaster.
Ordinary users can change their own session defaults.
Superusers can change anyone's session defaults.
</para>
<refsect2>
@ -135,12 +134,12 @@ ALTER USER <replaceable class="PARAMETER">username</replaceable> RESET <replacea
<term><replaceable>value</replaceable></term>
<listitem>
<para>
Set this user's session default of the specified configuration
Set this user's session default for the specified configuration
variable to the given value. If
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
or, equivalently, <literal>RESET</literal> is used, the
user-specific variable setting is removed and the user will
inherit the default setting in new sessions. Use
inherit the system-wide default setting in new sessions. Use
<literal>RESET ALL</literal> to clear all settings.
</para>

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.13 2001/12/08 03:24:39 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.14 2002/05/17 01:19:16 tgl Exp $
PostgreSQL documentation
-->
@ -37,7 +37,7 @@ RESET ALL
<term>ALL</term>
<listitem>
<para>
Resets all run-time parameters to default values.
Resets all settable run-time parameters to default values.
</para>
</listitem>
</varlistentry>
@ -53,11 +53,18 @@ RESET ALL
<command>RESET</command> restores run-time parameters to their
default values. Refer to
<xref linkend="sql-set" endterm="sql-set-title">
for details. <command>RESET</command> is an alternate form for
for details. <command>RESET</command> is an alternate spelling for
<synopsis>
SET <replaceable class="parameter">variable</replaceable> TO DEFAULT
</synopsis>
The default value is defined as the value that the variable would
have had, had no <command>SET</> ever been issued for it in the
current session. The actual source of this value might be a
compiled-in default, the postmaster's configuration file or command-line
switches, or per-database or per-user default settings. See the
<citetitle>Administrator's Guide</citetitle> for details.
</para>
</refsect1>

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.59 2002/04/21 19:02:39 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.60 2002/05/17 01:19:16 tgl Exp $
PostgreSQL documentation
-->
@ -14,14 +14,40 @@ PostgreSQL documentation
</refnamediv>
<refsynopsisdiv>
<synopsis>
SET <replaceable class="PARAMETER">variable</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL | DEFAULT }
SET [ SESSION | LOCAL ] <replaceable class="PARAMETER">variable</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</replaceable> | LOCAL | DEFAULT }
</synopsis>
<refsect2 id="R2-SQL-SET-1">
<title>Inputs</title>
<para>
<variablelist>
<varlistentry>
<term><option>SESSION</></term>
<listitem>
<para>
Specifies that the command takes effect for the current session.
(This is the default if neither <option>SESSION</> nor
<option>LOCAL</> appears.)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>LOCAL</></term>
<listitem>
<para>
Specifies that the command takes effect for only the current
transaction. After <command>COMMIT</> or <command>ROLLBACK</>,
the session-level setting takes effect again. Note that
<command>SET LOCAL</> will appear to have no effect if it's
executed outside a <command>BEGIN</> block, since the transaction
will end immediately.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">variable</replaceable></term>
<listitem>
@ -30,6 +56,7 @@ SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">value</replaceable></term>
<listitem>
@ -49,34 +76,49 @@ SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL
<refsect1 id="R1-SQL-SET-1">
<title>Description</title>
<para>
The <command>SET</command> command changes run-time configuration
parameters. The following parameters can be altered:
parameters. Many of the run-time parameters listed in the
<citetitle>Administrator's Guide</citetitle> can be changed on-the-fly
with <command>SET</command>. (But some require superuser privileges
to change, and others cannot be changed after server or session start.)
Note that <command>SET</command> only affects the value used by the
current session.
</para>
<para>
If <command>SET</command> or <command>SET SESSION</command> is issued
within a transaction that is later aborted, the effects of the
<command>SET</command> command disappear when the transaction is rolled
back. (This behavior represents a change from
<productname>PostgreSQL</productname> versions prior to 7.3, where
the effects of <command>SET</command> would not roll back after a later
error.) Once the surrounding transaction is committed, the effects
will persist until the end of the session, unless overridden by another
<command>SET</command>.
</para>
<para>
The effects of <command>SET LOCAL</command> last only till the end of
the current transaction, whether committed or not. A special case is
<command>SET</command> followed by <command>SET LOCAL</command> within
a single transaction: the <command>SET LOCAL</command> value will be
seen until the end of the transaction, but afterwards (if the transaction
is committed) the <command>SET</command> value will take effect.
</para>
<para>
Here are additional details about a few of the parameters that can be set:
<variablelist>
<varlistentry>
<term>CLIENT_ENCODING</term>
<term>NAMES</term>
<listitem>
<para>
Sets the multibyte client encoding. The specified encoding
must be supported by the backend.
</para>
<para>
This option is only available if
<productname>PostgreSQL</productname> is build with multibyte
support.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>DATESTYLE</term>
<listitem>
<para>
Choose the date/time representation style. Two separate
settings are made: the default date/time output and the
settings are involved: the default date/time output and the
interpretation of ambiguous input.
</para>
@ -158,22 +200,6 @@ SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL
(substyles), or one from each separated by a comma.
</para>
<para>
Date format initialization may be done by:
<simplelist>
<member>
Setting the <envar>PGDATESTYLE</envar> environment variable.
If PGDATESTYLE is set in the frontend environment of a client
based on libpq, libpq will automatically set DATESTYLE to the
value of PGDATESTYLE during connection start-up.
</member>
<member>
Running postmaster using the option <option>-o -e</option> to
set dates to the <literal>European</literal> convention.
</member>
</simplelist>
</para>
<para>
<command>SET DATESTYLE</command> affects interpretation of
input and provides several standard output formats. For
@ -182,6 +208,41 @@ SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL
the <function>to_char</function> family of
functions.
</para>
<para>
There are several now-deprecated means for setting the datestyle
in addition to the normal methods of setting it via <command>SET</> or
a configuration-file entry:
<simplelist>
<member>
Setting the postmaster's <envar>PGDATESTYLE</envar> environment
variable. (This will be overridden by any of the other methods.)
</member>
<member>
Running postmaster using the option <option>-o -e</option> to
select the <literal>European</literal> conventions.
(This overrides environment variables and configuration-file
entries.)
</member>
<member>
Setting the client's <envar>PGDATESTYLE</envar> environment variable.
If PGDATESTYLE is set in the frontend environment of a client
based on libpq, libpq will automatically set DATESTYLE to the
value of PGDATESTYLE during connection start-up. This is
equivalent to a manually issued <command>SET</>.
</member>
</simplelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>NAMES</term>
<listitem>
<para>
<command>SET NAMES</> is an alias for <command>SET CLIENT_ENCODING</>.
</para>
</listitem>
</varlistentry>
@ -199,23 +260,22 @@ SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL
The value for the seed to be used by the
<function>random</function> function. Allowed
values are floating-point numbers between 0 and 1, which
are then multiplied by 2<superscript>31</>-1. This product will
silently overflow if a number outside the range is used.
</para>
<para>
The seed can also be set by invoking the
<function>setseed</function> SQL function:
<programlisting>
SELECT setseed(<replaceable>value</replaceable>);
</programlisting>
are then multiplied by 2<superscript>31</>-1.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The seed can also be set by invoking the
<function>setseed</function> SQL function:
<programlisting>
SELECT setseed(<replaceable>value</replaceable>);
</programlisting>
</para>
</listitem>
</varlistentry>
@ -223,13 +283,9 @@ SELECT setseed(<replaceable>value</replaceable>);
<term>SERVER_ENCODING</term>
<listitem>
<para>
Sets the multibyte server encoding.
</para>
<para>
This option is only available if
<productname>PostgreSQL</productname> was built with multibyte
support.
Shows the server-side multibyte encoding. (At present, this
parameter can be shown but not set, because the encoding is
determined at initdb time.)
</para>
</listitem>
</varlistentry>
@ -241,18 +297,18 @@ SELECT setseed(<replaceable>value</replaceable>);
<para>
Sets the default time zone for your session. Arguments can be
an SQL time interval constant, an integer or double precision
constant, or a string representing a time zone supported by
the host operating system.
constant, or a string representing a time zone name recognized
by the host operating system.
</para>
<para>
The possible values for time zone depends on your operating
The available time zone names depend on your operating
system. For example, on Linux
<filename>/usr/share/zoneinfo</filename> contains the database
of time zones.
</para>
<para>
Here are some valid values for time zone:
Here are some typical values for time zone names:
<variablelist>
<varlistentry>
@ -279,6 +335,14 @@ SELECT setseed(<replaceable>value</replaceable>);
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
In addition to time zone names, <productname>PostgreSQL</productname>
accepts these other methods of specifying a time zone:
<variablelist>
<varlistentry>
<term>7</term>
<listitem>
@ -310,7 +374,7 @@ SELECT setseed(<replaceable>value</replaceable>);
</variablelist>
</para>
<para>
If an invalid time zone is specified, the time zone
If an invalid time zone name is specified, the time zone
becomes GMT (on most systems anyway).
</para>
<para>
@ -324,14 +388,9 @@ SELECT setseed(<replaceable>value</replaceable>);
</variablelist>
</para>
<para>
An extended list of other run-time parameters can be found in the
<citetitle>Administrator's Guide</citetitle>.
</para>
<para>
Use <xref linkend="SQL-SHOW" endterm="SQL-SHOW-title"> to show the
current setting of a parameters.
current setting of a parameter.
</para>
</refsect1>
@ -363,7 +422,7 @@ SELECT setseed(<replaceable>value</replaceable>);
<term><computeroutput>ERROR: permission denied</computeroutput></term>
<listitem>
<para>
You must be a superuser to have access to certain settings.
You must be a superuser to alter certain settings.
</para>
</listitem>
</varlistentry>
@ -394,7 +453,7 @@ SET DATESTYLE TO PostgreSQL,European;
<para>
Set the time zone for Berkeley, California, using quotes to
preserve the uppercase attributes of the time zone specifier (note
preserve the uppercase spelling of the time zone name (note
that the date style is <literal>PostgreSQL</literal> for this
example):
@ -437,8 +496,8 @@ SELECT CURRENT_TIMESTAMP AS today;
only numeric time zone offsets while
<productname>PostgreSQL</productname> allows full time zone
specifier strings as well. All other <literal>SET</literal>
features are a
<productname>PostgreSQL</productname> extension.
features are
<productname>PostgreSQL</productname> extensions.
</para>
</refsect2>
</refsect1>

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_session_auth.sgml,v 1.5 2002/05/06 19:47:30 tgl Exp $ -->
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_session_auth.sgml,v 1.6 2002/05/17 01:19:16 tgl Exp $ -->
<refentry id="SQL-SET-SESSION-AUTHORIZATION">
<docinfo>
<date>2001-04-21</date>
@ -16,8 +16,8 @@
<refsynopsisdiv>
<synopsis>
SET SESSION AUTHORIZATION <parameter>username</parameter>
SET SESSION AUTHORIZATION DEFAULT
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION <parameter>username</parameter>
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
RESET SESSION AUTHORIZATION
</synopsis>
</refsynopsisdiv>
@ -51,6 +51,12 @@ RESET SESSION AUTHORIZATION
specifies the authenticated username.
</para>
<para>
The <option>SESSION</> and <option>LOCAL</> modifiers act the same
as for the regular <xref linkend="SQL-SET" endterm="SQL-SET-title">
command.
</para>
<para>
The <literal>DEFAULT</> and <literal>RESET</> forms reset the session
and current user identifiers to be the originally authenticated user

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.16 2002/03/06 06:48:05 momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.17 2002/05/17 01:19:16 tgl Exp $
PostgreSQL documentation
-->
@ -54,7 +54,7 @@ SHOW ALL
<para>
<command>SHOW</command> will display the current setting of a
run-time parameter. These variables can be set using the
<command>SET</command> statement or are determined at server start.
<command>SET</command> statement or are determined at session start.
</para>
</refsect1>
@ -72,25 +72,6 @@ SHOW ALL
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>ERROR: permission denied</computeroutput></term>
<listitem>
<para>
You must be a superuser to be allowed to see certain settings.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>WARNING: Time zone is unknown</computeroutput></term>
<listitem>
<para>
If the <envar>TZ</envar> or <envar>PGTZ</envar> environment
variable is not set.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.134 2002/05/03 04:11:07 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.135 2002/05/17 01:19:16 tgl Exp $
-->
<appendix id="release">
@ -24,6 +24,9 @@ CDATA means the content is "SGML-free", so you can write without
worries about funny characters.
-->
<literallayout><![CDATA[
Effects of SET within a transaction block now roll back if transaction aborts
New SET LOCAL syntax sets a parameter for the life of the current transaction
Datestyle, timezone, client_encoding can be set in postgresql.conf
The last vestiges of support for type names datetime and timespan are gone; use timestamp and interval instead
Rule names are now per-relation, not global; DROP RULE and COMMENT ON RULE syntax changes accordingly
Readline and Zlib are now required by default and must be turned off explicitly if their use is not desired
@ -36,8 +39,7 @@ Access privileges on functions
Access privileges on procedural languages
CREATE DATABASE has OWNER option so superuser can create DB for someone else
Kerberos 5 support now works with Heimdal
Database and user-specific session defaults of run-time configurations variables
(ALTER DATABASE ... SET and ALTER USER ... SET)
Database and user-specific session defaults for run-time configuration variables (ALTER DATABASE ... SET and ALTER USER ... SET)
]]></literallayout>
</sect1>

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.115 2002/05/09 13:30:24 petere Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.116 2002/05/17 01:19:16 tgl Exp $
-->
<Chapter Id="runtime">
@ -488,11 +488,13 @@ psql: could not connect to server: Connection refused
# This is a comment
log_connections = yes
syslog = 2
search_path = '$user, public'
</programlisting>
As you see, options are one per line. The equal sign between name
and value is optional. Whitespace is insignificant and blank lines
are ignored. Hash marks (<quote>#</quote>) introduce comments
anywhere.
anywhere. Parameter values that are not simple identifiers or
numbers should be single-quoted.
</para>
<para>
@ -526,7 +528,7 @@ postmaster -c log_connections=yes -c syslog=2
<programlisting>
env PGOPTIONS='-c geqo=off' psql
</programlisting>
(This works for any client application, not just
(This works for any libpq-based client application, not just
<application>psql</application>.) Note that this won't work for
options that are fixed when the server is started, such as the port
number.
@ -539,11 +541,17 @@ env PGOPTIONS='-c geqo=off' psql
=&gt; <userinput>SET ENABLE_SEQSCAN TO OFF;</userinput>
</screen>
See the SQL command language reference for details on the syntax.
</para>
<para>
Furthermore, it is possible to assign a set of option settings to
a user or a database. Whenever a session is started, the default
settings for the user and database involved are loaded. The
commands <literal>ALTER DATABASE</literal> and <literal>ALTER
USER</literal>, respectively, are used to configure these.
USER</literal>, respectively, are used to configure these settings.
Such per-database settings override anything received from the postmaster
or the configuration file, and in turn are overridden by per-user
settings.
</para>
<sect2 id="runtime-config-optimizer">
@ -1091,6 +1099,34 @@ env PGOPTIONS='-c geqo=off' psql
</listitem>
</varlistentry>
<varlistentry>
<term><varname>CLIENT_ENCODING</varname> (<type>string</type>)</term>
<indexterm><primary>character set encoding</></>
<listitem>
<para>
Sets the client-side encoding for multibyte character sets.
The default is to use the database encoding.
</para>
<para>
This option is only available if
<productname>PostgreSQL</productname> was built with multibyte
support.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>DATESTYLE</varname> (<type>string</type>)</term>
<indexterm><primary>date style</></>
<listitem>
<para>
Sets the display format for dates, as well as the rules for
interpreting ambiguous input dates.
The default is <literal>ISO, US</>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<indexterm>
<primary>deadlock</primary>
@ -1586,6 +1622,18 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
</listitem>
</varlistentry>
<varlistentry>
<term><varname>TIMEZONE</varname> (<type>string</type>)</term>
<indexterm><primary>time zone</></>
<listitem>
<para>
Sets the time zone for displaying and interpreting timestamps.
The default is to use whatever the system environment
specifies as the timezone.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>TRANSFORM_NULL_EQUALS</varname> (<type>boolean</type>)</term>
<indexterm><primary>IS NULL</></>