Compare commits

...

6 Commits

Author SHA1 Message Date
Andres Freund
22655aa231 Fix bulk table extension when copying into multiple partitions
When COPYing into a partitioned table that does now permit the use of
table_multi_insert(), we could error out with
  ERROR: could not read block NN in file "base/...": read only 0 of 8192 bytes

because BulkInsertState->next_free was not reset between partitions. This
problem occurred only when not able to use table_multi_insert(), as a
dedicated BulkInsertState for each partition is used in that case.

The bug was introduced in 00d1e02be24, but it was hard to hit at that point,
as commonly bulk relation extension is not used when not using
table_multi_insert(). It became more likely after 82a4edabd27, which expanded
the use of bulk extension.

To fix the bug, reset the bulk relation extension state in BulkInsertState in
ReleaseBulkInsertStatePin(). That was added (in b1ecb9b3fcf) to tackle a very
similar issue.  Obviously the name is not quite correct, but there might be
external callers, and bulk insert state needs to be reset in precisely in the
situations that ReleaseBulkInsertStatePin() already needed to be called.

Medium term the better fix likely is to disallow reusing BulkInsertState
across relations.

Add a test that, without the fix, reproduces #18130 in most
configurations. The test also catches the problem fixed in b1ecb9b3fcf when
run with small shared_buffers.

Reported-by: Ivan Kolombet <enderstd@gmail.com>
Analyzed-by: Tom Lane <tgl@sss.pgh.pa.us>
Analyzed-by: Andres Freund <andres@anarazel.de>
Bug: #18130
Discussion: https://postgr.es/m/18130-7a86a7356a75209d%40postgresql.org
Discussion: https://postgr.es/m/257696.1695670946%40sss.pgh.pa.us
Backpatch: 16-
2023-10-13 19:16:44 -07:00
Nathan Bossart
8d140c5822 Improve the naming in wal_sync_method code.
* sync_method is renamed to wal_sync_method.

* sync_method_options[] is renamed to wal_sync_method_options[].

* assign_xlog_sync_method() is renamed to assign_wal_sync_method().

* The names of the available synchronization methods are now
  prefixed with "WAL_SYNC_METHOD_" and have been moved into a
  WalSyncMethod enum.

* PLATFORM_DEFAULT_SYNC_METHOD is renamed to
  PLATFORM_DEFAULT_WAL_SYNC_METHOD, and DEFAULT_SYNC_METHOD is
  renamed to DEFAULT_WAL_SYNC_METHOD.

These more descriptive names help distinguish the code for
wal_sync_method from the code for DataDirSyncMethod (e.g., the
recovery_init_sync_method configuration parameter and the
--sync-method option provided by several frontend utilities).  This
change also prevents name collisions between the aforementioned
sets of code.  Since this only improves the naming of internal
identifiers, there should be no behavior change.

Author: Maxim Orlov
Discussion: https://postgr.es/m/CACG%3DezbL1gwE7_K7sr9uqaCGkWhmvRTcTEnm3%2BX1xsRNwbXULQ%40mail.gmail.com
2023-10-13 15:16:45 -05:00
Daniel Gustafsson
c5a032e518 Update oldextversions test for pg_stat_statements 1.11
Commit 5a3423ad8e updated pg_stat_statements to 1.11 due to added
columns in the view for jit deform counters. Fixing oldextversion
was however missed in that commit.  This adds a test for the 1.11
version view definition.

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/CAN55FZ2Y7c2VEg4S1KDXFcaHjyF8=KZa_rMV6WOe+KwE-KE97g@mail.gmail.com
2023-10-13 13:50:18 +02:00
Amit Kapila
536f410111 Doc: Add more links in logical replication pages.
The logical replication pages in the docs mostly have links to
corresponding pub/sub commands whenever they are mentioned, but there were
some omissions. This patch adds the missing links.

Author: Peter Smith
Reviewed-by: Vignesh C, Amit Kapila
Discussion: https://www.postgresql.org/message-id/flat/CAHut%2BPu2S4RdzYKR7H5_E7QYWyq5hB0hL4EFrYbP91Qso62jeg%40mail.gmail.com
2023-10-13 12:13:46 +05:30
Michael Paquier
d16eb83aba psql: Add completion support for AT [ LOCAL | TIME ZONE ]
AT TIME ZONE is completed with a list of supported timezones, something
not needed by AT LOCAL.

Author: Dagfinn Ilmari Mannsåker
Reviewed-by: Jim Jones
Discussion: https://postgr.es/m/87jzyzsvgv.fsf@wibble.ilmari.org
2023-10-13 14:19:07 +09:00
Michael Paquier
97957fdbaa Add support for AT LOCAL
When converting a timestamp to/from with/without time zone, the SQL
Standard specifies an AT LOCAL variant of AT TIME ZONE which uses the
session's time zone.  This includes three system functions able to do
the work in the same way as the existing flavors for AT TIME ZONE,
except that these need to be marked as stable as they depend on the
session's TimeZone GUC.

Bump catalog version.

Author: Vik Fearing
Reviewed-by: Laurenz Albe, Cary Huang, Michael Paquier
Discussion: https://postgr.es/m/8e25dec4-5667-c1a5-6581-167d710c2182@postgresfriends.org
2023-10-13 13:01:37 +09:00
30 changed files with 532 additions and 74 deletions

View File

@ -250,4 +250,62 @@ SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
t t
(1 row) (1 row)
-- New views for pg_stat_statements in 1.11
AlTER EXTENSION pg_stat_statements UPDATE TO '1.11';
\d pg_stat_statements
View "public.pg_stat_statements"
Column | Type | Collation | Nullable | Default
------------------------+------------------+-----------+----------+---------
userid | oid | | |
dbid | oid | | |
toplevel | boolean | | |
queryid | bigint | | |
query | text | | |
plans | bigint | | |
total_plan_time | double precision | | |
min_plan_time | double precision | | |
max_plan_time | double precision | | |
mean_plan_time | double precision | | |
stddev_plan_time | double precision | | |
calls | bigint | | |
total_exec_time | double precision | | |
min_exec_time | double precision | | |
max_exec_time | double precision | | |
mean_exec_time | double precision | | |
stddev_exec_time | double precision | | |
rows | bigint | | |
shared_blks_hit | bigint | | |
shared_blks_read | bigint | | |
shared_blks_dirtied | bigint | | |
shared_blks_written | bigint | | |
local_blks_hit | bigint | | |
local_blks_read | bigint | | |
local_blks_dirtied | bigint | | |
local_blks_written | bigint | | |
temp_blks_read | bigint | | |
temp_blks_written | bigint | | |
blk_read_time | double precision | | |
blk_write_time | double precision | | |
temp_blk_read_time | double precision | | |
temp_blk_write_time | double precision | | |
wal_records | bigint | | |
wal_fpi | bigint | | |
wal_bytes | numeric | | |
jit_functions | bigint | | |
jit_generation_time | double precision | | |
jit_inlining_count | bigint | | |
jit_inlining_time | double precision | | |
jit_optimization_count | bigint | | |
jit_optimization_time | double precision | | |
jit_emission_count | bigint | | |
jit_emission_time | double precision | | |
jit_deform_count | bigint | | |
jit_deform_time | double precision | | |
SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
has_data
----------
t
(1 row)
DROP EXTENSION pg_stat_statements; DROP EXTENSION pg_stat_statements;

