.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PGObject::Util::DBAdmin 3pm" .TH PGObject::Util::DBAdmin 3pm "2021-11-12" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PGObject::Util::DBAdmin \- PostgreSQL Database Management Facilities for PGObject .SH "VERSION" .IX Header "VERSION" version 1.6.1 .SH "SYNOPSIS" .IX Header "SYNOPSIS" This module provides an interface to the basic Postgres db manipulation utilities. .PP .Vb 9 \& my $db = PGObject::Util::DBAdmin\->new( \& connect_data => { \& user => \*(Aqpostgres\*(Aq, \& password => \*(Aqmypassword\*(Aq, \& host => \*(Aqlocalhost\*(Aq, \& port => \*(Aq5432\*(Aq, \& dbname => \*(Aqmydb\*(Aq \& } \& ); \& \& my @dbnames = $db\->list_dbs(); # like psql \-l \& \& $db\->create(); # createdb \& $db\->run_file(file => \*(Aqsql/initial_schema.sql\*(Aq); # psql \-f \& \& my $filename = $db\->backup(format => \*(Aqc\*(Aq); # pg_dump \-Fc \& \& my $db2 = PGObject::Util::DBAdmin\->new($db\->export, (dbname => \*(Aqotherdb\*(Aq)); \& \& my $db3 = PGObject::Util::DBAdmin\->new( \& connect_data => { \& service => \*(Aqzephyr\*(Aq, \& sslmode => \*(Aqrequire\*(Aq, \& sslkey => "$HOME/.postgresql/postgresql.key", \& sslcert => "$HOME/.postgresql/postgresql.crt", \& sslpassword => \*(Aqyour\-sslpassword\*(Aq, \& } \& ); .Ve .SH "PROPERTIES" .IX Header "PROPERTIES" .SS "connect_data" .IX Subsection "connect_data" Contains a hash with connection parameters; see the PostgreSQL documentation for supported parameters. .PP The usual parameters are: .IP "\(bu" 4 user .IP "\(bu" 4 password .IP "\(bu" 4 dbname .IP "\(bu" 4 host .IP "\(bu" 4 port .PP Please note that the key \f(CW\*(C`requiressl\*(C'\fR is deprecated in favor of \&\f(CW\*(C`sslmode\*(C'\fR and isn't supported. .SS "username (deprecated)" .IX Subsection "username (deprecated)" The username used to authenticate with the PostgreSQL server. .SS "password (deprecated)" .IX Subsection "password (deprecated)" The password used to authenticate with the PostgreSQL server. .SS "host (deprecated)" .IX Subsection "host (deprecated)" In PostgreSQL, this can refer to the hostname or the absolute path to the directory where the \s-1UNIX\s0 sockets are set up. .SS "port (deprecated)" .IX Subsection "port (deprecated)" Default '5432' .SS "dbname (deprecated)" .IX Subsection "dbname (deprecated)" The database name to create or connect to. .SS "stderr" .IX Subsection "stderr" When applicable, the stderr output captured from any external commands (for example createdb or pg_restore) run during the previous method call. See notes in \*(L"\s-1CAPTURING\*(R"\s0. .SS "stdout" .IX Subsection "stdout" When applicable, the stdout output captured from any external commands (for example createdb or pg_restore) run during the previous method call. See notes in \*(L"\s-1CAPTURING\*(R"\s0. .SS "logger" .IX Subsection "logger" Provides a reference to the logger associated with the current instance. The logger uses \f(CW\*(C`ref $self\*(C'\fR as its category, eliminating the need to create new loggers when deriving from this class. .PP If you want to override the logger-instantiation behaviour, please implement the \f(CW\*(C`_build_logger\*(C'\fR builder method in your derived class. .SH "GLOBAL VARIABLES" .IX Header "GLOBAL VARIABLES" .ie n .SS "%helper_paths" .el .SS "\f(CW%helper_paths\fP" .IX Subsection "%helper_paths" This hash variable contains as its keys the names of the PostgreSQL helper executables \f(CW\*(C`psql\*(C'\fR, \f(CW\*(C`dropdb\*(C'\fR, \f(CW\*(C`pg_dump\*(C'\fR, etc. The values contain the paths at which the executables to be run are located. The default values are the names of the executables only, allowing them to be looked up in \&\f(CW$PATH\fR. .PP Modification of the values in this variable are the strict realm of \&\fIapplications\fR. Libraries using this library should defer potential required modifications to the applications based upon them. .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .SS "new" .IX Subsection "new" Creates a new db admin object for manipulating databases. .SS "\s-1BUILDARGS\s0" .IX Subsection "BUILDARGS" Compensates for the legacy invocation with the \f(CW\*(C`username\*(C'\fR, \f(CW\*(C`password\*(C'\fR, \&\f(CW\*(C`host\*(C'\fR, \f(CW\*(C`port\*(C'\fR and \f(CW\*(C`dbname\*(C'\fR parameters. .SS "verify_helpers( [ helpers => [...]], [operations => [...]])" .IX Subsection "verify_helpers( [ helpers => [...]], [operations => [...]])" Verifies ability to execute (external) helper applications by method name (through the \f(CW\*(C`operations\*(C'\fR argument) or by external helper name (through the \f(CW\*(C`helpers\*(C'\fR argument). Returns a hash ref with each key being the name of a helper application (see \f(CW\*(C`helpers\*(C'\fR below) with the values being a boolean indicating whether or not the helper can be successfully executed. .PP Valid values in the array referenced by the \f(CW\*(C`operations\*(C'\fR parameter are \&\f(CW\*(C`create\*(C'\fR, \f(CW\*(C`run_file\*(C'\fR, \f(CW\*(C`backup\*(C'\fR, \f(CW\*(C`backup_globals\*(C'\fR, \f(CW\*(C`restore\*(C'\fR and \&\f(CW\*(C`drop\*(C'\fR; the methods this module implements with the help of external helper programs. (Other values may be passed, but unsupported values aren't included in the return value.) .PP Valid values in the array referenced by the \f(CW\*(C`helpers\*(C'\fR parameter are the names of the PostgreSQL helper programs \f(CW\*(C`createdb\*(C'\fR, \f(CW\*(C`dropdb\*(C'\fR, \f(CW\*(C`pg_dump\*(C'\fR, \&\f(CW\*(C`pg_dumpall\*(C'\fR, \f(CW\*(C`pg_restore\*(C'\fR and \f(CW\*(C`psql\*(C'\fR. (Other values may be passed, but unsupported values will not be included in the return value.) .PP When no arguments are passed, all helpers will be tested. .PP Note: \f(CW\*(C`verify_helpers\*(C'\fR is a class method, meaning it wants to be called as \f(CW\*(C`PGObject::Util::DBAdmin\-\*(C'\fR\fBverify_helpers()\fR>. .SS "export" .IX Subsection "export" Exports the database parameters as a list so it can be used to create another object. .SS "connect($options)" .IX Subsection "connect($options)" Connects to the database using \s-1DBI\s0 and returns a database connection. .PP Connection options may be specified in the \f(CW$options\fR hashref. .SS "server_version([$dbname])" .IX Subsection "server_version([$dbname])" Returns a version string (like 9.1.4) for PostgreSQL. Croaks on error. .PP When a database name is specified, uses that database to connect to, using the credentials specified in the instance. .PP If no database name is specified, 'template1' is used. .SS "list_dbs([$dbname])" .IX Subsection "list_dbs([$dbname])" Returns a list of db names. .PP When a database name is specified, uses that database to connect to, using the credentials specified in the instance. .PP If no database name is specified, 'template1' is used. .SS "create" .IX Subsection "create" Creates a new database. .PP Croaks on error, returns true on success. .PP Supported arguments: .IP "copy_of" 4 .IX Item "copy_of" Creates the new database as a copy of the specified one (using it as a template). Optional parameter. Default is to create a database without a template. .SS "run_file" .IX Subsection "run_file" Run the specified file on the db. .PP After calling this method, \s-1STDOUT\s0 and \s-1STDERR\s0 output from the external utility which runs the file on the database are available as properties \&\f(CW$db\fR\->stdout and \f(CW$db\fR\->stderr respectively. .PP Croaks on error. Returns true on success. .PP Recognized arguments are: .IP "file" 4 .IX Item "file" Path to file to be run. This is a mandatory argument. .IP "vars" 4 .IX Item "vars" A hash reference containing \f(CW\*(C`psql\*(C'\fR\-variables to be passed to the script being executed. Running: .Sp .Vb 1 \& $dbadmin\->run_file(file => \*(Aq/tmp/pg.sql\*(Aq, vars => { schema => \*(Aqxyz\*(Aq }); .Ve .Sp Is equivalent to starting the file \f(CW\*(C`/tmp/pg.sql\*(C'\fR with the command .Sp .Vb 1 \& \eset schema xyz .Ve .Sp To undefine a variable, associate the variable name (hash key) with the value \f(CW\*(C`undef\*(C'\fR. .IP "stdout_log" 4 .IX Item "stdout_log" Provided for legacy compatibility. Optional argument. The full path of a file to which \s-1STDOUT\s0 from the external psql utility will be appended. .IP "errlog" 4 .IX Item "errlog" Provided for legacy compatibility. Optional argument. The full path of a file to which \s-1STDERR\s0 from the external psql utility will be appended. .SS "backup" .IX Subsection "backup" Creates a database backup file. .PP After calling this method, \s-1STDOUT\s0 and \s-1STDERR\s0 output from the external utility which runs the file on the database are available as properties \&\f(CW$db\fR\->stdout and \f(CW$db\fR\->stderr respectively. .PP Unlinks the output file and croaks on error. .PP Returns the full path of the file containining the backup. .PP Accepted parameters: .IP "format" 4 .IX Item "format" The specified format, for example c for custom. Defaults to plain text. .IP "file" 4 .IX Item "file" Full path of the file to which the backup will be written. If the file does not exist, one will be created with umask 0600. If the file exists, it will be overwritten, but its permissions will not be changed. .Sp If undefined, a file will be created using File::Temp having umask 0600. .IP "tempdir" 4 .IX Item "tempdir" The directory in which to write the backup file. Optional parameter. Uses File::Temp default if not defined. Ignored if file parameter is given. .IP "compress" 4 .IX Item "compress" Optional parameter. Specifies the compression level to use and is passed to the underlying pg_dump command. Default is no compression. .SS "backup_globals" .IX Subsection "backup_globals" This creates a file containing a plain text dump of global (inter-db) objects, such as users and tablespaces. It uses pg_dumpall to do this. .PP Being a plain text file, it can be restored using the run_file method. .PP Unlinks the output file and croaks on error. .PP Returns the full path of the file containining the backup. .PP Accepted parameters: .IP "file" 4 .IX Item "file" Full path of the file to which the backup will be written. If the file does not exist, one will be created with umask 0600. If the file exists, it will be overwritten, but its permissions will not be changed. .Sp If undefined, a file will be created using File::Temp having umask 0600. .IP "tempdir" 4 .IX Item "tempdir" The directory in which to write the backup file. Optional parameter. Uses File::Temp default if not defined. Ignored if file parameter is given. .SS "restore" .IX Subsection "restore" Restores from a saved file. Must pass in the file name as a named argument. .PP After calling this method, \s-1STDOUT\s0 and \s-1STDERR\s0 output from the external restore utility are available as properties \f(CW$db\fR\->stdout and \f(CW$db\fR\->stderr respectively. .PP Croaks on error. Returns true on success. .PP Recognized arguments are: .IP "file" 4 .IX Item "file" Path to file which will be restored to the database. Required. .IP "format" 4 .IX Item "format" The file format, for example c for custom. Defaults to plain text. .SS "drop" .IX Subsection "drop" Drops the database. This is not recoverable. Croaks on error, returns true on success. .SS "is_ready" .IX Subsection "is_ready" Drops the database. This is not recoverable. Croaks on error, returns true on success. .SH "CAPTURING" .IX Header "CAPTURING" This module uses \f(CW\*(C`Capture::Tiny\*(C'\fR to run extenal commands and capture their output, which is made available through the \f(CW\*(C`stderr\*(C'\fR and \f(CW\*(C`stdout\*(C'\fR properties. .PP This capturing does not work if Perl's standard \f(CW\*(C`STDOUT\*(C'\fR or \&\f(CW\*(C`STDERR\*(C'\fR filehandles have been localized. In this situation, the localized filehandles are captured, but external system calls are not affected by the localization, so their output is sent to the original filehandles and is not captured. .PP See the \f(CW\*(C`Capture::Tiny\*(C'\fR documentation for more details. .SH "AUTHOR" .IX Header "AUTHOR" Chris Travers, \f(CW\*(C`\*(C'\fR .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \f(CW\*(C`bug\-pgobject\-util\-dbadmin at rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc PGObject::Util::DBAdmin .Ve .PP You can also look for information at: .IP "\(bu" 4 \&\s-1RT: CPAN\s0's request tracker (report bugs here) .Sp .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Copyright 2014\-2020 Chris Travers. .PP This program is distributed under the (Revised) \s-1BSD\s0 License: .PP Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: .PP * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. .PP * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. .PP * Neither the name of Chris Travers's Organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. .PP \&\s-1THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \&\*(L"AS IS\*(R" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\s0 (\s-1INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES\s0; \s-1LOSS OF USE, DATA, OR PROFITS\s0; \s-1OR BUSINESS INTERRUPTION\s0) \s-1HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\s0 (\s-1INCLUDING NEGLIGENCE OR OTHERWISE\s0) \s-1ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\s0