|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.338 2006/09/16 00:30:13 momjian Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.339 2006/09/20 23:43:21 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="functions">
|
4 | 4 | <title>Functions and Operators</title>
|
@@ -10577,15 +10577,205 @@ postgres=# select * from pg_xlogfile_name_offset(pg_stop_backup());
|
10577 | 10577 | </indexterm>
|
10578 | 10578 | <para>
|
10579 | 10579 | <function>pg_stat_file</> returns a record containing the file
|
10580 |
| - size, last accessed time stamp, last modified time stamp, |
10581 |
| - last file status change time stamp (Unix platforms only), |
10582 |
| - file creation timestamp (Windows only), and a <type>boolean</type> indicating |
10583 |
| - if it is a directory. Typical usages include: |
| 10580 | + size, last accessed time stamp, last modified time stamp, |
| 10581 | + last file status change time stamp (Unix platforms only), |
| 10582 | + file creation timestamp (Windows only), and a <type>boolean</type> |
| 10583 | + indicating if it is a directory. Typical usages include: |
10584 | 10584 | <programlisting>
|
10585 | 10585 | SELECT * FROM pg_stat_file('filename');
|
10586 | 10586 | SELECT (pg_stat_file('filename')).modification;
|
10587 | 10587 | </programlisting>
|
10588 | 10588 | </para>
|
10589 | 10589 |
|
| 10590 | + <para> |
| 10591 | + The functions shown in <xref linkend="functions-advisory-locks"> manage |
| 10592 | + advisory locks. For details about proper usage of these functions, see |
| 10593 | + <xref linkend="advisory-locks">. |
| 10594 | + </para> |
| 10595 | + |
| 10596 | + <table id="functions-advisory-locks"> |
| 10597 | + <title>Advisory Lock Functions</title> |
| 10598 | + <tgroup cols="3"> |
| 10599 | + <thead> |
| 10600 | + <row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry> |
| 10601 | + </row> |
| 10602 | + </thead> |
| 10603 | + |
| 10604 | + <tbody> |
| 10605 | + <row> |
| 10606 | + <entry> |
| 10607 | + <literal><function>pg_advisory_lock</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10608 | + </entry> |
| 10609 | + <entry><type>void</type></entry> |
| 10610 | + <entry>Obtain exclusive advisory lock</entry> |
| 10611 | + </row> |
| 10612 | + <row> |
| 10613 | + <entry> |
| 10614 | + <literal><function>pg_advisory_lock</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10615 | + </entry> |
| 10616 | + <entry><type>void</type></entry> |
| 10617 | + <entry>Obtain exclusive advisory lock</entry> |
| 10618 | + </row> |
| 10619 | + |
| 10620 | + <row> |
| 10621 | + <entry> |
| 10622 | + <literal><function>pg_advisory_lock_shared</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10623 | + </entry> |
| 10624 | + <entry><type>void</type></entry> |
| 10625 | + <entry>Obtain shared advisory lock</entry> |
| 10626 | + </row> |
| 10627 | + <row> |
| 10628 | + <entry> |
| 10629 | + <literal><function>pg_advisory_lock_shared</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10630 | + </entry> |
| 10631 | + <entry><type>void</type></entry> |
| 10632 | + <entry>Obtain shared advisory lock</entry> |
| 10633 | + </row> |
| 10634 | + |
| 10635 | + <row> |
| 10636 | + <entry> |
| 10637 | + <literal><function>pg_try_advisory_lock</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10638 | + </entry> |
| 10639 | + <entry><type>boolean</type></entry> |
| 10640 | + <entry>Obtain exclusive advisory lock if available</entry> |
| 10641 | + </row> |
| 10642 | + <row> |
| 10643 | + <entry> |
| 10644 | + <literal><function>pg_try_advisory_lock</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10645 | + </entry> |
| 10646 | + <entry><type>boolean</type></entry> |
| 10647 | + <entry>Obtain exclusive advisory lock if available</entry> |
| 10648 | + </row> |
| 10649 | + |
| 10650 | + <row> |
| 10651 | + <entry> |
| 10652 | + <literal><function>pg_try_advisory_lock_shared</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10653 | + </entry> |
| 10654 | + <entry><type>boolean</type></entry> |
| 10655 | + <entry>Obtain shared advisory lock if available</entry> |
| 10656 | + </row> |
| 10657 | + <row> |
| 10658 | + <entry> |
| 10659 | + <literal><function>pg_try_advisory_lock_shared</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10660 | + </entry> |
| 10661 | + <entry><type>boolean</type></entry> |
| 10662 | + <entry>Obtain shared advisory lock if available</entry> |
| 10663 | + </row> |
| 10664 | + |
| 10665 | + <row> |
| 10666 | + <entry> |
| 10667 | + <literal><function>pg_advisory_unlock</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10668 | + </entry> |
| 10669 | + <entry><type>boolean</type></entry> |
| 10670 | + <entry>Release an exclusive advisory lock</entry> |
| 10671 | + </row> |
| 10672 | + <row> |
| 10673 | + <entry> |
| 10674 | + <literal><function>pg_advisory_unlock</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10675 | + </entry> |
| 10676 | + <entry><type>boolean</type></entry> |
| 10677 | + <entry>Release an exclusive advisory lock</entry> |
| 10678 | + </row> |
| 10679 | + |
| 10680 | + <row> |
| 10681 | + <entry> |
| 10682 | + <literal><function>pg_advisory_unlock_shared</function>(<parameter>key</> <type>bigint</>)</literal> |
| 10683 | + </entry> |
| 10684 | + <entry><type>boolean</type></entry> |
| 10685 | + <entry>Release a shared advisory lock</entry> |
| 10686 | + </row> |
| 10687 | + <row> |
| 10688 | + <entry> |
| 10689 | + <literal><function>pg_advisory_unlock_shared</function>(<parameter>key1</> <type>int</>, <parameter>key2</> <type>int</>)</literal> |
| 10690 | + </entry> |
| 10691 | + <entry><type>boolean</type></entry> |
| 10692 | + <entry>Release a shared advisory lock</entry> |
| 10693 | + </row> |
| 10694 | + |
| 10695 | + <row> |
| 10696 | + <entry> |
| 10697 | + <literal><function>pg_advisory_unlock_all</function>()</literal> |
| 10698 | + </entry> |
| 10699 | + <entry><type>void</type></entry> |
| 10700 | + <entry>Release all advisory locks held by the current session</entry> |
| 10701 | + </row> |
| 10702 | + |
| 10703 | + </tbody> |
| 10704 | + </tgroup> |
| 10705 | + </table> |
| 10706 | + |
| 10707 | + <indexterm zone="functions-admin"> |
| 10708 | + <primary>pg_advisory_lock</primary> |
| 10709 | + </indexterm> |
| 10710 | + <para> |
| 10711 | + <function>pg_advisory_lock</> locks an application-defined resource, |
| 10712 | + which may be identified either by a single 64-bit key value or two |
| 10713 | + 32-bit key values (note that these two key spaces do not overlap). If |
| 10714 | + another session already holds a lock on the same resource, the |
| 10715 | + function will wait until the resource becomes available. The lock |
| 10716 | + is exclusive. Multiple lock requests stack, so that if the same resource |
| 10717 | + is locked three times it must be also unlocked three times to be |
| 10718 | + released for other sessions' use. |
| 10719 | + </para> |
| 10720 | + |
| 10721 | + <indexterm zone="functions-admin"> |
| 10722 | + <primary>pg_advisory_lock_shared</primary> |
| 10723 | + </indexterm> |
| 10724 | + <para> |
| 10725 | + <function>pg_advisory_lock_shared</> works the same as |
| 10726 | + <function>pg_advisory_lock</>, |
| 10727 | + except the lock can be shared with other sessions requesting shared locks. |
| 10728 | + Only would-be exclusive lockers are locked out. |
| 10729 | + </para> |
| 10730 | + |
| 10731 | + <indexterm zone="functions-admin"> |
| 10732 | + <primary>pg_try_advisory_lock</primary> |
| 10733 | + </indexterm> |
| 10734 | + <para> |
| 10735 | + <function>pg_try_advisory_lock</> is similar to |
| 10736 | + <function>pg_advisory_lock</>, except the function will not wait for the |
| 10737 | + lock to become available. It will either obtain the lock immediately and |
| 10738 | + return <literal>true</>, or return <literal>false</> if the lock cannot be |
| 10739 | + acquired now. |
| 10740 | + </para> |
| 10741 | + |
| 10742 | + <indexterm zone="functions-admin"> |
| 10743 | + <primary>pg_try_advisory_lock_shared</primary> |
| 10744 | + </indexterm> |
| 10745 | + <para> |
| 10746 | + <function>pg_try_advisory_lock_shared</> works the same as |
| 10747 | + <function>pg_try_advisory_lock</>, except it attempts to acquire |
| 10748 | + shared rather than exclusive lock. |
| 10749 | + </para> |
| 10750 | + |
| 10751 | + <indexterm zone="functions-admin"> |
| 10752 | + <primary>pg_advisory_unlock</primary> |
| 10753 | + </indexterm> |
| 10754 | + <para> |
| 10755 | + <function>pg_advisory_unlock</> will release a previously-acquired |
| 10756 | + exclusive advisory lock. It |
| 10757 | + will return <literal>true</> if the lock is successfully released. |
| 10758 | + If the lock was in fact not held, it will return <literal>false</>, |
| 10759 | + and in addition, an SQL warning will be raised by the server. |
| 10760 | + </para> |
| 10761 | + |
| 10762 | + <indexterm zone="functions-admin"> |
| 10763 | + <primary>pg_advisory_unlock_shared</primary> |
| 10764 | + </indexterm> |
| 10765 | + <para> |
| 10766 | + <function>pg_advisory_unlock_shared</> works the same as |
| 10767 | + <function>pg_advisory_unlock</>, |
| 10768 | + except to release a shared advisory lock. |
| 10769 | + </para> |
| 10770 | + |
| 10771 | + <indexterm zone="functions-admin"> |
| 10772 | + <primary>pg_advisory_unlock_all</primary> |
| 10773 | + </indexterm> |
| 10774 | + <para> |
| 10775 | + <function>pg_advisory_unlock_all</> will release all advisory locks |
| 10776 | + held by the current session. (This function is implicitly invoked |
| 10777 | + at session end, even if the client disconnects ungracefully.) |
| 10778 | + </para> |
| 10779 | + |
10590 | 10780 | </sect1>
|
10591 | 10781 | </chapter>
|
0 commit comments