View File

@ -48,4 +48,9 @@ AlTER EXTENSION pg_stat_statements UPDATE TO '1.10';
\d pg_stat_statements \d pg_stat_statements
SELECT count(*) > 0 AS has_data FROM pg_stat_statements; SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
-- New views for pg_stat_statements in 1.11
AlTER EXTENSION pg_stat_statements UPDATE TO '1.11';
\d pg_stat_statements
SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
DROP EXTENSION pg_stat_statements; DROP EXTENSION pg_stat_statements;

View File

@ -10611,7 +10611,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
</sect2> </sect2>
<sect2 id="functions-datetime-zoneconvert"> <sect2 id="functions-datetime-zoneconvert">
<title><literal>AT TIME ZONE</literal></title> <title><literal>AT TIME ZONE and AT LOCAL</literal></title>
<indexterm> <indexterm>
<primary>time zone</primary> <primary>time zone</primary>
@ -10622,6 +10622,10 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
<primary>AT TIME ZONE</primary> <primary>AT TIME ZONE</primary>
</indexterm> </indexterm>
<indexterm>
<primary>AT LOCAL</primary>
</indexterm>
<para> <para>
The <literal>AT TIME ZONE</literal> operator converts time The <literal>AT TIME ZONE</literal> operator converts time
stamp <emphasis>without</emphasis> time zone to/from stamp <emphasis>without</emphasis> time zone to/from
@ -10632,7 +10636,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
</para> </para>
<table id="functions-datetime-zoneconvert-table"> <table id="functions-datetime-zoneconvert-table">
<title><literal>AT TIME ZONE</literal> Variants</title> <title><literal>AT TIME ZONE</literal> and <literal>AT LOCAL</literal> Variants</title>
<tgroup cols="1"> <tgroup cols="1">
<thead> <thead>
<row> <row>
@ -10665,6 +10669,22 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
</para></entry> </para></entry>
</row> </row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>timestamp without time zone</type> <literal>AT LOCAL</literal>
<returnvalue>timestamp with time zone</returnvalue>
</para>
<para>
Converts given time stamp <emphasis>without</emphasis> time zone to
time stamp <emphasis>with</emphasis> the session's
<varname>TimeZone</varname> value as time zone.
</para>
<para>
<literal>timestamp '2001-02-16 20:38:40' at local</literal>
<returnvalue>2001-02-17 03:38:40+00</returnvalue>
</para></entry>
</row>
<row> <row>
<entry role="func_table_entry"><para role="func_signature"> <entry role="func_table_entry"><para role="func_signature">
<type>timestamp with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable> <type>timestamp with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable>
@ -10681,6 +10701,22 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
</para></entry> </para></entry>
</row> </row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>timestamp with time zone</type> <literal>AT LOCAL</literal>
<returnvalue>timestamp without time zone</returnvalue>
</para>
<para>
Converts given time stamp <emphasis>with</emphasis> time zone to
time stamp <emphasis>without</emphasis> time zone, as the time would
appear with the session's <varname>TimeZone</varname> value as time zone.
</para>
<para>
<literal>timestamp with time zone '2001-02-16 20:38:40-05' at local</literal>
<returnvalue>2001-02-16 18:38:40</returnvalue>
</para></entry>
</row>
<row> <row>
<entry role="func_table_entry"><para role="func_signature"> <entry role="func_table_entry"><para role="func_signature">
<type>time with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable> <type>time with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable>
@ -10696,6 +10732,25 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
<returnvalue>10:34:17+00</returnvalue> <returnvalue>10:34:17+00</returnvalue>
</para></entry> </para></entry>
</row> </row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>time with time zone</type> <literal>AT LOCAL</literal>
<returnvalue>time with time zone</returnvalue>
</para>
<para>
Converts given time <emphasis>with</emphasis> time zone to a new time
zone. Since no date is supplied, this uses the currently active UTC
offset for the session's <varname>TimeZone</varname> value.
</para>
<para>
Assuming the session's <varname>TimeZone</varname> is set to <literal>UTC</literal>:
</para>
<para>
<literal>time with time zone '05:34:17-05' at local</literal>
<returnvalue>10:34:17+00</returnvalue>
</para></entry>
</row>
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
@ -10710,6 +10765,13 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
UTC, so it is not very common in practice. UTC, so it is not very common in practice.
</para> </para>
<para>
The syntax <literal>AT LOCAL</literal> may be used as shorthand for
<literal>AT TIME ZONE <replaceable>local</replaceable></literal>, where
<replaceable>local</replaceable> is the session's
<varname>TimeZone</varname> value.
</para>
<para> <para>
Examples (assuming the current <xref linkend="guc-timezone"/> setting Examples (assuming the current <xref linkend="guc-timezone"/> setting
is <literal>America/Los_Angeles</literal>): is <literal>America/Los_Angeles</literal>):
@ -10722,6 +10784,12 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/D
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago'; SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput> <lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT LOCAL;
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 17:38:40</computeroutput>
SELECT TIME WITH TIME ZONE '20:38:40-05' AT LOCAL;
<lineannotation>Result: </lineannotation><computeroutput>17:38:40</computeroutput>
</screen> </screen>
The first example adds a time zone to a value that lacks it, and The first example adds a time zone to a value that lacks it, and
displays the value using the current <varname>TimeZone</varname> displays the value using the current <varname>TimeZone</varname>
@ -10729,7 +10797,18 @@ SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'A
to the specified time zone, and returns the value without a time zone. to the specified time zone, and returns the value without a time zone.
This allows storage and display of values different from the current This allows storage and display of values different from the current
<varname>TimeZone</varname> setting. The third example converts <varname>TimeZone</varname> setting. The third example converts
Tokyo time to Chicago time. Tokyo time to Chicago time. The fourth example shifts the time stamp
with time zone value to the time zone currently specified by the
<varname>TimeZone</varname> setting and returns the value without a
time zone.
</para>
<para>
The fifth example is a cautionary tale. Due to the fact that there is no
date associated with the input value, the conversion is made using the
current date of the session. Therefore, this static example may show a wrong
result depending on the time of the year it is viewed because
<literal>'America/Los_Angeles'</literal> observes Daylight Savings Time.
</para> </para>
<para> <para>
@ -10745,6 +10824,18 @@ SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'A
<literal><replaceable>time</replaceable> AT TIME ZONE <literal><replaceable>time</replaceable> AT TIME ZONE
<replaceable>zone</replaceable></literal>. <replaceable>zone</replaceable></literal>.
</para> </para>
<para>
The function <literal><function>timezone</function>(<replaceable>timestamp</replaceable>)</literal>
is equivalent to the SQL-conforming construct <literal><replaceable>timestamp</replaceable>
AT LOCAL</literal>.
</para>
<para>
The function <literal><function>timezone</function>(<replaceable>time</replaceable>)</literal>
is equivalent to the SQL-conforming construct <literal><replaceable>time</replaceable>
AT LOCAL</literal>.
</para>
</sect2> </sect2>
<sect2 id="functions-datetime-current"> <sect2 id="functions-datetime-current">

