.\" 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Test::PostgreSQL 3pm" .TH Test::PostgreSQL 3pm "2021-03-15" "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" Test::PostgreSQL \- PostgreSQL runner for tests .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use DBI; \& use Test::PostgreSQL; \& use Test::More; \& \& # optionally \& # (if not already set at shell): \& # \& # $ENV{POSTGRES_HOME} = \*(Aq/path/to/my/pgsql/installation\*(Aq; \& \& my $pgsql = eval { Test::PostgreSQL\->new() } \& or plan skip_all => $@; \& \& plan tests => XXX; \& \& my $dbh = DBI\->connect($pgsql\->dsn); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Test::PostgreSQL\*(C'\fR automatically setups a PostgreSQL instance in a temporary directory, and destroys it when the perl script exits. .PP This module is a fork of Test::postgresql, which was abandoned by its author several years ago. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" \&\f(CW\*(C`Test::PostgreSQL\*(C'\fR object has the following attributes, overridable by passing corresponding argument to constructor: .SS "dbname" .IX Subsection "dbname" Database name to use in this \f(CW\*(C`Test::PostgreSQL\*(C'\fR instance. Default is \f(CW\*(C`test\*(C'\fR. .SS "dbowner" .IX Subsection "dbowner" Database owner user name. Default is \f(CW\*(C`postgres\*(C'\fR. .SS "host" .IX Subsection "host" Host name or \s-1IP\s0 address to use for PostgreSQL instance connections. Default is \&\f(CW127.0.0.1\fR. .SS "base_dir" .IX Subsection "base_dir" Base directory under which the PostgreSQL instance is being created. The property can be passed as a parameter to the constructor, in which case the directory will not be removed at exit. .SS "base_port" .IX Subsection "base_port" Connection port number to start with. If the port is already used we will increment the value and try again. .PP Default: \f(CW15432\fR. .SS "unix_socket" .IX Subsection "unix_socket" Whether to only connect via \s-1UNIX\s0 sockets; if false (the default), connections can occur via localhost. [This changes the \*(L"dsn\*(R" returned to only give the \s-1UNIX\s0 socket directory, and avoids any issues with conflicting \s-1TCP\s0 ports on localhost.] .SS "socket_dir" .IX Subsection "socket_dir" Unix socket directory to use if \*(L"unix_socket\*(R" is true. Default is \f(CW\*(C`$basedir/tmp\*(C'\fR. .SS "pg_ctl" .IX Subsection "pg_ctl" Path to \f(CW\*(C`pg_ctl\*(C'\fR program which is part of the PostgreSQL distribution. .PP Starting with PostgreSQL version 9.0 \f(CW\*(C`pg_ctl\*(C'\fR can be used to start/stop postgres without having to use fork/pipe and will be chosen automatically if \*(L"pg_ctl\*(R" is not set but the program is found and the version is recent enough. .PP \&\fB\s-1NOTE:\s0\fR do \s-1NOT\s0 use this with PostgreSQL versions prior to version 9.0. .PP By default we will try to find \f(CW\*(C`pg_ctl\*(C'\fR in PostgresSQL directory. .SS "initdb" .IX Subsection "initdb" Path to \f(CW\*(C`initdb\*(C'\fR program which is part of the PostreSQL distribution. Default is to try and find it in PostgreSQL directory. .SS "initdb_args" .IX Subsection "initdb_args" Arguments to pass to \f(CW\*(C`initdb\*(C'\fR program when creating a new PostgreSQL database cluster for Test::PostgreSQL session. .PP Defaults to \f(CW\*(C`\-U postgres \-A trust\*(C'\fR. See \*(L"dbowner\*(R". .SS "extra_initdb_args" .IX Subsection "extra_initdb_args" Extra args to be appended to \*(L"initdb_args\*(R". Default is empty. .SS "pg_config" .IX Subsection "pg_config" Configuration to place in \f(CW\*(C`$basedir/data/postgresql.conf\*(C'\fR. Use this to override PostgreSQL configuration defaults, e.g. to speed up PostgreSQL database init and seeding one might use something like this: .PP .Vb 11 \& my $pgsql = Test::PostgreSQL\->new( \& pg_config => q| \& # foo baroo mymse throbbozongo \& fsync = off \& synchronous_commit = off \& full_page_writes = off \& bgwriter_lru_maxpages = 0 \& shared_buffers = 512MB \& effective_cache_size = 512MB \& work_mem = 100MB \& |); .Ve .SS "postmaster" .IX Subsection "postmaster" Path to \f(CW\*(C`postmaster\*(C'\fR which is part of the PostgreSQL distribution. If not set, the programs are automatically searched by looking up \f(CW$PATH\fR and other prefixed directories. Since \f(CW\*(C`postmaster\*(C'\fR is deprecated in newer PostgreSQL versions \&\f(CW\*(C`postgres\*(C'\fR is used in preference to \f(CW\*(C`postmaster\*(C'\fR. .SS "postmaster_args" .IX Subsection "postmaster_args" Defaults to \f(CW\*(C`\-h 127.0.0.1 \-F\*(C'\fR. .SS "extra_postmaster_args" .IX Subsection "extra_postmaster_args" Extra args to be appended to \*(L"postmaster_args\*(R". Default is empty. .SS "psql" .IX Subsection "psql" Path to \f(CW\*(C`psql\*(C'\fR client which is part of the PostgreSQL distribution. .PP \&\f(CW\*(C`psql\*(C'\fR can be used to run \s-1SQL\s0 scripts against the temporary database created by \*(L"new\*(R": .PP .Vb 2 \& my $pgsql = Test::PostgreSQL\->new(); \& my $psql = $pgsql\->psql; \& \& my $out = \`$psql \-f /path/to/script.sql 2>&1\`; \& \& die "Error executing script.sql: $out" unless $? == 0; .Ve .SS "psql_args" .IX Subsection "psql_args" Command line arguments necessary for \f(CW\*(C`psql\*(C'\fR to connect to the correct PostgreSQL instance. .PP Defaults to \f(CW\*(C`\-U postgres \-d test \-h 127.0.0.1 \-p $self\->port\*(C'\fR. .PP See also \*(L"dbowner\*(R", \*(L"dbname\*(R", \*(L"host\*(R", \*(L"base_port\*(R". .SS "extra_psql_args" .IX Subsection "extra_psql_args" Extra args to be appended to \*(L"psql_args\*(R". .SS "run_psql_args" .IX Subsection "run_psql_args" Arguments specific for \*(L"run_psql\*(R" invocation, used mostly to set up and seed database schema after PostgreSQL instance is launched and configured. .PP Default is \f(CW\*(C`\-1Xqb \-v ON_ERROR_STOP=1\*(C'\fR. This means: .IP "\(bu" 4 1: Run all \s-1SQL\s0 statements in passed scripts as single transaction .IP "\(bu" 4 X: Skip \f(CW\*(C`.psqlrc\*(C'\fR files .IP "\(bu" 4 q: Run quietly, print only notices and errors on stderr (if any) .IP "\(bu" 4 b: Echo \s-1SQL\s0 statements that cause PostgreSQL exceptions (version 9.5+) .IP "\(bu" 4 \&\-v ON_ERROR_STOP=1: Stop processing \s-1SQL\s0 statements after the first error .SS "seed_scripts" .IX Subsection "seed_scripts" Arrayref with the list of \s-1SQL\s0 scripts to run after the database was instanced and set up. Default is \f(CW\*(C`[]\*(C'\fR. .PP \&\fB\s-1NOTE\s0\fR that \f(CW\*(C`psql\*(C'\fR older than 9.6 does not support multiple \f(CW\*(C`\-c\*(C'\fR and \f(CW\*(C`\-f\*(C'\fR switches in arguments so \f(CW\*(C`seed_scripts\*(C'\fR will be executed one by one. This implies multiple transactions instead of just one; if you need all seed statements to apply within a single transaction, combine them into one seed script. .SS "auto_start" .IX Subsection "auto_start" Integer value that controls whether PostgreSQL server is started and setup after creating \f(CW\*(C`Test::PostgreSQL\*(C'\fR instance. Possible values: .ie n .IP "0" 4 .el .IP "\f(CW0\fR" 4 .IX Item "0" Do not start PostgreSQL. .ie n .IP "1" 4 .el .IP "\f(CW1\fR" 4 .IX Item "1" Start PostgreSQL but do not run \*(L"setup\*(R". .ie n .IP "2" 4 .el .IP "\f(CW2\fR" 4 .IX Item "2" Start PostgreSQL and run \*(L"setup\*(R". .Sp Default is \f(CW2\fR. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Create and run a PostgreSQL instance. The instance is terminated when the returned object is being DESTROYed. If required programs (initdb and postmaster) were not found, the function returns undef and sets appropriate message to \f(CW$Test::PostgreSQL::errstr\fR. .SS "dsn" .IX Subsection "dsn" Builds and returns dsn by using given parameters (if any). Default username is \&\f(CW\*(C`postgres\*(C'\fR, and dbname is \f(CW\*(C`test\*(C'\fR (an empty database). .SS "uri" .IX Subsection "uri" Builds and returns a connection \s-1URI\s0 using the given parameters (if any). See URI::db for details about the format. .PP Default username is \f(CW\*(C`postgres\*(C'\fR, and dbname is \f(CW\*(C`test\*(C'\fR (an empty database). .SS "pid" .IX Subsection "pid" Returns process id of PostgreSQL (or undef if not running). .SS "port" .IX Subsection "port" Returns \s-1TCP\s0 port number on which postmaster is accepting connections (or undef if not running). .SS "start" .IX Subsection "start" Starts postmaster. .SS "stop" .IX Subsection "stop" Stops postmaster. .SS "setup" .IX Subsection "setup" Setups the PostgreSQL instance. Note that this method should be invoked \fIbefore\fR \&\*(L"start\*(R". .SS "run_psql" .IX Subsection "run_psql" Execute \f(CW\*(C`psql\*(C'\fR program with the given list of arguments. Usually this would be something like: .PP .Vb 1 \& $pgsql\->run_psql(\*(Aq\-c\*(Aq, q|\*(AqINSERT INTO foo (bar) VALUES (42)\*(Aq|); .Ve .PP Or: .PP .Vb 1 \& $pgsql\->run_psql(\*(Aq\-f\*(Aq, \*(Aq/path/to/script.sql\*(Aq); .Ve .PP Note that when using literal \s-1SQL\s0 statements with \f(CW\*(C`\-c\*(C'\fR parameter you will need to escape them manually like shown above. \f(CW\*(C`run_psql\*(C'\fR will not quote them for you. .PP The actual command line to execute \f(CW\*(C`psql\*(C'\fR will be concatenated from \*(L"psql_args\*(R", \&\*(L"extra_psql_args\*(R", and \*(L"run_psql_args\*(R". .PP \&\fB\s-1NOTE\s0\fR that \f(CW\*(C`psql\*(C'\fR older than 9.6 does not support multiple \f(CW\*(C`\-c\*(C'\fR and/or \f(CW\*(C`\-f\*(C'\fR switches in arguments. .SS "run_psql_scripts" .IX Subsection "run_psql_scripts" Given a list of script file paths, invoke \*(L"run_psql\*(R" once with \f(CW\*(C`\-f \*(Aqscript\*(Aq\*(C'\fR for every path in PostgreSQL 9.6+, or once per \f(CW\*(C`\-f \*(Aqscript\*(Aq\*(C'\fR for older PostgreSQL versions. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" .SS "\s-1POSTGRES_HOME\s0" .IX Subsection "POSTGRES_HOME" If your postgres installation is not located in a well known path, or you have many versions installed and want to run your tests against particular one, set this environment variable to the desired path. For example: .PP .Vb 1 \& export POSTGRES_HOME=\*(Aq/usr/local/pgsql94beta\*(Aq .Ve .PP This is the same idea and variable name which is used by the installer of DBD::Pg. .SH "AUTHOR" .IX Header "AUTHOR" Toby Corkindale, Kazuho Oku, Peter Mottram, Alex Tokarev, plus various contributors. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Current version copyright X 2012\-2015 Toby Corkindale. .PP Previous versions copyright (C) 2009 Cybozu Labs, Inc. .SH "LICENSE" .IX Header "LICENSE" This module is free software, released under the Perl Artistic License 2.0. See for more information.