Skip to content

6 Utilities

Changes to configure, initdb, backup, restore, upgrade, psql, and maintenance tools.
GASource pages: PDF 66-75Original PDF on GitHub

PDF page 66

Describes the major enhancements of utility commands.

3.4.1 Configure

The following options have been added to the ‘configure’ command.

Specify SSL library

Added “–with-ssl={library name}” option to specify the SSL library. Also, conventional “–withopenssl” option has been left for compatibility.

Example 76 Configure command for SSL
$ ./configure --help | grep ssl
  --with-ssl=LIB          use LIB for SSL/TLS support (openssl)
  --with-openssl          obsolete spelling of --with-ssl=openssl
$
Column compression method

The –with-lz4 option has been added to take advantage of the LZ4 column compression feature. The compiler flag LZ4_CFLAGS and the linker flag LZ4_LIBS have been added as environment variables.

Example 77 Configure command for LZ4
$ ./configure --help | grep -i lz4
  --with-lz4              build with LZ4 support
  LZ4_CFLAGS  C compiler flags for LZ4, overriding pkg-config
  LZ4_LIBS    linker flags for LZ4, overriding pkg-config
$

3.4.2 Initdb

The following options have been added to the initdb command.

–no-instructions option

When this option is specified, a message indicating the instance start-up method will not be output.

PDF page 67

Example 78 --no-instructions option
$ initdb -D data --no-instructions
The files belonging to this database system will be owned by user
"postgres".
This user must also own the server process.
…
initdb: warning: enabling "trust" authentication for local
connections
You can change this by editing pg_hba.conf or using the option -
A, or
--auth-local and --auth-host, the next time you run initdb.
–data-checksums option

In the message output when the –help option is specified, the –data-checksums option that specifies the checksum has been promoted from “Less commonly used options:” to the commonly used option “Options:”.

Example 79 Checksum specification option
$ initdb --help
initdb initializes a PostgreSQL database cluster.
Usage:
  initdb [OPTION]... [DATADIR]
Options:
  -A, --auth=METHOD         default authentication method for local connections
      --auth-host=METHOD    default authentication method for local TCP/IP
connections
      --auth-local=METHOD   default authentication method for local-socket
connections
 [-D, --pgdata=]DATADIR     location for this database cluster
  -E, --encoding=ENCODING   set default encoding for new databases
  -g, --allow-group-access  allow group read/execute on data directory
  -k, --data-checksums      use data page checksums
      --locale=LOCALE       set default locale for new databases
–clobber-cache option
…

PDF page 68

–discard-cache option

Run the bootstrap backend with the debug_discard_caches=1 option. This takes a very long time and is only of use for debugging.

3.4.3 Pg_amcheck

The pg_amcheck command has been added. This command makes it easy to check the structure of tables and indexes against a database with the Contrib module amcheck installed. In the following example, it can be seen that the damaged part of data2 table.

Example 80 Pg_amcheck command
$ pg_amcheck --database=postgres --table=data2 --verbose
pg_amcheck: including database: "postgres"
pg_amcheck: in database "postgres": using amcheck version "1.3" in
schema "public"
pg_amcheck: checking heap table "postgres"."public"."data2"
heap table "postgres"."public"."data2", block 0, offset 17:
    xmin 3236212 equals or exceeds next valid transaction ID 0:546
heap table "postgres"."public"."data2", block 0, offset 48:
    line pointer to page offset 6282 is not maximally aligned
pg_amcheck:
checking
btree
index
"postgres"."pg_toast"."pg_toast_16399_index"
pg_amcheck:
checking
heap
table
"postgres"."pg_toast"."pg_toast_16399"
Many options can be specified for the pg_amcheck command other than the above example.

PDF page 69

Option nameDescription
–allCheck all databases.
–index=PATTERNCheck matching index(es).
–schema=PATTERNCheck matching schema(s).
–on-error-stopStop checking at end of first corrupt page.
–parent-checkCheck index parent/child relationships.
–startblock=BLOCKBegin checking table(s) at the given block number.
–endblock=BLOCKCheck table(s) only up to the given block number.
–jobs=NUMUse this many concurrent connections to the server.
–progressShow progress information.
Table 27 Major options

3.4.4 Pg_dump

The pg_dump command has been following enhancements are implemented.

Restore partitions

It is now possible to restore a single partition from the partitioned table as a table.

Dumping Extension settings

The –extension option has been added to limit the extension definitions to be dumped. Specify the pattern for the extension name.

Example 81 --extension option
$ pg_dump --extension=cube
--
-- PostgreSQL database dump
…
--
-- Name: cube; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public;
…

PDF page 70

Multiple –verbose option

In the pg_dump command, pg_dumpall command, pg_restore command, and pg_rewind command, specifying the -v option multiple times will now increase the output level of the log.

3.4.5 Pg_dumpall

The pg_dumpall command now has an option –no-toast-compression that does not dump the compression settings for TOAST data.

3.4.6 Pg_rewind

It is now possible to specify a standby instance of streaming replication as the connection destination.

3.4.7 Psql

The following features have been added to the psql command.

Displaying access methods

The Access Method is now output to the output of the \di+, \dm+, \dt+, and \dtS+ commands.

Example 82 Display access method
postgres=> \di+
                                        List of relations
 Schema |    Name    | Type  | Owner | Table | Persistence | Access Method | …
--------+------------+-------+-------+-------+-------------+-------------+ …
 public | idx1_data1 | index | demo  | data1 | permanent   | btree         | …
 public | idx1_data2 | index | demo  | data2 | permanent   | btree         | …
