Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

PgCommon

Name PgCommon
Version 1
Located at /usr/share/perl5
File /usr/share/perl5/PgCommon.pm
Is Core No
Search CPAN for this module PgCommon
Documentation PgCommon
Module Details PgCommon

NAME

PgCommon - Common functions for the postgresql-common framework


COPYRIGHT AND LICENSE

 (C) 2008-2009 Martin Pitt <mpitt@debian.org>
 (C) 2012-2021 Christoph Berg <myon@debian.org>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


CONTENTS

error

 Print an error message to stderr and die with exit status 1

prepare_exec, restore_exec

 Functions for configuration

config_bool

 returns '1' if the argument is a configuration file value that stands for
 true (ON, TRUE, YES, or 1, case insensitive), '0' if the argument represents
 a false value (OFF, FALSE, NO, or 0, case insensitive), or undef otherwise.

quote_conf_value

 Quotes a value with single quotes
 Arguments: <value>
 Returns: quoted string

replace_v_c

 Replaces %v and %c placeholders
 Arguments: <string> <version> <cluster>
 Returns: string

read_conf_file

 Read a 'var = value' style configuration file and return a hash with the
 values. Error out if the file cannot be read.
 If the file name ends with '.conf', the keys will be normalized to
 lower case (suitable for e.g. postgresql.conf), otherwise kept intact
 (suitable for environment).
 Arguments: <path>
 Returns: hash (empty if file does not exist)

cluster_conf_filename

 Returns path to cluster config file from a cluster configuration
 directory (with /etc/postgresql-common/<file name> as fallback)
 and return a hash with the values. Error out if the file cannot be read.
 If config file name is postgresql.auto.conf, read from PGDATA
 Arguments: <version> <cluster> <config file name>
 Returns: hash (empty if the file does not exist)

read_cluster_conf_file

Read a 'var = value' style configuration file from a cluster configuration

Arguments: <version> <cluster> <config file name> Returns: hash (empty if the file does not exist)

get_conf_value

 Return parameter from a PostgreSQL configuration file,
 or undef if the parameter does not exist.
 Arguments: <version> <cluster> <config file name> <parameter name>

set_conffile_value

 Set parameter of a PostgreSQL configuration file.
 Arguments: <config file name> <parameter name> <value>

set_conf_value

 Set parameter of a PostgreSQL cluster configuration file.
 Arguments: <version> <cluster> <config file name> <parameter name> <value>

disable_conffile_value

 Disable a parameter in a PostgreSQL configuration file by prepending it
 with a '#'. Appends an optional explanatory comment <reason> if given.
 Arguments: <config file name> <parameter name> <reason>

disable_conf_value

 Disable a parameter in a PostgreSQL cluster configuration file by prepending
 it with a '#'. Appends an optional explanatory comment <reason> if given.
 Arguments: <version> <cluster> <config file name> <parameter name> <reason>

replace_conf_value

 Replace a parameter in a PostgreSQL configuration file. The old parameter
 is prepended with a '#' and gets an optional explanatory comment <reason>
 appended, if given. The new parameter is inserted directly after the old one.
 Arguments: <version> <cluster> <config file name> <old parameter name>
            <reason> <new parameter name> <new value>

get_cluster_port

 Return the port of a particular cluster
 Arguments: <version> <cluster>

set_cluster_port

 Set the port of a particular cluster.
 Arguments: <version> <cluster> <port>

cluster_data_directory

 Return cluster data directory.
 Arguments: <version> <cluster name> [<config_hash>]

get_cluster_socketdir

 Return the socket directory of a particular cluster
 or undef if the cluster does not exist.
 Arguments: <version> <cluster>

set_cluster_socketdir

 Set the socket directory of a particular cluster.
 Arguments: <version> <cluster> <directory>

get_program_path

 Return the path of a program of a particular version.
 Arguments: <program name> [<version>]

cluster_port_running

 Check whether a postgres server is running at the specified port.
 Arguments: <version> <cluster> <port>

get_cluster_start_conf

 Read, verify, and return the current start.conf setting.
 Arguments: <version> <cluster>
 Returns: auto | manual | disabled

set_cluster_start_conf

 Change start.conf setting.
 Arguments: <version> <cluster> <value>
 <value> = auto | manual | disabled

set_cluster_pg_ctl_conf

 Change pg_ctl.conf setting.
 Arguments: <version> <cluster> <options>
 <options> = options passed to pg_ctl(1)

read_pidfile

 Return the PID from an existing PID file or undef if it does not exist.
 Arguments: <pid file path>

