.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "PGObject::Util::DBAdmin 3pm" .TH PGObject::Util::DBAdmin 3pm "2018-06-07" "perl v5.26.2" "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 0.130.1 .SH "SYNOPSIS" .IX Header "SYNOPSIS" This module provides an interface to the basic Postgres db manipulation utilities. .PP .Vb 7 \& my $db = PGObject::Util::DBAdmin\->new( \& username => \*(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)); .Ve .SH "PROPERTIES" .IX Header "PROPERTIES" .SS "username" .IX Subsection "username" The username used to authenticate with the PostgreSQL server. .SS "password" .IX Subsection "password" The password used to authenticate with the PostgreSQL server. .SS "host" .IX Subsection "host" 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" .IX Subsection "port" Default '5432' .SS "dbname" .IX Subsection "dbname" 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. .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .SS "new" .IX Subsection "new" Creates a new db admin object for manipulating databases. .SS "export" .IX Subsection "export" Exports the database parameters in a hash 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" .IX Subsection "server_version" Returns a version string (like 9.1.4) for PostgreSQL. Croaks on error. .SS "list_dbs" .IX Subsection "list_dbs" Returns a list of db names. .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 "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. .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\-2018 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