<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vertica Documentation – External procedures</title>
    <link>/en/extending/external-procedures/</link>
    <description>Recent content in External procedures on Vertica Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/extending/external-procedures/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Extending: Requirements for external procedures</title>
      <link>/en/extending/external-procedures/requirements-external-procedures/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/external-procedures/requirements-external-procedures/</guid>
      <description>
        
        
        &lt;p&gt;Enterprise Mode only&lt;/p&gt;

&lt;p&gt;External procedures have requirements regarding their attributes, where you store them, and how you handle their output. You should also be cognizant of their resource usage.&lt;/p&gt;
&lt;h2 id=&#34;procedure-file-attributes&#34;&gt;Procedure file attributes&lt;/h2&gt;
&lt;p&gt;The procedure file cannot be owned by root. It must have the set-user-ID (SUID), user execute, and group execute attributes set. If it is not readable by the Linux database administrator user, then the owner&#39;s password will have to be specified when installing the procedure.&lt;/p&gt;
&lt;h2 id=&#34;handling-procedure-output&#34;&gt;Handling procedure output&lt;/h2&gt;
&lt;p&gt;Vertica does not provide a facility for handling procedure output. Therefore, you must make your own arrangements for handling procedure output, which should include writing error, logging, and program information directly to files that you manage.&lt;/p&gt;
&lt;h2 id=&#34;handling-resource-usage&#34;&gt;Handling resource usage&lt;/h2&gt;
&lt;p&gt;The Vertica resource manager is unaware of resources used by external procedures. Additionally, Vertica is intended to be the only major process running on your system. If your external procedure is resource intensive, it could affect the performance and stability of Vertica. Consider the types of external procedures you create and when you run them. For example, you might run a resource-intensive procedure during off hours.&lt;/p&gt;
&lt;h2 id=&#34;sample-procedure-file&#34;&gt;Sample procedure file&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/bin/bash
echo &amp;#34;hello planet argument: $1&amp;#34; &amp;gt;&amp;gt; /tmp/myprocedure.log
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Extending: Installing external procedure executable files</title>
      <link>/en/extending/external-procedures/installing-external-procedure-executable-files/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/external-procedures/installing-external-procedure-executable-files/</guid>
      <description>
        
        
        &lt;p&gt;Enterprise Mode only&lt;/p&gt;

&lt;p&gt;To install an external procedure, use the Administration Tools through either the menu or the command line.&lt;/p&gt;
&lt;h2 id=&#34;menu&#34;&gt;Menu&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Run the &lt;a class=&#34;glosslink&#34; href=&#34;../../../en/glossary/admin-tools/&#34; title=&#34;Vertica Administration Tools provides a graphical user interface for managing a Vertica database.&#34;&gt;Administration tools&lt;/a&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ /opt/vertica/bin/adminTools
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On the AdminTools &lt;strong&gt;Main Menu&lt;/strong&gt;, click &lt;strong&gt;Configuration Menu&lt;/strong&gt;, and then click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On the &lt;strong&gt;Configuration Menu&lt;/strong&gt;, click &lt;strong&gt;Install External Procedure&lt;/strong&gt; and then click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select the database on which you want to install the external procedure.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Either select the file to install or manually type the complete file path, and then click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you are not the superuser, you are prompted to enter your password and click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The Administration Tools automatically create the &lt;em&gt;&lt;code&gt;database-name&lt;/code&gt;&lt;/em&gt;&lt;code&gt;/procedures&lt;/code&gt; directory on each node in the database and installs the external procedure in these directories for you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;OK&lt;/strong&gt; in the dialog that indicates that the installation was successful.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&#34;command-line&#34;&gt;Command line&lt;/h2&gt;
&lt;p&gt;If you use the command line, be sure to specify the full path to the procedure file and the password of the Linux user who owns the procedure file. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ admintools -t install_procedure -d vmartdb -f /scratch/helloworld.sh -p ownerpassword
Installing external procedure...
External procedure installed
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After you have installed an external procedure, you need to make Vertica aware of it. To do so, use the &lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-procedure-external/&#34;&gt;&lt;code&gt;CREATE PROCEDURE&lt;/code&gt;&lt;/a&gt; statement, but review &lt;a href=&#34;../../../en/extending/external-procedures/creating-external-procedures/&#34;&gt;Creating external procedures&lt;/a&gt; first.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Extending: Creating external procedures</title>
      <link>/en/extending/external-procedures/creating-external-procedures/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/external-procedures/creating-external-procedures/</guid>
      <description>
        
        
        &lt;p&gt;Enterprise Mode only&lt;/p&gt;

&lt;p&gt;After you install an external procedure, you must make Vertica aware of it with &lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-procedure-external/&#34;&gt;CREATE PROCEDURE (external)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Only superusers can create an external procedure, and by default, only they have execute privileges. However, superusers can &lt;a href=&#34;../../../en/sql-reference/statements/grant-statements/grant-procedure/&#34;&gt;grant&lt;/a&gt; users and roles EXECUTE privilege on the stored procedure.&lt;/p&gt;
&lt;p&gt;After you create a procedure, its metadata is stored in system table &lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/user-procedures/&#34;&gt;USER_PROCEDURES&lt;/a&gt;. Users can see only those procedures that they have been granted the privilege to execute.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example creates a procedure named &lt;code&gt;helloplanet&lt;/code&gt; for external procedure file &lt;code&gt;helloplanet.sh&lt;/code&gt;. This file accepts one &lt;code&gt;VARCHAR&lt;/code&gt; argument. The sample code is provided in &lt;a href=&#34;../../../en/extending/external-procedures/requirements-external-procedures/&#34;&gt;Requirements for external procedures&lt;/a&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE PROCEDURE helloplanet(arg1 VARCHAR) AS &amp;#39;helloplanet.sh&amp;#39; LANGUAGE &amp;#39;external&amp;#39;
   USER &amp;#39;dbadmin&amp;#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next example creates a procedure named &lt;code&gt;proctest&lt;/code&gt; for the script &lt;code&gt;copy_vertica_database.sh&lt;/code&gt;. This script copies a database from one cluster to another; it is included in the server RPM located in directory 