check_pidfile_running

 Check whether a pid file is present and belongs to a running postgres.
 Returns undef if it cannot be determined
 Arguments: <pid file path>
 postgres does not clean up the PID file when it stops, and it is
 not world readable, so only its absence is a definitive result;
 if it is present, we need to read it and check the PID, which will
 only work as root

cluster_supervisor

 Determine if a cluster is managed by a supervisor (pacemaker, patroni).
 Returns undef if it cannot be determined
 Arguments: <pid file path>
 postgres does not clean up the PID file when it stops, and it is
 not world readable, so only its absence is a definitive result; if it
 is present, we need to read it and check the PID, which will only
 work as root

cluster_info

 Return a hash with information about a specific cluster (which needs to exist).
 Arguments: <version> <cluster name>
 Returns: information hash (keys: pgdata, port, running, logfile [unless it
          has a custom one], configdir, owneruid, ownergid, waldir, socketdir,
          config->postgresql.conf)

validate_cluster_owner

 Checks if the owner of a cluster is valid, and the owner of the config matches
 the owner of the data directory.
 Arguments: cluster_info hash reference

get_versions

 Return an array of all available versions (by binaries and postgresql.conf files)
 Arguments: binary to scan for (optional, defaults to postgres)

get_newest_version

 Return the newest available version
 Arguments: binary to scan for (optional)

version_exists

 Check whether a version exists

get_version_clusters

 Return an array of all available clusters of given version
 Arguments: <version>

cluster_exists

 Check if a cluster exists.
 Arguments: <version> <cluster>

next_free_port

 Return the next free PostgreSQL port.

user_cluster_map

 Return the PostgreSQL version, cluster, and database to connect to.
 Version is always set (defaulting to the version of the default port
 if no matching entry is found, or finally to the latest installed version
 if there are no clusters at all), cluster and database may be 'undef'.
 If only one cluster exists, and no matching entry is found in the map files,
 that cluster is returned.

install_file

 Copy a file to a destination and setup permissions
 Arguments: <source file> <destination file or dir> <uid> <gid> <permissions>

change_ugid

 Change effective and real user and group id. Also activates all auxiliary
 groups the user is in. Exits with an error message if user/group ID cannot
 be changed.
 Arguments: <user id> <group id>

system_or_error

 Run a command and error out if it exits with a non-zero status.
 Arguments: <command ...>

get_db_encoding

 Return the encoding of a particular database in a cluster.
 This requires access privileges to that database, so this
 function should be called as the cluster owner.
 Arguments: <version> <cluster> <database>
 Returns: Encoding or undef if it cannot be determined.

get_db_locales

 Return locale of a particular database in a cluster. This requires access
 privileges to that database, so this function should be called as the cluster
 owner. (For versions >= 8.4; for older versions use get_cluster_locales()).
 Arguments: <version> <cluster> <database>
 Returns: (LC_CTYPE, LC_COLLATE) or (undef,undef) if it cannot be determined.

get_cluster_locales

 Return the CTYPE and COLLATE locales of a cluster.
 This needs to be called as root or as the cluster owner.
 (For versions <= 8.3; for >= 8.4, use get_db_locales()).
 Arguments: <version> <cluster>
 Returns: (LC_CTYPE, LC_COLLATE) or (undef,undef) if it cannot be determined.

get_cluster_controldata

 Return the pg_control data for a cluster
 Arguments: <version> <cluster>
 Returns: hashref

get_cluster_databases

 Return an array with all databases of a cluster.
 This requires connection privileges to template1, so
 this function should be called as the cluster owner.
 Arguments: <version> <cluster>
 Returns: array of database names or undef on error.

get_file_device

 Return the device name a file is stored at.
 Arguments: <file path>
 Returns:  device name, or '' if it cannot be determined.

parse_hba_line

 Parse a single pg_hba.conf line.
 Arguments: <line>
 Returns: Hash reference (or only line and type==undef for invalid lines)
  • line -> the verbatim pg_hba line

  • type -> comment, local, host, hostssl, hostnossl, undef

  • db -> database name

  • user -> user name

  • method -> trust, reject, md5, crypt, password, krb5, ident, pam

  • ip -> ip address

  • mask -> network mask (either a single number as number of bits, or bit mask)

read_pg_hba

 Parse given pg_hba.conf file.
 Arguments: <pg_hba.conf path>
 Returns: Array with hash refs; for hash contents, see parse_hba_line().

valid_hba_method

 Check if hba method is known
 Argument: hba method
 Returns: True if method is valid

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026