createlang Command in Linux



The createlang command in Linux is a utility for adding new procedural programming languages to a PostgreSQL database. It acts as a wrapper around the CREATE LANGUAGE command, simplifying the process of language addition.

The createlang command in PostgreSQL allows you to install new procedural languages into a database. While the core functionality is to install a language, you can use several connection options to specify the target database server. The createlang command is used to install a new procedural language into a PostgreSQL database.

Important Note − The createlang command is deprecated and removed in future PostgreSQL releases. It's recommended to use the CREATE EXTENSION command directly instead.

Table of Contents

Here is a comprehensive guide to the options available with the createlang command −

Understanding createlang Command in Linux

If you're working with PostgreSQL, the command you're thinking of is likely createlang. This command is specific to PostgreSQL and is used to create language extensions within a database.

The createlang command in PostgreSQL allows you to add support for different programming languages to your database. These languages can be used for writing functions, triggers, and other procedural objects.

Install createlang Command in Linux

If you don't have PostgreSQL installed, you'll need to do that first. The installation process varies based on your Linux distribution. Here are the general steps −

Update package lists

sudo apt update  # For Debian/Ubuntu-based systems
sudo yum update  # For Fedora/CentOS/RHEL-based systems

Install PostgreSQL

sudo apt install postgresql postgresql-contrib  # For Debian/Ubuntu
sudo yum install postgresql postgresql-contrib  # For Fedora/CentOS/RHEL

Replace postgresql-contrib with the appropriate package name for your distribution if necessary.

How to use createlang Command in Linux?

The createlang command in Linux is a utility for adding new procedural languages to a PostgreSQL database. It acts as a wrapper around the CREATE LANGUAGE command, providing a more straightforward way to define a new language within the database environment.

The syntax for createlang is a series of fields separated by spaces, where each field represents a different unit of time −

createlang [connection-option...] langname [dbname]

Where langname is the name of the procedural programming language to be defined, and dbname is the database to which the language should be added.

While the basic syntax is straightforward, there are additional options to control the creation process −

  • No options − Creates the language without specifying any additional parameters.
  • Custom options − Some languages might support additional options specific to their implementation.

Here's a detailed look at the options available with the createlang command −

Options Descriptions
langname This option specifies the name of the procedural programming language to be defined.
-W or --password Forces createlang to prompt for a password before connecting to a database.
-w or --no-password This option ensures that createlang never prompts for a password. If the server requires password authentication and a password is not available by other means, the connection attempt will fail.
-U username or --username username Indicates the user name to connect as.
-p port or --port port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.
-e or --echo This flag causes createlang to display the SQL commands as they are executed, which can be helpful for debugging or learning purposes. Displays the SQL commands as they are executed, useful for debugging purposes.
-h host or --host host Specifies the hostname of the machine where the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket.
-D dir or --directory dir Specifies the directory where the language interpreter can be found. This is primarily used for debugging and testing purposes.
-l or --list This option shows a list of already installed languages in the target database. Or lists the already installed languages in the specified database.
-d dbname or --dbname dbname This option specifies the target database to which the language should be added. By default, if no database is specified, the language is added to the database with the same name as the current system user.

Connection Parameters

The createlang command also respects the following environment variables, which can set default connection parameters −

  • PGDATABASE
  • PGHOST
  • PGPORT
  • PGUSER

These variables are supported by the libpq front-end library, which PostgreSQL utilities use for managing connections and executing commands.

For diagnostics, most error messages provided by createlang are self-explanatory. If an error message is unclear, running createlang with the --echo option may provide additional context, as it will display the SQL commands being executed.

Examples of createlang Command in Linux

Let’s explore a few basic examples of createlang command in Linux system −

  • Installing a Language
  • Installing a Language in a Specific Database
  • Specifying the Database Name
  • Listing Installed Languages
  • Echoing SQL Commands
  • Installing a Language from a Specific Directory
  • Installing PL/Python on a Remote Server
  • Installing a Language with Password Prompt

Installing a Language

As an example of using createlang, to install the language plpgsql into the database mydatabase, one would execute the following command −

createlang plpgsql mydatabase

This action will cause the language to be automatically installed into any databases created subsequently. This command installs the PL/pgSQL procedural language into the database named mydatabase.

Note that installing a language into template1 will cause it to be automatically installed into any databases created subsequently.

Installing a Language in a Specific Database

This command installs the PL/Python procedural language into the database named my_app_db −

createlang plpythonu my_app_db

Specifying the Database Name

This is equivalent to the first example, but explicitly specifies the database name using the -d option −

createlang plpgsql -d mydatabase

Listing Installed Languages

To list the languages already installed in the database mydb, the command would be −

createlang --list mydb
createlang -l -d mydatabase

This command lists all procedural languages installed in the mydatabase database.

Echoing SQL Commands

This command installs PL/pgSQL in mydatabase and displays the SQL commands executed during the process −

createlang -e plpgsql mydatabase

Installing a Language from a Specific Directory

This option is primarily used for debugging or testing purposes and is not commonly used in production environments −

createlang -D /path/to/language_directory plpgsql mydatabase

This command installs PL/pgSQL from the specified directory into the mydatabase database.

Installing PL/Python on a Remote Server

This command installs the PL/Python language into the myappdb database on the remote server mydbserver using port 5432 and the postgres user −

createlang plpythonu -h mydbserver -p 5432 -U postgres -d myappdb

The -W option could be added if password authentication is required.

Installing a Language with Password Prompt

This command installs PL/pgSQL into the mydatabase database on the mydbserver. It uses the user myuser and prompts for the password −

createlang plpgsql -h mydbserver -U myuser -W mydatabase

It's important to note that as of PostgreSQL 9.1, most procedural languages have been made into "extensions" and should be installed with CREATE EXTENSION rather than CREATE LANGUAGE.

For removing a language, the droplang command should be used, which is the counterpart to createlang.

Alternatives of createlang Command in Linux

createlang is a widely used tool for scheduling tasks in Linux, but there are several alternatives that might better suit your needs depending on the situation.

1. Systemd Timers

Systemd is a widely adopted init system (service manager) on many Linux distributions. It provides a built-in mechanism for scheduling tasks using timers. systemd timers offer features like dependency management, precise execution times, and integration with systemd services.

2. Anacron

Anacron is specifically designed for scheduling tasks on systems that aren't running 24/7. It checks for missed scheduled tasks upon system boot and runs them accordingly. This is useful for laptops or servers that might be turned off periodically.

3. GUI-based Schedulers

Many desktop environments offer graphical user interface (GUI) based schedulers. These tools allow you to configure tasks visually, often without needing to write complex cron expressions.

Conclusion

The createlang command is used to install languages, but it doesn't create functions or other objects using those languages. Once a language is installed, you can create functions, triggers, and other procedural objects using the language's syntax. It's a utility used to add a procedural language to a PostgreSQL database. It's essentially a wrapper around the CREATE EXTENSION SQL command.

Understanding the createlang command and its options can be crucial for database administrators and developers who work with PostgreSQL and need to manage multiple programming languages within their databases. With its straightforward syntax and comprehensive options, createlang provides a powerful yet user-friendly way to extend the capabilities of PostgreSQL databases.

Advertisements