How to Enable PL/Tcl on PostgreSQL 17 on Windows

As of PostgreSQL 17, the Windows download from EDB no longer includes the Language Pack that was previously part of the Stack Builder utility. To enable PL/Tcl, you must install Tcl separately. This guide walks you through the steps to enable PL/Tcl on PostgreSQL 17 on Windows.

Prerequisites

  • PostgreSQL 17 installed on Windows.
  • Administrator privileges to modify system settings.

Important Note At the time of writing, PL/Tcl requires Tcl version 8.6.X. It is not compatible with Tcl 9.

Steps to Enable PL/Tcl

1. Download Tcl 8.6.16

Download the **Batteries Included (64-bit)** installer for Tcl 8.6.16 from the following link: Download Tcl 8.6.16

2. Install Tcl

Run the installer and install Tcl to the "C:\Tcl" directory.

3. Update the System PATH Variable

Add the "C:\Tcl\bin" folder to the global "PATH" environment variable:

  1. Open System Properties (press "Win + R", type "sysdm.cpl", and press Enter).
  2. Go to the Advanced tab and click Environment Variables.
  3. Under System Variables, find "Path" and click Edit.
  4. Add "C:\Tcl\bin" and click OK.

Restart Windows to ensure the PATH changes take effect.

4. Fix DLL Name Compatibility

The "pltcl.dll" file in PostgreSQL expects the Tcl DLL to be named "tcl86t.dll". To resolve this:

  • Navigate to the "C:\Tcl\bin" directory.
  • Copy "tcl86.dll" and rename the copy to "tcl86t.dll".

Alternatively, you can create a symbolic link:

     mklink "C:\Tcl\bin\tcl86t.dll" "C:\Tcl\bin\tcl86.dll"

5. Restart PostgreSQL Service

Restart the PostgreSQL service to apply the changes:

     net stop postgresql-x64-17
     net start postgresql-x64-17

6. Enable the PL/Tcl Extension

Open "psql" or your preferred PostgreSQL client and run the following command:

     CREATE EXTENSION pltcl;

7. Test the Installation

Verify that PL/Tcl is installed and functioning:

Check Available Extensions:

     SELECT name, installed_version
     FROM pg_available_extensions
     WHERE name = 'pltcl';

Check Language Availability:

SELECT lanname, lanpltrusted
     FROM pg_language
     WHERE lanname = 'pltcl';

Run a Simple PL/Tcl Function:

     CREATE FUNCTION tcl_test() RETURNS text AS $$
         return "Hello, PL/Tcl!"
     $$ LANGUAGE pltcl;

     SELECT tcl_test();

If everything is set up correctly, the function should return:

    Hello, PL/Tcl!