Skip to main content
Version 3.1.1

Instance Initialization

Database Instance Initialization

Before any activity, it is necessary to initialize the cluster, or instance, a grouping of databases managed by a single master process of the PostgreSQL Database Management System.

In terms of file systems, the cluster is a directory on the file system under which all data and metadata will be stored. We call this area the instance data directory or PGDATA.

note

In this option, PgSmart activates the initdb command from PostgreSQL, passing the main options necessary for creating a cluster.

note

PgSmart creates a drop-in file for each launched instance, with the port number in the file name. This file contains the environment variables required to run the database service. PgSmart also includes and enables the database service in systemd.

Prerequisites
Command Syntax
Terminal input
   pgsmart cluster init [Flags]

Flags:

  • -D, --pgdata=<path> => Data directory of the PostgreSQL instance.
  • -M, --pgversion=(11|12|13|14|15) => Major version of PostgreSQL.
  • -a, --agent=<agent> => Alias, hostname or IP of the server where a Pgagent is installed.
  • -h, --help => Help.
  • -t, --template => Indicates that a template for instance initialization should be used.
Non-Interactive Initialization

Non-interactive execution is disabled for this operation.

Interactive Execution
Terminal input
   pgsmart cluster init
  1. Select the PgSmart agent (or register new Agent).

  2. Select the major version of PostgreSQL among those identified.

  3. Provide the Data directory of the PostgreSQL instance ([PGDATA]. (/docs_comuns/terminologias#pgdata)).

  4. Provide the Transactional logs directory (WALDIR).

  5. Provide the Standard character encoding (ENCODE).

  6. Select the Standard regional representation of data and monetary values (LOCALE).

  7. Provide the Instance port (PGPORT).

  8. Select the Network interfaces through which access will be granted (LISTEN_ADDRESSES).

  9. Confirm if you want to Export the template, with all the instance configuration done, for later reuse (Optional).

  10. Confirm the creation of the Instance.

    Figure 1 - Cluster Start
    Figure 1 - Cluster Start
    note

    The Default values can be confirmed (<ENTER>) or modified by the user.

    note

    The Data Directory of the Instance, the Transactional Logs Directory, and the port number of the instance must be unique for each instance.

    note

    The Installation Directory of binaries and the Data Directory of the instance will only be requested if the environment variables PGDATA and [PGBIN] are not found by PgSmart.

Command Variations for Interactive Installation

Some parameters can be previously passed in the command, however, the execution remains interactive, i.e., the informed parameters will need to be confirmed, along with the <Default> values for those parameters not informed.

Examples:

Interactive execution using the default base version of PostgreSQL: 15.

Terminal input
   pgsmart cluster init --pgversion 15
Cluster creation using initialization templates

When initializing the cluster, PgSmart can save the data from this initialization, providing a starting point for future initialization operations.

These templates are stored within the PgSmart directory opt/PgSmart-client/templates, in JSON format.

These templates are identified by the timestamp relative to the date and time of creation and can be reused in another configuration, from another server, for example, by simply copying the desired template into the templates directory of the target server.

The command for initializing the cluster using templates is:

Terminal input
   pgsmart cluster init -t
  1. Select the PgSmart Agent (or register new Agent).

  2. The desired template can be selected from the list of available templates.

  3. After confirming the template, the following information will be displayed based on the selected template:

    • The major version of PostgreSQL.

    • The Data directory of the PostgreSQL instance PGDATA.

    • The Transactional logs directory WALDIR.

    • The Standard character encoding ENCODING.

    • The Standard regional representation of data and monetary values LOCALE.

    • The Instance port PGPORT.

    • The Network interfaces through which access will be granted LISTEN_ADDRESSES.

    3.1. Confirm the selected template.

    3.2. Modify the template, if desired.

    3.3. Confirm the creation of the instance.

    Figure 1 - Cluster Start
    Figure 1 - Cluster Start
note

For creating a new instance on the same server (in localhost mode), the variables config_pgdata, initdb_waldir, and the connection port must be manually changed by accessing the desired template file directly.

Final Notes
note

PgSmart defines environment variables in the Linux bash_profile for the user, which can be reloaded in Linux sessions when a new login is performed. To load these variables immediately after installation, execute the following command (one time only):

Terminal input
   source ~/.bash_profile