Skip to main content
Version Next

Database Instance Initialization

Before any activity, it is necessary to initialize the cluster or instance, which is a group of databases managed by a single master PostgreSQL server process.

In terms of file systems, the cluster is a directory where all data and metadata will be stored. This area is called the instance data directory or PGDATA.

note

This option allows PgSmart to run the PostgreSQL initdb command, passing the required options to create a cluster.

note

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

Prerequisites
Command Syntax
Terminal input
   pgsmart db init [Flags]

Flags:

  • -D, --pgdata=<value> => Data directory of the PostgreSQL instance.
  • -M, --pgversion=(11|12|13|14|15) => Major PostgreSQL version.
  • -a, --agent=<agent> => Alias, hostname or IP of the server where a PgSmart Agent is installed.
  • -h, --help => Help.
  • -t, --template => Use an instance initialization template.
Non-Interactive Execution

Non-interactive execution is disabled for this operation.

Interactive Execution
Terminal input
   pgsmart db init
  1. Select the desired PgSmart Agent (or Register new Agent).

  2. Select the major version of PostgreSQL from the listed options.

  3. Enter the instance's data directory (PGDATA).

  4. Enter the transaction log directory (WALDIR).

  5. Enter the default character encoding ENCODE.

  6. Select the default locale representation (LOCALE).

  7. Enter the instance port (PGPORT).

  8. Select the network interfaces used to access the instance (LISTEN_ADDRESSES).

  9. Confirm whether to export the template for reuse (optional).

  10. Confirm instance creation.

Figure 1 - Database Instance Initialization
Figure 1 - Database Instance Initialization
note

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

note

PGDATA, WALDIR, and port must be unique for each instance.

note

Binary installation directory and data directory will only be requested if [PGDATA] and [PGBIN] are not found in the environment.

Command Variants for Interactive Initialization

Some parameters can be passed in advance, but execution will still require confirmation.

Example:

Terminal input
   pgsmart db init --pgversion 15
Cluster Initialization Using Templates.

PgSmart can save instance initialization data as a reusable template, stored in opt/pgsmart-client/templates in JSON format.

These templates are identified by their timestamp and can be reused by copying to the templates directory on the target server.

To initialize a cluster using a template:

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

  2. Select the desired template from the list.

  3. The following information will be displayed from the selected template:

    • PostgreSQL major version
    • PGDATA
    • WALDIR
    • ENCODING
    • LOCALE
    • PGPORT
    • LISTEN_ADDRESSES

    3.1. Confirm the selected template. 3.2. Edit the template if desired. 3.3. Confirm instance creation.

    Figure 2 - Database Instance Initialization - Template
    Figure 2 - Database Instance Initialization - Template
note

For a new instance on the same server (localhost mode), manually update config_pgdata, initdb_waldir, and the connection port in the template file.

Final Notes
note

PgSmart sets environment variables in the Linux bash_profile. To load them immediately, run:

Terminal input
   source ~/.bash_profile