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.
In this option, PgSmart activates the initdb command from PostgreSQL, passing the main options necessary for creating a cluster.
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.
- Before initializing the database instance, you must install the Database Service. For more information, see Database Service Installation.
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 execution is disabled for this operation.
pgsmart cluster init
- Instructions
- Video
-
Select the PgSmart agent (or register new Agent).
-
Select the
major version of PostgreSQL
among those identified. -
Provide the
Data directory of the PostgreSQL instance
([PGDATA]. (/docs_comuns/terminologias#pgdata)). -
Provide the
Transactional logs directory
(WALDIR). -
Provide the
Standard character encoding
(ENCODE). -
Select the
Standard regional representation of data
and monetary values (LOCALE). -
Provide the
Instance port
(PGPORT). -
Select the
Network interfaces
through which access will be granted (LISTEN_ADDRESSES). -
Confirm if you want to Export the template, with all the instance configuration done, for later reuse (Optional).
-
Confirm the creation of the Instance.
Figure 1 - Cluster StartnoteThe
Default
values can be confirmed (<ENTER>
) or modified by the user.noteThe Data Directory of the Instance, the Transactional Logs Directory, and the port number of the instance must be unique for each instance.
noteThe 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.
pgsmart cluster init --pgversion 15
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:
pgsmart cluster init -t
- Instructions
- Video
-
Select the
PgSmart Agent
(or register new Agent). -
The
desired template
can be selected from the list of available templates. -
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 -
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.
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):
source ~/.bash_profile