(2 rows)
postgres=> \dt+
                                           List of relations
 Schema |  Name   |       Type        | Owner | Persistence | Access Method | …
--------+---------+-------------------+-------+-------------+-----------+ …-
 public | data1   | table             | demo  | permanent   | heap          | …
 public | data2   | table             | demo  | permanent   | heap          | …
(2 rows)

PDF page 71

\dt, \di command

It is now possible to specify for TOAST table and TOAST index.

Example 83 Specifying the TOAST table
postgres=> \dt pg_toast.pg_toast_16384
                 List of relations
  Schema  |      Name      |    Type     |  Owner
----------+----------------+-------------+----------
 pg_toast | pg_toast_16384 | TOAST table | postgres
(1 row)
postgres=> \di pg_toast.pg_toast_1213_index
                         List of relations
  Schema  |        Name         | Type  |  Owner   |     Table
----------+---------------------+-------+----------+-------------
 pg_toast | pg_toast_1213_index | index | postgres | pg_toast_1213
(1 row)
\dX command

Outputs a list of extended statistics.

Example 84 List of extended statistics
postgres=> CREATE STATISTICS stat1_data1 ON c1, c2 FROM data1 ;
CREATE STATISTICS
postgres=> ANALYZE data1 ;
ANALYZE
postgres=> \dX
                          List of extended statistics
 Schema |    Name     |    Definition     | Ndistinct | Dependencies |   MCV
--------+-------------+-------------------+-----------+--------------+------
 public | stat1_data1 | c1, c2 FROM data1 | defined   | defined      | defined
(1 row)

PDF page 72

\d+ command

When the table name is specified in the \d+ command, a compression setting column (Compression) is output between the Storage and Stats target columns. This column can be suppressed by setting the HIDE_TOAST_COMPRESSION variable to ‘on’.

Example 85 \d+ command
postgres=> \d+ compress1
                                       Table "public.compress1"
 Column |  Type   | Collation | Nullable | Default | Storage  | Compression | …
--------+---------+-----------+----------+---------+----------+------------+ …
 c1     | integer |           |          |         | plain    |             | …
 c2     | text    |           |          |         | extended | lz4         | …
Access method: heap
postgres=> \set HIDE_TOAST_COMPRESSION on
postgres=> \d+ compress1
                                 Table "public.compress1"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | …
--------+---------+-----------+----------+---------+----------+--------------+ …
 c1     | integer |           |          |         | plain    |              | …
 c2     | text    |           |          |         | extended |              | …
Access method: heap
\df, \do command

These commands can now add specify the data type.

PDF page 73

Example 86 \df, \do command
postgres=> \do - pg_catalog.int4
                               List of operators
   Schema   | Name | Left arg type | Right arg type | Result type | Description
------------+------+---------------+----------------+-------------+-----------
 pg_catalog | -    |               | integer        | integer     | negate
(1 row)
postgres=> \df sum (numeric)
                         List of functions
   Schema   | Name | Result data type | Argument data types | Type
------------+------+------------------+---------------------+------
 pg_catalog | sum  | numeric          | numeric             | agg
(1 row)
\dT command

The \dT command now accepts alias names for data types.

Example 87 \dT command with alias
postgres=> \dT int
                           List of data types
   Schema   |  Name   |                   Description
------------+---------+-------------------------------------------------
 pg_catalog | integer | -2 billion to 2 billion integer, 4-byte storage
(1 row)
Behavior when the editor is closed

The \e command (also \ef and \ev commands) launches the editor and no longer re-executes SQL statements in the file if the file is not modified.

3.4.8 Reindexdb

The –tablespace option has been added to the reindexdb command. It is now possible to specify the tablespace in which to store the indexes to be recreated.

PDF page 74

Example 88 REINDEXDB --tablespace option
$ reindexdb --table=data1 --tablespace=ts1 --verbose postgres
INFO:  index "idx1_data1" was reindexed
DETAIL:  CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
INFO:  index "pg_toast_16385_index" was reindexed
DETAIL:  CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s

3.4.9 Vacuumdb

The following options have been added to the vacuumdb command.

–force-index-cleanup option
  Always remove index entries pointing to dead tuples.
–no-index-cleanup option

Do not delete unnecessary tuples in the index.

–no-truncate option

Do not truncate the free pages at the end of the table.

–no-process-toast option

Do not perform VACUUM processing on the TOAST table.

PDF page 75

Example 89 Vacuumdb command options
$ vacuumdb --help
vacuumdb cleans and analyzes a PostgreSQL database.
Usage:
  vacuumdb [OPTION]... [DBNAME]
Options:
  -a, --all                       vacuum all databases
  -d, --dbname=DBNAME             database to vacuum
      --disable-page-skipping     disable all page-skipping behavior
  -e, --echo                      show the commands being sent to the server
  -f, --full                      do full vacuuming
  -F, --freeze                    freeze row transaction information
      --force-index-cleanup       always remove index entries that point to
dead tuples
  -j, --jobs=NUM                  use this many concurrent connections to vacuum
      --min-mxid-age=MXID_AGE     minimum multixact ID age of tables to vacuum
      --min-xid-age=XID_AGE       minimum transaction ID age of tables to
vacuum
      --no-index-cleanup          don't remove index entries that point to dead
tuples
      --no-process-toast          skip the TOAST table associated with the
table to vacuum
      --no-truncate               don't truncate empty pages at the end of the
table
  -P, --parallel=PARALLEL_WORKERS use this many background workers for vacuum,
if available
…