バージョンごとのドキュメント一覧

44.1. 概要 #

<title>Overview</title>

PL/Tcl offers most of the capabilities a function writer has in the C language, with a few restrictions, and with the addition of the powerful string processing libraries that are available for Tcl. PL/Tclは、いくつか制限がありますが、C言語で書かれた関数と同じような能力を提供します。 さらに、Tclで利用できる、強力な文字列処理ライブラリを持っています。

One compelling <emphasis>good</emphasis> restriction is that everything is executed from within the safety of the context of a Tcl interpreter. In addition to the limited command set of safe Tcl, only a few commands are available to access the database via SPI and to raise messages via <function>elog()</function>. PL/Tcl provides no way to access internals of the database server or to gain OS-level access under the permissions of the <productname>PostgreSQL</productname> server process, as a C function can do. Thus, unprivileged database users can be trusted to use this language; it does not give them unlimited authority. すべてがTclインタプリタの安全なコンテキスト内で実行されるという制約はやむを得ないものですが、逆に良い制約でもあります。 安全なTclの制約付きのコマンドセットに、SPIを使ってデータベースにアクセスするコマンドと、elog()を使ってメッセージを処理するためのコマンドなどの、わずかなコマンドが追加されています。 C関数では可能ですが、PL/Tclにはデータベースサーバ内部にアクセスする方法や、PostgreSQLサーバプロセスの権限によるOSレベルのアクセスを行う方法はありません。 この結果、非特権データベースユーザがこの言語を信頼して使用することができます。 つまり、無制限の権限は与えられません。

The other notable implementation restriction is that Tcl functions cannot be used to create input/output functions for new data types. その他の注意すべき実装上の制約として、Tcl関数を使用して新しいデータ型用の入出力関数を作成することはできません。

Sometimes it is desirable to write Tcl functions that are not restricted to safe Tcl. For example, one might want a Tcl function that sends email. To handle these cases, there is a variant of <application>PL/Tcl</application> called <literal>PL/TclU</literal> (for untrusted Tcl). This is exactly the same language except that a full Tcl interpreter is used. <emphasis>If <application>PL/TclU</application> is used, it must be installed as an untrusted procedural language</emphasis> so that only database superusers can create functions in it. The writer of a <application>PL/TclU</application> function must take care that the function cannot be used to do anything unwanted, since it will be able to do anything that could be done by a user logged in as the database administrator. 例えば、メールを送るTcl関数が必要な場合など、安全なTclに制約されないTcl関数を書くことが望ましい場合があります。 このような場合、PL/TclU(信頼されないTcl)というPL/Tclの亜種を使用します。 これは、完全なTclインタプリタが使用されているという点以外の違いはありません。 PL/TclUを使用する場合は、信頼されていない手続き言語としてインストールする必要があります。 そうすることによって、データベースのスーパーユーザのみが関数を作成することができるようになります。 PL/TclU関数ではデータベース管理者としてログインしたユーザができるあらゆることの実行が可能となるので、作成する際に、この関数が意図された以外のことを行わないように細心の注意を払う必要があります。

The shared object code for the <application>PL/Tcl</application> and <application>PL/TclU</application> call handlers is automatically built and installed in the <productname>PostgreSQL</productname> library directory if Tcl support is specified in the configuration step of the installation procedure. To install <application>PL/Tcl</application> and/or <application>PL/TclU</application> in a particular database, use the <command>CREATE EXTENSION</command> command, for example <literal>CREATE EXTENSION pltcl</literal> or <literal>CREATE EXTENSION pltclu</literal>. インストール時にTclサポートの設定が指定されていれば、PL/TclPL/TclU呼び出しハンドラの共有オブジェクトコードは自動的に作成され、PostgreSQLのライブラリディレクトリにインストールされます。 PL/TclまたはPL/TclUの一方あるいは両方を特定のデータベースにインストールしたい場合は、CREATE EXTENSIONコマンドを使用してください。 例えば、CREATE EXTENSION pltclあるいはCREATE EXTENSION pltcluです。