View File

@ -274,9 +274,11 @@
</para> </para>
<para> <para>
Normally, the remote replication slot is created automatically when the Normally, the remote replication slot is created automatically when the
subscription is created using <command>CREATE SUBSCRIPTION</command> and it subscription is created using <link linkend="sql-createsubscription">
<command>CREATE SUBSCRIPTION</command></link> and it
is dropped automatically when the subscription is dropped using is dropped automatically when the subscription is dropped using
<command>DROP SUBSCRIPTION</command>. In some situations, however, it can <link linkend="sql-dropsubscription"><command>DROP SUBSCRIPTION</command></link>.
In some situations, however, it can
be useful or necessary to manipulate the subscription and the underlying be useful or necessary to manipulate the subscription and the underlying
replication slot separately. Here are some scenarios: replication slot separately. Here are some scenarios:
@ -306,8 +308,9 @@
When dropping a subscription, the replication slot should be kept. When dropping a subscription, the replication slot should be kept.
This could be useful when the subscriber database is being moved to a This could be useful when the subscriber database is being moved to a
different host and will be activated from there. In that case, different host and will be activated from there. In that case,
disassociate the slot from the subscription using <command>ALTER disassociate the slot from the subscription using
SUBSCRIPTION</command> before attempting to drop the subscription. <link linkend="sql-altersubscription"><command>ALTER SUBSCRIPTION</command></link>
before attempting to drop the subscription.
</para> </para>
</listitem> </listitem>
@ -1349,7 +1352,8 @@ test_sub=# SELECT * FROM child ORDER BY a;
If a subscription is affected by this problem, the only way to resume If a subscription is affected by this problem, the only way to resume
replication is to adjust one of the column lists on the publication replication is to adjust one of the column lists on the publication
side so that they all match; and then either recreate the subscription, side so that they all match; and then either recreate the subscription,
or use <literal>ALTER SUBSCRIPTION ... DROP PUBLICATION</literal> to or use <link linkend="sql-altersubscription-params-setadddrop-publication">
<literal>ALTER SUBSCRIPTION ... DROP PUBLICATION</literal></link> to
remove one of the offending publications and add it again. remove one of the offending publications and add it again.
</para> </para>
</warning> </warning>
@ -1504,13 +1508,15 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
the replication origin name can be found from the server log (LSN 0/14C0378 and the replication origin name can be found from the server log (LSN 0/14C0378 and
replication origin <literal>pg_16395</literal> in the above case). The replication origin <literal>pg_16395</literal> in the above case). The
transaction that produced the conflict can be skipped by using transaction that produced the conflict can be skipped by using
<command>ALTER SUBSCRIPTION ... SKIP</command> with the finish LSN <link linkend="sql-altersubscription-params-skip"><command>ALTER SUBSCRIPTION ... SKIP</command></link>
with the finish LSN
(i.e., LSN 0/14C0378). The finish LSN could be an LSN at which the transaction (i.e., LSN 0/14C0378). The finish LSN could be an LSN at which the transaction
is committed or prepared on the publisher. Alternatively, the transaction can is committed or prepared on the publisher. Alternatively, the transaction can
also be skipped by calling the <link linkend="pg-replication-origin-advance"> also be skipped by calling the <link linkend="pg-replication-origin-advance">
<function>pg_replication_origin_advance()</function></link> function. <function>pg_replication_origin_advance()</function></link> function.
Before using this function, the subscription needs to be disabled temporarily Before using this function, the subscription needs to be disabled temporarily
either by <command>ALTER SUBSCRIPTION ... DISABLE</command> or, the either by <link linkend="sql-altersubscription-params-disable">
<command>ALTER SUBSCRIPTION ... DISABLE</command></link> or, the
subscription can be used with the subscription can be used with the
<link linkend="sql-createsubscription-with-disable-on-error"><literal>disable_on_error</literal></link> <link linkend="sql-createsubscription-with-disable-on-error"><literal>disable_on_error</literal></link>
option. Then, you can use <function>pg_replication_origin_advance()</function> option. Then, you can use <function>pg_replication_origin_advance()</function>

View File

@ -51,7 +51,8 @@ ALTER PUBLICATION <replaceable class="parameter">name</replaceable> RENAME TO <r
<literal>ADD</literal> and <literal>DROP</literal> clauses will add and <literal>ADD</literal> and <literal>DROP</literal> clauses will add and
remove one or more tables/schemas from the publication. Note that adding remove one or more tables/schemas from the publication. Note that adding
tables/schemas to a publication that is already subscribed to will require an tables/schemas to a publication that is already subscribed to will require an
<literal>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</literal> action on the <link linkend="sql-altersubscription-params-refresh-publication">
<literal>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</literal></link> action on the
subscribing side in order to become effective. Note also that subscribing side in order to become effective. Note also that
<literal>DROP TABLES IN SCHEMA</literal> will not drop any schema tables <literal>DROP TABLES IN SCHEMA</literal> will not drop any schema tables
that were specified using that were specified using

View File

@ -85,7 +85,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
<title>Parameters</title> <title>Parameters</title>
<variablelist> <variablelist>
<varlistentry> <varlistentry id="sql-altersubscription-params-name">
<term><replaceable class="parameter">name</replaceable></term> <term><replaceable class="parameter">name</replaceable></term>
<listitem> <listitem>
<para> <para>
@ -94,7 +94,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-connection">
<term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term> <term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term>
<listitem> <listitem>
<para> <para>
@ -105,7 +105,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-setadddrop-publication">
<term><literal>SET PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term> <term><literal>SET PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
<term><literal>ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term> <term><literal>ADD PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
<term><literal>DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term> <term><literal>DROP PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
@ -147,13 +147,14 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-refresh-publication">
<term><literal>REFRESH PUBLICATION</literal></term> <term><literal>REFRESH PUBLICATION</literal></term>
<listitem> <listitem>
<para> <para>
Fetch missing table information from publisher. This will start Fetch missing table information from publisher. This will start
replication of tables that were added to the subscribed-to publications replication of tables that were added to the subscribed-to publications
since <command>CREATE SUBSCRIPTION</command> or since <link linkend="sql-createsubscription">
<command>CREATE SUBSCRIPTION</command></link> or
the last invocation of <command>REFRESH PUBLICATION</command>. the last invocation of <command>REFRESH PUBLICATION</command>.
</para> </para>
@ -192,7 +193,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-enable">
<term><literal>ENABLE</literal></term> <term><literal>ENABLE</literal></term>
<listitem> <listitem>
<para> <para>
@ -202,7 +203,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-disable">
<term><literal>DISABLE</literal></term> <term><literal>DISABLE</literal></term>
<listitem> <listitem>
<para> <para>
@ -212,7 +213,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-set">
<term><literal>SET ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )</literal></term> <term><literal>SET ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )</literal></term>
<listitem> <listitem>
<para> <para>
@ -232,7 +233,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-skip">
<term><literal>SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )</literal></term> <term><literal>SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )</literal></term>
<listitem> <listitem>
<para> <para>
@ -272,7 +273,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-new-owner">
<term><replaceable class="parameter">new_owner</replaceable></term> <term><replaceable class="parameter">new_owner</replaceable></term>
<listitem> <listitem>
<para> <para>
@ -281,7 +282,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry id="sql-altersubscription-params-new-name">
<term><replaceable class="parameter">new_name</replaceable></term> <term><replaceable class="parameter">new_name</replaceable></term>
<listitem> <listitem>
<para> <para>

