Scripts

This chapter presents the available scripts. All our scripts have a detailed synopsis please, check the option “-h” or “—help”.

Operating system Start/Stop integration

DMK provides a tiny script which integrated to the boot procedure serves to start & stop all the PostgreSQL services smoothly for either SYSV or systemd based Linux dsitributions:

init.d script

cat ${DMK_HOME}/templates/init.d/postgres.linux
#!/bin/bash
...
case "$1" in
'start')
 "${DMK_HOME:-/u01/app/postgres/local/dmk}/bin/postgres.sh" start
 touch /var/lock/subsys/postgres
;;
'stop')
 "${DMK_HOME:-/u01/app/postgres/local/dmk}/bin/postgres.sh" stop
 rm -f /var/lock/subsys/postgres
;;
*)
 echo "usage $0 {start|stop}"
 exit 1
;;
esac

systemd service file

cat $DMK_HOME/templates/init.d/dbpostgres.service
#
# systemd integration for PostgreSQL instances managed by DMK
# Put this file under /etc/systemd/system/dbpostgres.service
# then: systemctl daemon-reload
# then: systemctl list-unit-files | grep postgres
# then: systemctl enable dbpostgres.service
# This is only required for RHEL8:
# then: semanage fcontext -a -t bin_t
/u01/app/postgres/local/dmk/bin/postgres.sh
# then: restorecon -v /u01/app/postgres/local/dmk/bin/postgres.sh
#
[Unit]
Description=The PostgreSQL Instance Service
After=syslog.target network.target efm-3.0.service
Requires=network.target local-fs.target
[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
CPUAccounting=true
CPUShares=1500
Type=forking
RemainAfterExit=yes
User=root
Group=root
ExecStart=/u01/app/postgres/local/dmk/bin/postgres.sh start
ExecStop=/u01/app/postgres/local/dmk/bin/postgres.sh stop
[Install]
WantedBy=multi-user.target

This script serves to start/stop all databases simultaneously which have the "Y" define in the pgtab file:

pg950:/u01/app/postgres/product/94/db_1/:dummy:9999:D
PG3:/u01/app/postgres/product/94/db_1/:/u02/pgdata/PG3:4445:N
PG4:/u01/app/postgres/product/94/db_1/:/u02/pgdata/PG4:4446:N
PG8:/u01/app/postgres/product/95/db_0:/u02/pgdata/PG8:5000:Y
PG9:/u01/app/postgres/product/95/db_0:/u02/pgdata/PG9:5001:Y

fsdisc.ksh

This script prompts in a graphical way the file system usage. The alias “f” refers to this script.

Syntax

fsdic.ksh

dmk-run.bash

This script prints the status of several PostgreSQL components. It’s commonly launched with the short aliases “sta”, “ser” or “u”.

Please check the respective platform script as the features differ (i.e. hiding stopped components)

Syntax

dmk-run.bash -h

This script prints the version and level of patch for each DMK package installed on the system.

version.sh

This script is parsing the PostgreSQL log file and alerts whenever an issue is found:

$DMK_HOME/bin/dmk-check-pg-logfile.sh --help

	 USAGE of dmk-check-pg-logfile.sh -s [-m]

	 SYNOPSIS
		
		dmk-check-pg-logfile.sh
		 -h print this help message
		 -s the PostgreSQL pgtab alias
		 -m Send an email in case of any issues detected

	 DESCRIPTION
		 This script is used to check the PostgreSQL log file for FATAL and ERROR messages

This script is used to perform basic health check against a PostgreSQL instance and is ending alerts in case of any issues:

$DMK_HOME/bin/dmk-check-postgres.sh --help

	 USAGE of dmk-check-postgres.sh -s [-m]

	 SYNOPSIS

	 dmk-check-postgres.sh
		 -v print version of this script
		 -h print this help message
		 -s the PostgreSQL pgtab alias
		 -m Send an email in case of any issues detected

	 DESCRIPTION
		 This script is used to perform various healthchecks against a PostgreSQL instance

This script is a wrapper around pgBadger and periodically generates pgBadger reports:

$DMK_HOME/bin/dmk-pg-badger-reports.sh --help
	 
	USAGE of dmk-pg-badger-reports.sh -s [-f -d -r -c -t -m -e]
	
	SYNOPSIS
 
		dmk-pg-badger-reports.sh
		 -v print version of this script
		 -h print this help message
		 -s the PostgreSQL pgtab alias
 
DESCRIPTION
 This script is used to generate pgbader reports out of the PostgreSQL instance logfiles
 
DEFAULTS
 We assume that the PostgreSQL logfile is rotated each day

In case BARMAN is used to create PostgreSQL backups this script is a wrapper for automating backups with BARMAN:

$DMK_HOME/bin/dmk-pg-barman-backup.sh --help
	
	USAGE of dmk-pg-barman-backup.sh -s [-m]
 
	SYNOPSIS
		 
		dmk-pg-barman-backup.sh
		 -v print version of this script
		 -h print this help message
		 -s the PostgreSQL pgtab alias
		 -m send mail notification not only on failure but also on success
 
	DESCRIPTION
	 This script is a wrapper around barman which does the backup with barman either manually or scheduled via cron

This script is used to automatically create PostgreSQL instances:

$DMK_HOME/bin/dmk-pg-dbcreate.pl --help
 
		USAGE of dmk-pg-dbcreate.pl
 
		SYNOPSIS
		 dmk-pg-dbcreate.pl -f <configuration_file>
 
		DESCRIPTION

			Initializes a PostgreSQL database cluster based on the configuration file
			There is a template configuration file in $DMK_HOME/templates/postgres/create_database.cfg
 
		DEPENDENCIES
			Basic DMK environment must be installed previously
			For the creation of the systemd service sudo must be setup for the postgres user.
 
		LIMITATIONS
			n.a
 
		PARAMETERS
			-h|help Display help
			-v|version Display version
			-f|file Path to the configuration file
 
		DISCLAIMER
			n.a.

This script helps with doing logical dumps of PostgreSQL instances:

$DMK_HOME/bin/dmk-pg-dump.sh --help
	USAGE of dmk-pg-dump.sh -s [-f -d -r -c -t -m -e -l]

	SYNOPSIS
		dmk-pg-dump.sh
			-v print version of this script
			-h print this help message
			-s the PostgreSQL pgtab alias
			-f shall we do a full dump ? (pg_dumpall)
			-d the database which shall be dumped, if not a full dump
			-r the retention in days to keep the dumps
			-c compress the dump (ignored for full dumps)
 			-t the target directory for the dumps
 			-m send mail notification not only on failure but also on success
			-e send an email which lists all dumps that have been deleted according to the retention policy
 			-l the host the database instance is running on when not localhost this is used for dumping over the network
 			-u the user to be used for connecting to the database. The default is postgres.
 			we do not accept a password so it must be either in .pgpass or the environment

	DESCRIPTION
		This script is used to either dump a single database from a PostgreSQL instance or to do a full dump of the whole PostgreSQL cluster. For a
database dump
		we use standard pg_dump and for a full dump we use standard
pg_dumpall.
 
	DEFAULTS
		 - The default is to do a full dump, this means if you do not provide
a database
 name to dump a full dump will be done
 		 - The default target directory is: /u90/pgdata/[PGALIAS]/dumps/
 You can overwrite this by using the -t switch
 		 - The default retention to keep the dumps is 7 days
 You can overwrite this by using the -r switch

dmk-pgpool-*.sh

The dmk-pgpool scripts provide integration with pgpgool when it comes to automated failover and can be used as templates for custom setups.

Last updated