&lt;code&gt;/opt/vertica/scripts&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE PROCEDURE proctest(shosts VARCHAR, thosts VARCHAR, dbdir VARCHAR)
   AS &amp;#39;copy_vertica_database.sh&amp;#39; LANGUAGE &amp;#39;external&amp;#39; USER &amp;#39;dbadmin&amp;#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;overloading-external-procedures&#34;&gt;Overloading external procedures&lt;/h2&gt;
&lt;p&gt;You can create multiple external procedures with the same name if they have different signatures—that is, accept a different set of arguments. For example, you can overload the &lt;code&gt;helloplanet&lt;/code&gt; external procedure to also accept an integer value:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE PROCEDURE helloplanet(arg1 INT) AS &amp;#39;helloplanet.sh&amp;#39; LANGUAGE &amp;#39;external&amp;#39;
   USER &amp;#39;dbadmin&amp;#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After executing this statement, the database catalog stores two external procedures named &lt;code&gt;helloplanet&lt;/code&gt;—one that accepts a VARCHAR argument and one that accepts an integer. When you call the external procedure, Vertica evaluates the arguments in the procedure call to determine which procedure to call.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-procedure-external/&#34;&gt;CREATE PROCEDURE (external)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../en/sql-reference/statements/grant-statements/grant-procedure/&#34;&gt;GRANT (procedure)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Extending: Executing external procedures</title>
      <link>/en/extending/external-procedures/executing-external-procedures/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/external-procedures/executing-external-procedures/</guid>
      <description>
        
        
        &lt;p&gt;Enterprise Mode only&lt;/p&gt;

&lt;p&gt;After you define a procedure using the &lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-procedure-external/&#34;&gt;CREATE PROCEDURE (external)&lt;/a&gt; statement, you can use it as a meta command in a &lt;span class=&#34;sql&#34;&gt;SELECT&lt;/span&gt; statement. Vertica does not support using procedures in more complex statements or in expressions.&lt;/p&gt;
&lt;p&gt;The following example runs a procedure named &lt;code&gt;helloplanet&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT helloplanet(&amp;#39;earthlings&amp;#39;);
 helloplanet
-------------
           0
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example runs a procedure named &lt;code&gt;proctest&lt;/code&gt;. This procedure references the &lt;code&gt;copy_vertica_database.sh&lt;/code&gt; script that copies a database from one cluster to another. It is installed by the server RPM in the 
&lt;code&gt;/opt/vertica/scripts&lt;/code&gt; directory.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT proctest(
    &amp;#39;-s qa01&amp;#39;,
    &amp;#39;-t rbench1&amp;#39;,
    &amp;#39;-D /scratch_b/qa/PROC_TEST&amp;#39; );
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

External procedures have no direct access to database data. Use ODBC or JDBC for this purpose.

&lt;/div&gt;
&lt;p&gt;Procedures are executed on the initiating node. Vertica runs the procedure by forking and executing the program. Each procedure argument is passed to the executable file as a string. The parent fork process waits until the child process ends.&lt;/p&gt;
&lt;p&gt;If the child process exits with status 0, Vertica reports the operation took place by returning one row as shown in the &lt;code&gt;helloplanet&lt;/code&gt; example. If the child process exits with any other status, Vertica reports an error like the following:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ERROR 7112: Procedure reported: Procedure execution error: exit status = &lt;span class=&#34;code-variable&#34;&gt;code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To stop execution, cancel the process by sending a cancel command (for example, CTRL+C) through the client. If the procedure program exits with an error, an error message with the exit status is returned.&lt;/p&gt;
&lt;h2 id=&#34;permissions&#34;&gt;Permissions&lt;/h2&gt;
&lt;p&gt;To execute an external procedure, the user needs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;EXECUTE privilege on procedure&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;USAGE privilege on schema that contains the procedure&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Extending: Dropping external procedures</title>
      <link>/en/extending/external-procedures/dropping-external-procedures/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/external-procedures/dropping-external-procedures/</guid>
      <description>
        
        
        &lt;p&gt;Enterprise Mode only&lt;/p&gt;

&lt;p&gt;Only a superuser can drop an external procedure. To drop the definition for an external procedure from Vertica, use the &lt;a href=&#34;../../../en/sql-reference/statements/drop-statements/drop-procedure-external/&#34;&gt;DROP PROCEDURE (external)&lt;/a&gt; statement. Only the reference to the procedure is removed. The external file remains in the &lt;code&gt;&amp;lt;database&amp;gt;/procedures&lt;/code&gt; directory on each node in the database.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The definition Vertica uses for a procedure cannot be altered; it can only be dropped.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP PROCEDURE helloplanet(arg1 varchar);
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;../../../en/sql-reference/statements/drop-statements/drop-procedure-external/&#34;&gt;DROP PROCEDURE (external)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
  </channel>
</rss>