View File

@ -40,7 +40,7 @@ DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable
<para> <para>
<command>DROP SUBSCRIPTION</command> cannot be executed inside a <command>DROP SUBSCRIPTION</command> cannot be executed inside a
transaction block if the subscription is associated with a replication transaction block if the subscription is associated with a replication
slot. (You can use <command>ALTER SUBSCRIPTION</command> to unset the slot. (You can use <link linkend="sql-altersubscription"><command>ALTER SUBSCRIPTION</command></link> to unset the
slot.) slot.)
</para> </para>
</refsect1> </refsect1>
@ -87,9 +87,11 @@ DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable
replication slot cannot be dropped or does not exist or never existed, replication slot cannot be dropped or does not exist or never existed,
the <command>DROP SUBSCRIPTION</command> command will fail. To proceed the <command>DROP SUBSCRIPTION</command> command will fail. To proceed
in this situation, first disable the subscription by executing in this situation, first disable the subscription by executing
<literal>ALTER SUBSCRIPTION ... DISABLE</literal>, and then disassociate <link linkend="sql-altersubscription-params-disable">
<literal>ALTER SUBSCRIPTION ... DISABLE</literal></link>, and then disassociate
it from the replication slot by executing it from the replication slot by executing
<literal>ALTER SUBSCRIPTION ... SET (slot_name = NONE)</literal>. <link linkend="sql-altersubscription-params-set">
<literal>ALTER SUBSCRIPTION ... SET (slot_name = NONE)</literal></link>.
After that, <command>DROP SUBSCRIPTION</command> will no longer attempt any After that, <command>DROP SUBSCRIPTION</command> will no longer attempt any
actions on a remote host. Note that if the remote replication slot still actions on a remote host. Note that if the remote replication slot still
exists, it (and any related table synchronization slots) should then be exists, it (and any related table synchronization slots) should then be

View File

@ -1792,6 +1792,17 @@ ReleaseBulkInsertStatePin(BulkInsertState bistate)
if (bistate->current_buf != InvalidBuffer) if (bistate->current_buf != InvalidBuffer)
ReleaseBuffer(bistate->current_buf); ReleaseBuffer(bistate->current_buf);
bistate->current_buf = InvalidBuffer; bistate->current_buf = InvalidBuffer;
/*
* Despite the name, we also reset bulk relation extension
* state. Otherwise we can end up erroring out due to looking for free
* space in ->next_free of one partition, even though ->next_free was set
* when extending another partition. It's obviously also could be bad for
* efficiency to look at existing blocks at offsets from another
* partition, even if we don't error out.
*/
bistate->next_free = InvalidBlockNumber;
bistate->last_free = InvalidBlockNumber;
} }

View File

