Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit760c770

Browse files
committed
Add convenience functions pg_sleep_for and pg_sleep_until.
Vik Fearing, reviewed by Pavel Stehule and myself
1 parent043f6ff commit760c770

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7664,20 +7664,28 @@ SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT
76647664
</indexterm>
76657665

76667666
<para>
7667-
The followingfunction is available to delay execution of the server
7667+
The followingfunctions are available to delay execution of the server
76687668
process:
76697669
<synopsis>
76707670
pg_sleep(<replaceable>seconds</replaceable>)
7671+
pg_sleep_for(<type>interval</>)
7672+
pg_sleep_until(<type>timestamp with time zone</>)
76717673
</synopsis>
76727674

76737675
<function>pg_sleep</function> makes the current session's process
76747676
sleep until <replaceable>seconds</replaceable> seconds have
76757677
elapsed. <replaceable>seconds</replaceable> is a value of type
76767678
<type>double precision</>, so fractional-second delays can be specified.
7679+
<function>pg_sleep_for</function> is a convenience function for larger
7680+
sleep times specified as an <type>interval</>.
7681+
<function>pg_sleep_until</function> is a convenience function for when
7682+
a specific wake-up time is desired.
76777683
For example:
76787684

76797685
<programlisting>
76807686
SELECT pg_sleep(1.5);
7687+
SELECT pg_sleep_for('5 minutes');
7688+
SELECT pg_sleep_until('tomorrow 03:00');
76817689
</programlisting>
76827690
</para>
76837691

@@ -7686,15 +7694,17 @@ SELECT pg_sleep(1.5);
76867694
The effective resolution of the sleep interval is platform-specific;
76877695
0.01 seconds is a common value. The sleep delay will be at least as long
76887696
as specified. It might be longer depending on factors such as server load.
7697+
In particular, <function>pg_sleep_until</function> is not guaranteed to
7698+
wake up exactly at the specified time, but it will not wake up any earlier.
76897699
</para>
76907700
</note>
76917701

76927702
<warning>
76937703
<para>
76947704
Make sure that your session does not hold more locks than necessary
7695-
when calling <function>pg_sleep</function>. Otherwise other sessions
7696-
might have to wait for your sleeping process, slowing down the entire
7697-
system.
7705+
when calling <function>pg_sleep</function> or its variants. Otherwise
7706+
other sessionsmight have to wait for your sleeping process, slowing down
7707+
the entiresystem.
76987708
</para>
76997709
</warning>
77007710
</sect2>

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201401291
56+
#defineCATALOG_VERSION_NO201401301
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,10 @@ DATA(insert OID = 2625 ( pg_ls_dirPGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0
30343034
DESCR("list all files in a directory");
30353035
DATA(insertOID=2626 (pg_sleepPGNSPPGUID121000fffftfv102278"701"_null__null__null__null_pg_sleep_null__null__null_ ));
30363036
DESCR("sleep for the specified time in seconds");
3037+
DATA(insertOID=3935 (pg_sleep_forPGNSPPGUID141000fffftfv102278"1186"_null__null__null__null_"select pg_catalog.pg_sleep(extract(epoch from pg_catalog.now() operator(pg_catalog.+) $1) operator(pg_catalog.-) extract(epoch from pg_catalog.now()))"_null__null__null_ ));
3038+
DESCR("sleep for the specified interval");
3039+
DATA(insertOID=3936 (pg_sleep_untilPGNSPPGUID141000fffftfv102278"1184"_null__null__null__null_"select pg_catalog.pg_sleep(extract(epoch from $1) operator(pg_catalog.-) extract(epoch from pg_catalog.now()))"_null__null__null_ ));
3040+
DESCR("sleep until the specified time");
30373041

30383042
DATA(insertOID=2971 (textPGNSPPGUID121000fffftfi1025"16"_null__null__null__null_booltext_null__null__null_ ));
30393043
DESCR("convert boolean to text");

‎src/test/regress/expected/stats.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ SET enable_indexscan TO on;
1818
SET enable_indexonlyscan TO off;
1919
-- wait to let any prior tests finish dumping out stats;
2020
-- else our messages might get lost due to contention
21-
SELECTpg_sleep(2.0);
22-
pg_sleep
23-
----------
21+
SELECTpg_sleep_for('2 seconds');
22+
pg_sleep_for
23+
--------------
2424

2525
(1 row)
2626

‎src/test/regress/sql/stats.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SET enable_indexonlyscan TO off;
1616

1717
-- wait to let any prior tests finish dumping out stats;
1818
-- else our messages might get lost due to contention
19-
SELECTpg_sleep(2.0);
19+
SELECTpg_sleep_for('2 seconds');
2020

2121
-- save counters
2222
CREATE TEMP TABLE prevstatsAS

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp