NAMEDATALEN

A constant which defines the maximum length of database identifiers

NAMEDATALEN is a constant which defines the maximum length (in single byte characters) of database identifiers such as the names of databases, tables, columns etc. This value includes a trailing zero byte, meaning the actual maximum length is NAMEDATALEN - 1.

NAMEDATALEN is configured at compile time. If changed, initdb is required to initialise a new database instance with the changed value.

The standard value is: 64.

Determining the value of NAMEDATALEN

The value of NAMEDATALEN used by the instance is stored in the pg_control file and is reported by pg_controldata in the field "Maximum length of identifiers".

In PostgreSQL 9.6 and later, it is reported by the column max_identifier_length returned by the function pg_control_init().

In PostgreSQL 8.0 and later, it is reported by the preset configuration parameter max_identifier_length. Note that the value reported by max_identifier_length is always NAMEDATALEN - 1.

NAMEDATALEN and ENUM

As well as database identifiers, the maximum length of ENUM labels is also limited to NAMEDATALEN - 1 bytes.

Source code

NAMEDATALEN is defined in src/include/pg_config_manual.h as:

/*
 * Maximum length for identifiers (e.g. table names, column names,
 * function names).  Names actually are limited to one less byte than this,
 * because the length must include a trailing zero byte.
 *
 * Changing this requires an initdb.
 */
#define NAMEDATALEN 64

Notes

This 2017 pgsql-hackers thread: Revisiting NAMEDATALEN contains some insights into why it's unlikely NAMEDATALEN will be extended in the future and discusses the (in)feasibility of making it a configurable parameter.

Change history

Categories

DDL, PostgreSQL internals