@ -130,7 +130,7 @@ bool *wal_consistency_checking = NULL;
bool wal_init_zero = true; bool wal_init_zero = true;
bool wal_recycle = true; bool wal_recycle = true;
bool log_checkpoints = true; bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD; int wal_sync_method = DEFAULT_WAL_SYNC_METHOD;
int wal_level = WAL_LEVEL_REPLICA; int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */ int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */ int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
@ -171,17 +171,17 @@ static bool check_wal_consistency_checking_deferred = false;
/* /*
* GUC support * GUC support
*/ */
const struct config_enum_entry sync_method_options[] = { const struct config_enum_entry wal_sync_method_options[] = {
{"fsync", SYNC_METHOD_FSYNC, false}, {"fsync", WAL_SYNC_METHOD_FSYNC, false},
#ifdef HAVE_FSYNC_WRITETHROUGH #ifdef HAVE_FSYNC_WRITETHROUGH
{"fsync_writethrough", SYNC_METHOD_FSYNC_WRITETHROUGH, false}, {"fsync_writethrough", WAL_SYNC_METHOD_FSYNC_WRITETHROUGH, false},
#endif #endif
{"fdatasync", SYNC_METHOD_FDATASYNC, false}, {"fdatasync", WAL_SYNC_METHOD_FDATASYNC, false},
#ifdef O_SYNC #ifdef O_SYNC
{"open_sync", SYNC_METHOD_OPEN, false}, {"open_sync", WAL_SYNC_METHOD_OPEN, false},
#endif #endif
#ifdef O_DSYNC #ifdef O_DSYNC
{"open_datasync", SYNC_METHOD_OPEN_DSYNC, false}, {"open_datasync", WAL_SYNC_METHOD_OPEN_DSYNC, false},
#endif #endif
{NULL, 0, false} {NULL, 0, false}
}; };
@ -2343,8 +2343,8 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
* have no open file or the wrong one. However, we do not need to * have no open file or the wrong one. However, we do not need to
* fsync more than one file. * fsync more than one file.
*/ */
if (sync_method != SYNC_METHOD_OPEN && if (wal_sync_method != WAL_SYNC_METHOD_OPEN &&
sync_method != SYNC_METHOD_OPEN_DSYNC) wal_sync_method != WAL_SYNC_METHOD_OPEN_DSYNC)
{ {
if (openLogFile >= 0 && if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo, !XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo,
@ -2974,7 +2974,7 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
*/ */
*added = false; *added = false;
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC | fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
get_sync_bit(sync_method)); get_sync_bit(wal_sync_method));
if (fd < 0) if (fd < 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)
@ -3139,7 +3139,7 @@ XLogFileInit(XLogSegNo logsegno, TimeLineID logtli)
/* Now open original target segment (might not be file I just made) */ /* Now open original target segment (might not be file I just made) */
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC | fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
get_sync_bit(sync_method)); get_sync_bit(wal_sync_method));
if (fd < 0) if (fd < 0)
ereport(ERROR, ereport(ERROR,
(errcode_for_file_access(), (errcode_for_file_access(),
@ -3371,7 +3371,7 @@ XLogFileOpen(XLogSegNo segno, TimeLineID tli)
XLogFilePath(path, tli, segno, wal_segment_size); XLogFilePath(path, tli, segno, wal_segment_size);
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC | fd = BasicOpenFile(path, O_RDWR | PG_BINARY | O_CLOEXEC |
get_sync_bit(sync_method)); get_sync_bit(wal_sync_method));
if (fd < 0) if (fd < 0)
ereport(PANIC, ereport(PANIC,
(errcode_for_file_access(), (errcode_for_file_access(),
@ -8137,16 +8137,16 @@ get_sync_bit(int method)
* not included in the enum option array, and therefore will never * not included in the enum option array, and therefore will never
* be seen here. * be seen here.
*/ */
case SYNC_METHOD_FSYNC: case WAL_SYNC_METHOD_FSYNC:
case SYNC_METHOD_FSYNC_WRITETHROUGH: case WAL_SYNC_METHOD_FSYNC_WRITETHROUGH:
case SYNC_METHOD_FDATASYNC: case WAL_SYNC_METHOD_FDATASYNC:
return o_direct_flag; return o_direct_flag;
#ifdef O_SYNC #ifdef O_SYNC
case SYNC_METHOD_OPEN: case WAL_SYNC_METHOD_OPEN:
return O_SYNC | o_direct_flag; return O_SYNC | o_direct_flag;
#endif #endif
#ifdef O_DSYNC #ifdef O_DSYNC
case SYNC_METHOD_OPEN_DSYNC: case WAL_SYNC_METHOD_OPEN_DSYNC:
return O_DSYNC | o_direct_flag; return O_DSYNC | o_direct_flag;
#endif #endif
default: default:
@ -8160,9 +8160,9 @@ get_sync_bit(int method)
* GUC support * GUC support
*/ */
void void
assign_xlog_sync_method(int new_sync_method, void *extra) assign_wal_sync_method(int new_wal_sync_method, void *extra)
{ {
if (sync_method != new_sync_method) if (wal_sync_method != new_wal_sync_method)
{ {
/* /*
* To ensure that no blocks escape unsynced, force an fsync on the * To ensure that no blocks escape unsynced, force an fsync on the
@ -8188,7 +8188,7 @@ assign_xlog_sync_method(int new_sync_method, void *extra)
} }
pgstat_report_wait_end(); pgstat_report_wait_end();
if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method)) if (get_sync_bit(wal_sync_method) != get_sync_bit(new_wal_sync_method))
XLogFileClose(); XLogFileClose();
} }
} }
@ -8214,8 +8214,8 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
* file. * file.
*/ */
if (!enableFsync || if (!enableFsync ||
sync_method == SYNC_METHOD_OPEN || wal_sync_method == WAL_SYNC_METHOD_OPEN ||
sync_method == SYNC_METHOD_OPEN_DSYNC) wal_sync_method == WAL_SYNC_METHOD_OPEN_DSYNC)
return; return;
/* Measure I/O timing to sync the WAL file */ /* Measure I/O timing to sync the WAL file */
@ -8225,29 +8225,29 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
INSTR_TIME_SET_ZERO(start); INSTR_TIME_SET_ZERO(start);
pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC); pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC);
switch (sync_method) switch (wal_sync_method)
{ {
case SYNC_METHOD_FSYNC: case WAL_SYNC_METHOD_FSYNC:
if (pg_fsync_no_writethrough(fd) != 0) if (pg_fsync_no_writethrough(fd) != 0)
msg = _("could not fsync file \"%s\": %m"); msg = _("could not fsync file \"%s\": %m");
break; break;
#ifdef HAVE_FSYNC_WRITETHROUGH #ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH: case WAL_SYNC_METHOD_FSYNC_WRITETHROUGH:
if (pg_fsync_writethrough(fd) != 0) if (pg_fsync_writethrough(fd) != 0)
msg = _("could not fsync write-through file \"%s\": %m"); msg = _("could not fsync write-through file \"%s\": %m");
break; break;
#endif #endif
case SYNC_METHOD_FDATASYNC: case WAL_SYNC_METHOD_FDATASYNC:
if (pg_fdatasync(fd) != 0) if (pg_fdatasync(fd) != 0)
msg = _("could not fdatasync file \"%s\": %m"); msg = _("could not fdatasync file \"%s\": %m");
break; break;
case SYNC_METHOD_OPEN: case WAL_SYNC_METHOD_OPEN:
case SYNC_METHOD_OPEN_DSYNC: case WAL_SYNC_METHOD_OPEN_DSYNC:
/* not reachable */ /* not reachable */
Assert(false); Assert(false);
break; break;
default: default:
elog(PANIC, "unrecognized wal_sync_method: %d", sync_method); elog(PANIC, "unrecognized wal_sync_method: %d", wal_sync_method);
break; break;
} }

View File

@ -14508,6 +14508,13 @@ a_expr: c_expr { $$ = $1; }
COERCE_SQL_SYNTAX, COERCE_SQL_SYNTAX,
@2); @2);
} }
| a_expr AT LOCAL %prec AT
{
$$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
list_make1($1),
COERCE_SQL_SYNTAX,
-1);
}
/* /*
* These operators must be called out explicitly in order to make use * These operators must be called out explicitly in order to make use
* of bison's automatic operator-precedence handling. All other * of bison's automatic operator-precedence handling. All other

View File

@ -398,9 +398,9 @@ pg_fsync(int fd)
errno = 0; errno = 0;
#endif #endif
/* #if is to skip the sync_method test if there's no need for it */ /* #if is to skip the wal_sync_method test if there's no need for it */
#if defined(HAVE_FSYNC_WRITETHROUGH) #if defined(HAVE_FSYNC_WRITETHROUGH)
if (sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH) if (wal_sync_method == WAL_SYNC_METHOD_FSYNC_WRITETHROUGH)
return pg_fsync_writethrough(fd); return pg_fsync_writethrough(fd);
else else
#endif #endif

View File

@ -3125,3 +3125,18 @@ timetz_izone(PG_FUNCTION_ARGS)
PG_RETURN_TIMETZADT_P(result); PG_RETURN_TIMETZADT_P(result);
} }
/* timetz_at_local()
*
* Unlike for timestamp[tz]_at_local, the type for timetz does not flip between
* time with/without time zone, so we cannot just call the conversion function.
*/
Datum
timetz_at_local(PG_FUNCTION_ARGS)
{
Datum time = PG_GETARG_DATUM(0);
const char *tzn = pg_get_timezone_name(session_timezone);
Datum zone = PointerGetDatum(cstring_to_text(tzn));
return DirectFunctionCall2(timetz_zone, zone, time);
}

View File

@ -10347,6 +10347,16 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
appendStringInfoChar(buf, ')'); appendStringInfoChar(buf, ')');
return true; return true;
case F_TIMEZONE_TIMESTAMP:
case F_TIMEZONE_TIMESTAMPTZ:
case F_TIMEZONE_TIMETZ:
/* AT LOCAL */
appendStringInfoChar(buf, '(');
get_rule_expr_paren((Node *) linitial(expr->args), context, false,
(Node *) expr);
appendStringInfoString(buf, " AT LOCAL)");
return true;
case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_INTERVAL: case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_INTERVAL:
case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_TIMESTAMPTZ: case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_TIMESTAMPTZ:
case F_OVERLAPS_TIMESTAMPTZ_TIMESTAMPTZ_TIMESTAMPTZ_INTERVAL: case F_OVERLAPS_TIMESTAMPTZ_TIMESTAMPTZ_TIMESTAMPTZ_INTERVAL:

View File

@ -5921,3 +5921,23 @@ generate_series_timestamptz_at_zone(PG_FUNCTION_ARGS)
{ {
return generate_series_timestamptz_internal(fcinfo); return generate_series_timestamptz_internal(fcinfo);
} }
/* timestamp_at_local()
* timestamptz_at_local()
*
* The regression tests do not like two functions with the same proargs and
* prosrc but different proname, but the grammar for AT LOCAL needs an
* overloaded name to handle both types of timestamp, so we make simple
* wrappers for it.
*/
Datum
timestamp_at_local(PG_FUNCTION_ARGS)
{
return timestamp_timestamptz(fcinfo);
}
Datum
timestamptz_at_local(PG_FUNCTION_ARGS)
{
return timestamptz_timestamp(fcinfo);
}

View File

@ -485,7 +485,7 @@ static const struct config_enum_entry wal_compression_options[] = {
extern const struct config_enum_entry wal_level_options[]; extern const struct config_enum_entry wal_level_options[];
extern const struct config_enum_entry archive_mode_options[]; extern const struct config_enum_entry archive_mode_options[];
extern const struct config_enum_entry recovery_target_action_options[]; extern const struct config_enum_entry recovery_target_action_options[];
extern const struct config_enum_entry sync_method_options[]; extern const struct config_enum_entry wal_sync_method_options[];
extern const struct config_enum_entry dynamic_shared_memory_options[]; extern const struct config_enum_entry dynamic_shared_memory_options[];
/* /*
@ -4843,9 +4843,9 @@ struct config_enum ConfigureNamesEnum[] =
gettext_noop("Selects the method used for forcing WAL updates to disk."), gettext_noop("Selects the method used for forcing WAL updates to disk."),
NULL NULL
}, },
&sync_method, &wal_sync_method,
DEFAULT_SYNC_METHOD, sync_method_options, DEFAULT_WAL_SYNC_METHOD, wal_sync_method_options,
NULL, assign_xlog_sync_method, NULL NULL, assign_wal_sync_method, NULL
}, },
{ {

View File

@ -4682,6 +4682,12 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches("JOIN")) else if (TailMatches("JOIN"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
/* ... AT [ LOCAL | TIME ZONE ] ... */
else if (TailMatches("AT"))
COMPLETE_WITH("LOCAL", "TIME ZONE");
else if (TailMatches("AT", "TIME", "ZONE"))
COMPLETE_WITH_TIMEZONE_NAME();
/* Backslash commands */ /* Backslash commands */
/* TODO: \dc \dd \dl */ /* TODO: \dc \dd \dl */
else if (TailMatchesCS("\\?")) else if (TailMatchesCS("\\?"))

View File

@ -19,12 +19,15 @@
/* Sync methods */ /* Sync methods */
#define SYNC_METHOD_FSYNC 0 typedef enum WalSyncMethod
#define SYNC_METHOD_FDATASYNC 1 {
#define SYNC_METHOD_OPEN 2 /* for O_SYNC */ WAL_SYNC_METHOD_FSYNC = 0,
#define SYNC_METHOD_FSYNC_WRITETHROUGH 3 WAL_SYNC_METHOD_FDATASYNC,
#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */ WAL_SYNC_METHOD_OPEN, /* for O_SYNC */
extern PGDLLIMPORT int sync_method; WAL_SYNC_METHOD_FSYNC_WRITETHROUGH,
WAL_SYNC_METHOD_OPEN_DSYNC /* for O_DSYNC */
} WalSyncMethod;
extern PGDLLIMPORT int wal_sync_method;
extern PGDLLIMPORT XLogRecPtr ProcLastRecPtr; extern PGDLLIMPORT XLogRecPtr ProcLastRecPtr;
extern PGDLLIMPORT XLogRecPtr XactLastRecEnd; extern PGDLLIMPORT XLogRecPtr XactLastRecEnd;

View File

@ -71,12 +71,12 @@ typedef uint16 RepOriginId;
* *
* Note that we define our own O_DSYNC on Windows, but not O_SYNC. * Note that we define our own O_DSYNC on Windows, but not O_SYNC.
*/ */
#if defined(PLATFORM_DEFAULT_SYNC_METHOD) #if defined(PLATFORM_DEFAULT_WAL_SYNC_METHOD)
#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD #define DEFAULT_WAL_SYNC_METHOD PLATFORM_DEFAULT_WAL_SYNC_METHOD
#elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC) #elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC)
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC #define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_OPEN_DSYNC
#else #else
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC #define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC
#endif #endif
#endif /* XLOG_DEFS_H */ #endif /* XLOG_DEFS_H */

View File

@ -57,6 +57,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 202309251 #define CATALOG_VERSION_NO 202310131
#endif #endif

View File

@ -2319,6 +2319,9 @@
{ oid => '1159', descr => 'adjust timestamp to new time zone', { oid => '1159', descr => 'adjust timestamp to new time zone',
proname => 'timezone', prorettype => 'timestamp', proname => 'timezone', prorettype => 'timestamp',
proargtypes => 'text timestamptz', prosrc => 'timestamptz_zone' }, proargtypes => 'text timestamptz', prosrc => 'timestamptz_zone' },
{ oid => '9159', descr => 'adjust timestamp to local time zone',
proname => 'timezone', provolatile => 's', prorettype => 'timestamp',
proargtypes => 'timestamptz', prosrc => 'timestamptz_at_local' },
{ oid => '1160', descr => 'I/O', { oid => '1160', descr => 'I/O',
proname => 'interval_in', provolatile => 's', prorettype => 'interval', proname => 'interval_in', provolatile => 's', prorettype => 'interval',
@ -6095,6 +6098,9 @@
{ oid => '2038', descr => 'adjust time with time zone to new zone', { oid => '2038', descr => 'adjust time with time zone to new zone',
proname => 'timezone', prorettype => 'timetz', proname => 'timezone', prorettype => 'timetz',
proargtypes => 'interval timetz', prosrc => 'timetz_izone' }, proargtypes => 'interval timetz', prosrc => 'timetz_izone' },
{ oid => '9161', descr => 'adjust time to local time zone',
proname => 'timezone', provolatile => 's', prorettype => 'timetz',
proargtypes => 'timetz', prosrc => 'timetz_at_local' },
{ oid => '2039', descr => 'hash', { oid => '2039', descr => 'hash',
proname => 'timestamp_hash', prorettype => 'int4', proargtypes => 'timestamp', proname => 'timestamp_hash', prorettype => 'int4', proargtypes => 'timestamp',
prosrc => 'timestamp_hash' }, prosrc => 'timestamp_hash' },
@ -6190,6 +6196,9 @@
{ oid => '2070', descr => 'adjust timestamp to new time zone', { oid => '2070', descr => 'adjust timestamp to new time zone',
proname => 'timezone', prorettype => 'timestamptz', proname => 'timezone', prorettype => 'timestamptz',
proargtypes => 'interval timestamp', prosrc => 'timestamp_izone' }, proargtypes => 'interval timestamp', prosrc => 'timestamp_izone' },
{ oid => '9160', descr => 'adjust timestamp to local time zone',
proname => 'timezone', provolatile => 's', prorettype => 'timestamptz',
proargtypes => 'timestamp', prosrc => 'timestamp_at_local' },
{ oid => '2071', { oid => '2071',
proname => 'date_pl_interval', prorettype => 'timestamp', proname => 'date_pl_interval', prorettype => 'timestamp',
proargtypes => 'date interval', prosrc => 'date_pl_interval' }, proargtypes => 'date interval', prosrc => 'date_pl_interval' },

View File

@ -5,4 +5,4 @@
* would prefer open_datasync on FreeBSD 13+, but that is not a good choice on * would prefer open_datasync on FreeBSD 13+, but that is not a good choice on
* many systems. * many systems.
*/ */
#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC #define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC

View File

@ -19,4 +19,4 @@
* perform better and (b) causes outright failures on ext4 data=journal * perform better and (b) causes outright failures on ext4 data=journal
* filesystems, because those don't support O_DIRECT. * filesystems, because those don't support O_DIRECT.
*/ */
#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC #define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC

View File

@ -159,6 +159,6 @@ extern bool check_wal_consistency_checking(char **newval, void **extra,
GucSource source); GucSource source);
extern void assign_wal_consistency_checking(const char *newval, void *extra); extern void assign_wal_consistency_checking(const char *newval, void *extra);
extern bool check_wal_segment_size(int *newval, void **extra, GucSource source); extern bool check_wal_segment_size(int *newval, void **extra, GucSource source);
extern void assign_xlog_sync_method(int new_sync_method, void *extra); extern void assign_wal_sync_method(int new_wal_sync_method, void *extra);
#endif /* GUC_HOOKS_H */ #endif /* GUC_HOOKS_H */

View File

@ -257,3 +257,40 @@ ERROR: value too long for type character varying(5)
\. \.
invalid command \. invalid command \.
drop table oversized_column_default; drop table oversized_column_default;
--
-- Create partitioned table that does not allow bulk insertions, to test bugs
-- related to the reuse of BulkInsertState across partitions (only done when
-- not using bulk insert). Switching between partitions often makes it more
-- likely to encounter these bugs, so we just switch on roughly every insert
-- by having an even/odd number partition and inserting evenly distributed
-- data.
--
CREATE TABLE parted_si (
id int not null,
data text not null,
-- prevent use of bulk insert by having a volatile function
rand float8 not null default random()
)
PARTITION BY LIST((id % 2));
CREATE TABLE parted_si_p_even PARTITION OF parted_si FOR VALUES IN (0);
CREATE TABLE parted_si_p_odd PARTITION OF parted_si FOR VALUES IN (1);
-- Test that bulk relation extension handles reusing a single BulkInsertState
-- across partitions. Without the fix applied, this reliably reproduces
-- #18130 unless shared_buffers is extremely small (preventing any use use of
-- bulk relation extension). See
-- https://postgr.es/m/18130-7a86a7356a75209d%40postgresql.org
-- https://postgr.es/m/257696.1695670946%40sss.pgh.pa.us
\set filename :abs_srcdir '/data/desc.data'
COPY parted_si(id, data) FROM :'filename';
-- An earlier bug (see commit b1ecb9b3fcf) could end up using a buffer from
-- the wrong partition. This test is *not* guaranteed to trigger that bug, but
-- does so when shared_buffers is small enough. To test if we encountered the
-- bug, check that the partition condition isn't violated.
SELECT tableoid::regclass, id % 2 = 0 is_even, count(*) from parted_si GROUP BY 1, 2 ORDER BY 1;
tableoid | is_even | count
------------------+---------+-------
parted_si_p_even | t | 5000
parted_si_p_odd | f | 5000
(2 rows)
DROP TABLE parted_si;

View File

@ -3135,6 +3135,62 @@ SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK';
Sun Oct 26 02:00:00 2014 Sun Oct 26 02:00:00 2014
(1 row) (1 row)
--
-- Test LOCAL time zone
--
BEGIN;
SET LOCAL TIME ZONE 'Europe/Paris';
VALUES (CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL);
column1
--------------------------
Sat Jul 08 01:38:00 1978
(1 row)
VALUES (TIMESTAMP '1978-07-07 19:38' AT LOCAL);
column1
-------------------------------
Fri Jul 07 19:38:00 1978 CEST
(1 row)
SET LOCAL TIME ZONE 'Australia/Sydney';
VALUES (CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL);
column1
--------------------------
Sat Jul 08 09:38:00 1978
(1 row)
VALUES (TIMESTAMP '1978-07-07 19:38' AT LOCAL);
column1
-------------------------------
Fri Jul 07 19:38:00 1978 AEST
(1 row)
SET LOCAL TimeZone TO 'UTC';
CREATE VIEW timestamp_local_view AS
SELECT CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL AS ttz_at_local,
timezone(CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE)) AS ttz_func,
TIMESTAMP '1978-07-07 19:38' AT LOCAL AS t_at_local,
timezone(TIMESTAMP '1978-07-07 19:38') AS t_func;
SELECT pg_get_viewdef('timestamp_local_view', true);
pg_get_viewdef
----------------------------------------------------------------------------------------------
SELECT ('Fri Jul 07 23:38:00 1978 UTC'::timestamp with time zone AT LOCAL) AS ttz_at_local,+
timezone('Fri Jul 07 23:38:00 1978 UTC'::timestamp with time zone) AS ttz_func, +
('Fri Jul 07 19:38:00 1978'::timestamp without time zone AT LOCAL) AS t_at_local, +
timezone('Fri Jul 07 19:38:00 1978'::timestamp without time zone) AS t_func;
(1 row)
\x
TABLE timestamp_local_view;
-[ RECORD 1 ]+-----------------------------
ttz_at_local | Fri Jul 07 23:38:00 1978
ttz_func | Fri Jul 07 23:38:00 1978
t_at_local | Fri Jul 07 19:38:00 1978 UTC
t_func | Fri Jul 07 19:38:00 1978 UTC
\x
DROP VIEW timestamp_local_view;
COMMIT;
-- --
-- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504)
-- --

