4 Utilities
PDF page 16
The following sections describe the major enhancements of the utility commands.
3.2.1 pg_rewind
Pg_rewind command has been added in PostgreSQL 9.5.
Overview
Pg_rewind command is a tool to build replication environment. Unlike pg_basebackup command, this command can synchronize to an existing database cluster. It will be used to resynchronization of the promoted slave instance and the old master instance.
Command Parameters
Following parameters can be specified to pg_rewind command.
| Parameter Name | Description |
|---|---|
| -D / –target-pgdata | Existing data directory to modify |
| –source-pgdata | Source data directory to sync with |
| –source-server | Source server to sync with |
| -P / –progress | Output progress messages |
| -n / –dry-run | Stop before modifying anything |
| –debug | Output a lot of debug messages |
| -V / –version | Output version information, then exit |
| -? / –help | Output usage information |
Conditions for executing
To run the pg_rewind command, there are some conditions. pg_rewind command is to check the conditions to run from the contents of the pg_control file of source and target. It is necessary either to specify the parameters wal_log_hints of PostgreSQL instance to “on” (the default value: “off”), or to enable the function of the data checksum. The parameters full_page_writes is also need to be set to “on” (the default value: “on”).
PDF page 17
Execution procedure
Pg_rewind should be executed according to the procedure listed below. In the following example, the old master instance is set to be the new slave instance using the promotion of the slave instance. 1. Setup the parameters of the master instance Setup the parameters in pg_hba.conf and postgresql.conf file. Reload the parameter file, if necessary. 2. Stop the target instance Stop the old master instance. 3. Execute pg_rewind command Run the pg_rewind command on the host of the old master instance. First specify with the -n parameter, and after the test, run without the -n parameter.
PDF page 18
Exit status
Pg_rewind command returns 0 when the process is completed successfully. If it fails then exits with 1.
3.2.2 pg_ctl
PDF page 19
3.2.3 vacuumdb
The –jobs parameter has been added to use multiple cores actively. You can specify the number of jobs of parallel processing for the –jobs parameter. The range of the number of the jobs is more than one, less than “macro FD_SETSIZE - 1” (in Red Hat Enterprise Linux 7 1,023 or less).
Relationship between –jobs parameter and the number of session
When a number is specified to –jobs parameter, the same number of sessions as the number specified in the parameter are created. In case that VACUUM is performed for all database (–all specified), this command processes each database in parallel. In case that VACUUM is performed on a single database, it processes each table in parallel. The default value for this parameter is 1; it leads the same behavior as previous versions. In the following example, 10 postgres processes have started because ‘-jobs=10’ is specified.
PDF page 20
PDF page 21
3.2.4 pg_dump
The following enhancements have been implemented.
Add –enable-row-security parameter
At default, pg_dump command gets a dump by specifying the row_security parameter to “off”. Data acquisition will result in an error in case of connecting with user privileges that cannot bypass the Row Level Security. By specifying the –enable-row-security parameter, the dump file contains only the data that has the authority contained. Error in Alpha 2 will occur.
Add –snapshot parameter
Specify the snapshot ID created with pg_export_snapshot function. You can get a dump using the specified snapshot ID.
Enhance output at the –verbose parameter
Schema name is included in the log that is output when you specify the –verbose parameter.
Obsolete –ignore-version parameter
–ignore-version parameter was made obsolete. pg_dumpall command, pg_restore command has also been modified as well.
3.2.5 psql
The following features have been added to the psql command.
pager_min_lines parameter
Pager_min_lines parameter has been added. If this parameter is specified, pager is not used when the number of rows of output is less than the specified value. The default value is 0, and pager works in accordance with the number of rows of the terminal. This setting did not work at the author environment.
PDF page 22
\set ECHO errors
If you specify a \set ECHO errors, statement which you are trying to run is displayed in case of an error.
Display schema name error
A message is added to indicate the error occurrence location in the case a schema name which does not exist is specified.
\watch output \timing information
The output of the \watch command, are now added to the results of \timing command.
PDF page 23
Backslash Command
The following enhancements have been implemented. Require superuser privilege for \db+ command. In previous version, general user can execute \db+ command.
| \dT+ | Additional information | data type of the owner has been added. |
|---|
Command Modification Description
3.2.6 pgbench
Some new features have been provided for pgbench command.
–latency-limit parameter
Parameter –latency-limit (-L) can now be specified in the parameters of the pgbench command. If you specify a value in milliseconds for this parameter, the transaction rate of which the duration is shorter than the specified time is displayed.
PDF page 24
Behavior change at the specified -f parameter
Behavior of the command in case of using a custom script (-f option), and not specifying the -n option, has been changed. In previous versions, VACUUM is performed to each table which pgbench created, and ended the command if the table does not exist. In PostgreSQL 9.5, it has been changed to continue the processing the custom scripts even if VACUUM process fails.
PDF page 25
3.2.7 pg_receivexlog
To the pg_receivexlog command, parameters for controlling the replication slot was added. Slot name is specified using –slot parameters as in the previous version.
–create-slot
Create a slot with the name specified in -slot parameter, and continues to receive WAL data. If there is no margin in the parameter max_replication_slots of the PostgreSQL instance, or if the slot having the same name already exists, then an error occurs.
–drop-slot
Remove the specified slot, and exit the command.
–synchronous
Flush the WAL data to disk immediately after it has been received
3.2.8 reindexdb
“-v” “-verbose” option has been added to output a detailed information. “REINDEX (VERBOSE) DATABASE database_name” statement is executed internally.
PDF page 26