*** a/contrib/pg_trgm/pg_trgm--1.2.sql
--- b/contrib/pg_trgm/pg_trgm--1.2.sql
***************
*** 3,13 ****
--- 3,15 ----
  -- complain if script is sourced in psql, rather than via CREATE EXTENSION
  \echo Use "CREATE EXTENSION pg_trgm" to load this file. \quit
  
+ -- Deprecated function
  CREATE FUNCTION set_limit(float4)
  RETURNS float4
  AS 'MODULE_PATHNAME'
  LANGUAGE C STRICT VOLATILE;
  
+ -- Deprecated function
  CREATE FUNCTION show_limit()
  RETURNS float4
  AS 'MODULE_PATHNAME'
***************
*** 26,32 **** LANGUAGE C STRICT IMMUTABLE;
  CREATE FUNCTION similarity_op(text,text)
  RETURNS bool
  AS 'MODULE_PATHNAME'
! LANGUAGE C STRICT STABLE;  -- stable because depends on trgm_limit
  
  CREATE OPERATOR % (
          LEFTARG = text,
--- 28,34 ----
  CREATE FUNCTION similarity_op(text,text)
  RETURNS bool
  AS 'MODULE_PATHNAME'
! LANGUAGE C STRICT STABLE;  -- stable because depends on pg_trgm.limit
  
  CREATE OPERATOR % (
          LEFTARG = text,
*** a/contrib/pg_trgm/trgm.h
--- b/contrib/pg_trgm/trgm.h
***************
*** 105,111 **** typedef char *BITVECP;
  
  typedef struct TrgmPackedGraph TrgmPackedGraph;
  
! extern float4 trgm_limit;
  
  extern uint32 trgm2int(trgm *ptr);
  extern void compact_trigram(trgm *tptr, char *str, int bytelen);
--- 105,111 ----
  
  typedef struct TrgmPackedGraph TrgmPackedGraph;
  
! extern double trgm_limit;
  
  extern uint32 trgm2int(trgm *ptr);
  extern void compact_trigram(trgm *tptr, char *str, int bytelen);
*** a/contrib/pg_trgm/trgm_op.c
--- b/contrib/pg_trgm/trgm_op.c
***************
*** 14,20 ****
  
  PG_MODULE_MAGIC;
  
! float4		trgm_limit = 0.3f;
  
  PG_FUNCTION_INFO_V1(set_limit);
  PG_FUNCTION_INFO_V1(show_limit);
--- 14,23 ----
  
  PG_MODULE_MAGIC;
  
! /* GUC variables */
! double		trgm_limit = 0.3f;
! 
! void		_PG_init(void);
  
  PG_FUNCTION_INFO_V1(set_limit);
  PG_FUNCTION_INFO_V1(show_limit);
***************
*** 23,40 **** PG_FUNCTION_INFO_V1(similarity);
  PG_FUNCTION_INFO_V1(similarity_dist);
  PG_FUNCTION_INFO_V1(similarity_op);
  
  
  Datum
  set_limit(PG_FUNCTION_ARGS)
  {
  	float4		nlimit = PG_GETARG_FLOAT4(0);
  
  	if (nlimit < 0 || nlimit > 1.0)
! 		elog(ERROR, "wrong limit, should be between 0 and 1");
  	trgm_limit = nlimit;
  	PG_RETURN_FLOAT4(trgm_limit);
  }
  
  Datum
  show_limit(PG_FUNCTION_ARGS)
  {
--- 26,73 ----
  PG_FUNCTION_INFO_V1(similarity_dist);
  PG_FUNCTION_INFO_V1(similarity_op);
  
+ /*
+  * Module load callback
+  */
+ void
+ _PG_init(void)
+ {
+ 	/* Define custom GUC variables. */
+ 	DefineCustomRealVariable("pg_trgm.limit",
+ 							"Sets the threshold used by the %% operator.",
+ 							"Valid range is 0.0 .. 1.0.",
+ 							&trgm_limit,
+ 							0.3,
+ 							0.0,
+ 							1.0,
+ 							PGC_USERSET,
+ 							0,
+ 							NULL,
+ 							NULL,
+ 							NULL);
+ }
  
+ /*
+  * Deprecated function.
+  * Use "pg_trgm.limit" GUC variable instead of this function
+  */
  Datum
  set_limit(PG_FUNCTION_ARGS)
  {
  	float4		nlimit = PG_GETARG_FLOAT4(0);
  
  	if (nlimit < 0 || nlimit > 1.0)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
! 				 errmsg("wrong limit, should be between 0 and 1")));
  	trgm_limit = nlimit;
  	PG_RETURN_FLOAT4(trgm_limit);
  }
  
+ /*
+  * Deprecated function.
+  * Use "pg_trgm.limit" GUC variable instead of this function
+  */
  Datum
  show_limit(PG_FUNCTION_ARGS)
  {
*** a/doc/src/sgml/pgtrgm.sgml
--- b/doc/src/sgml/pgtrgm.sgml
***************
*** 99,105 ****
         Returns the current similarity threshold used by the <literal>%</>
         operator.  This sets the minimum similarity between
         two words for them to be considered similar enough to
!        be misspellings of each other, for example.
        </entry>
       </row>
       <row>
--- 99,106 ----
         Returns the current similarity threshold used by the <literal>%</>
         operator.  This sets the minimum similarity between
         two words for them to be considered similar enough to
!        be misspellings of each other, for example
!        (<emphasis>deprecated</emphasis>).
        </entry>
       </row>
       <row>
***************
*** 108,114 ****
        <entry>
         Sets the current similarity threshold that is used by the <literal>%</>
         operator.  The threshold must be between 0 and 1 (default is 0.3).
!        Returns the same value passed in.
        </entry>
       </row>
      </tbody>
--- 109,115 ----
        <entry>
         Sets the current similarity threshold that is used by the <literal>%</>
         operator.  The threshold must be between 0 and 1 (default is 0.3).
!        Returns the same value passed in (<emphasis>deprecated</emphasis>).
        </entry>
       </row>
      </tbody>
***************
*** 133,139 ****
        <entry>
         Returns <literal>true</> if its arguments have a similarity that is
         greater than the current similarity threshold set by
!        <function>set_limit</>.
        </entry>
       </row>
       <row>
--- 134,140 ----
        <entry>
         Returns <literal>true</> if its arguments have a similarity that is
         greater than the current similarity threshold set by
!        <varname>pg_trgm.limit</>.
        </entry>
       </row>
       <row>
***************
*** 150,155 ****
--- 151,177 ----
   </sect2>
  
   <sect2>
+   <title>GUC Parameters</title>
+ 
+   <variablelist>
+    <varlistentry id="guc-pgtrgm-limit" xreflabel="pg_trgm.limit">
+     <term>
+      <varname>pg_trgm.limit</> (<type>real</type>)
+      <indexterm>
+       <primary><varname>pg_trgm.limit</> configuration parameter</primary>
+      </indexterm>
+     </term>
+     <listitem>
+      <para>
+       Sets the current similarity threshold that is used by the <literal>%</>
+       operator.  The threshold must be between 0 and 1 (default is 0.3).
+      </para>
+     </listitem>
+    </varlistentry>
+   </variablelist>
+  </sect2>
+ 
+  <sect2>
    <title>Index Support</title>
  
    <para>