View File

@ -262,3 +262,45 @@ SELECT date_part('epoch', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-
63025.575401 63025.575401
(1 row) (1 row)
--
-- AT LOCAL with timetz
--
BEGIN;
SET LOCAL TimeZone TO 'UTC';
CREATE VIEW timetz_local_view AS
SELECT f1 AS dat,
timezone(f1) AS dat_func,
f1 AT LOCAL AS dat_at_local,
f1 AT TIME ZONE current_setting('TimeZone') AS dat_at_time
FROM TIMETZ_TBL
ORDER BY f1;
SELECT pg_get_viewdef('timetz_local_view', true);
pg_get_viewdef
------------------------------------------------------------------------
SELECT f1 AS dat, +
timezone(f1) AS dat_func, +
(f1 AT LOCAL) AS dat_at_local, +
(f1 AT TIME ZONE current_setting('TimeZone'::text)) AS dat_at_time+
FROM timetz_tbl +
ORDER BY f1;
(1 row)
TABLE timetz_local_view;
dat | dat_func | dat_at_local | dat_at_time
----------------+----------------+----------------+----------------
00:01:00-07 | 07:01:00+00 | 07:01:00+00 | 07:01:00+00
01:00:00-07 | 08:00:00+00 | 08:00:00+00 | 08:00:00+00
02:03:00-07 | 09:03:00+00 | 09:03:00+00 | 09:03:00+00
08:08:00-04 | 12:08:00+00 | 12:08:00+00 | 12:08:00+00
07:07:00-08 | 15:07:00+00 | 15:07:00+00 | 15:07:00+00
11:59:00-07 | 18:59:00+00 | 18:59:00+00 | 18:59:00+00
12:00:00-07 | 19:00:00+00 | 19:00:00+00 | 19:00:00+00
12:01:00-07 | 19:01:00+00 | 19:01:00+00 | 19:01:00+00
15:36:39-04 | 19:36:39+00 | 19:36:39+00 | 19:36:39+00
15:36:39-05 | 20:36:39+00 | 20:36:39+00 | 20:36:39+00
23:59:00-07 | 06:59:00+00 | 06:59:00+00 | 06:59:00+00
23:59:59.99-07 | 06:59:59.99+00 | 06:59:59.99+00 | 06:59:59.99+00
(12 rows)
DROP VIEW timetz_local_view;
COMMIT;

View File

@ -283,3 +283,40 @@ copy oversized_column_default (col2) from stdin;
copy oversized_column_default from stdin (default ''); copy oversized_column_default from stdin (default '');
\. \.
drop table oversized_column_default; drop table oversized_column_default;
--
-- Create partitioned table that does not allow bulk insertions, to test bugs
-- related to the reuse of BulkInsertState across partitions (only done when
-- not using bulk insert). Switching between partitions often makes it more
-- likely to encounter these bugs, so we just switch on roughly every insert
-- by having an even/odd number partition and inserting evenly distributed
-- data.
--
CREATE TABLE parted_si (
id int not null,
data text not null,
-- prevent use of bulk insert by having a volatile function
rand float8 not null default random()
)
PARTITION BY LIST((id % 2));
CREATE TABLE parted_si_p_even PARTITION OF parted_si FOR VALUES IN (0);
CREATE TABLE parted_si_p_odd PARTITION OF parted_si FOR VALUES IN (1);
-- Test that bulk relation extension handles reusing a single BulkInsertState
-- across partitions. Without the fix applied, this reliably reproduces
-- #18130 unless shared_buffers is extremely small (preventing any use use of
-- bulk relation extension). See
-- https://postgr.es/m/18130-7a86a7356a75209d%40postgresql.org
-- https://postgr.es/m/257696.1695670946%40sss.pgh.pa.us
\set filename :abs_srcdir '/data/desc.data'
COPY parted_si(id, data) FROM :'filename';
-- An earlier bug (see commit b1ecb9b3fcf) could end up using a buffer from
-- the wrong partition. This test is *not* guaranteed to trigger that bug, but
-- does so when shared_buffers is small enough. To test if we encountered the
-- bug, check that the partition condition isn't violated.
SELECT tableoid::regclass, id % 2 = 0 is_even, count(*) from parted_si GROUP BY 1, 2 ORDER BY 1;
DROP TABLE parted_si;

View File

@ -611,6 +611,29 @@ SELECT '2014-10-25 22:00:00 UTC'::timestamptz AT TIME ZONE 'MSK';
SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'MSK';
SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK';
--
-- Test LOCAL time zone
--
BEGIN;
SET LOCAL TIME ZONE 'Europe/Paris';
VALUES (CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL);
VALUES (TIMESTAMP '1978-07-07 19:38' AT LOCAL);
SET LOCAL TIME ZONE 'Australia/Sydney';
VALUES (CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL);
VALUES (TIMESTAMP '1978-07-07 19:38' AT LOCAL);
SET LOCAL TimeZone TO 'UTC';
CREATE VIEW timestamp_local_view AS
SELECT CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE) AT LOCAL AS ttz_at_local,
timezone(CAST('1978-07-07 19:38 America/New_York' AS TIMESTAMP WITH TIME ZONE)) AS ttz_func,
TIMESTAMP '1978-07-07 19:38' AT LOCAL AS t_at_local,
timezone(TIMESTAMP '1978-07-07 19:38') AS t_func;
SELECT pg_get_viewdef('timestamp_local_view', true);
\x
TABLE timestamp_local_view;
\x
DROP VIEW timestamp_local_view;
COMMIT;
-- --
-- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504)
-- --

View File

@ -84,3 +84,20 @@ SELECT date_part('microsecond', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-
SELECT date_part('millisecond', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04'); SELECT date_part('millisecond', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04');
SELECT date_part('second', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04'); SELECT date_part('second', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04');
SELECT date_part('epoch', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04'); SELECT date_part('epoch', TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04');
--
-- AT LOCAL with timetz
--
BEGIN;
SET LOCAL TimeZone TO 'UTC';
CREATE VIEW timetz_local_view AS
SELECT f1 AS dat,
timezone(f1) AS dat_func,
f1 AT LOCAL AS dat_at_local,
f1 AT TIME ZONE current_setting('TimeZone') AS dat_at_time
FROM TIMETZ_TBL
ORDER BY f1;
SELECT pg_get_viewdef('timetz_local_view', true);
TABLE timetz_local_view;
DROP VIEW timetz_local_view;
COMMIT;

View File

@ -3016,6 +3016,7 @@ WalSnd
WalSndCtlData WalSndCtlData
WalSndSendDataCallback WalSndSendDataCallback
WalSndState WalSndState
WalSyncMethod
WalTimeSample WalTimeSample
WalUsage WalUsage
WalWriteMethod WalWriteMethod