"Test::PostgreSQL" object has the following attributes, overridable by passing corresponding argument to
constructor:
dbname
Database name to use in this "Test::PostgreSQL" instance. Default is "test".
dbowner
Database owner user name. Default is "postgres".
host
Host name or IP address to use for PostgreSQL instance connections. Default is 127.0.0.1.
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.
base_port
Connection port number to start with. If the port is already used we will increment the value and try
again.
Default: 15432.
unix_socket
Whether to only connect via UNIX sockets; if false (the default), connections can occur via localhost.
[This changes the "dsn" returned to only give the UNIX socket directory, and avoids any issues with
conflicting TCP ports on localhost.]
socket_dir
Unix socket directory to use if "unix_socket" is true. Default is "$base_dir/tmp".
pg_ctl
Path to "pg_ctl" program which is part of the PostgreSQL distribution.
Starting with PostgreSQL version 9.0 "pg_ctl" can be used to start/stop postgres without having to use
fork/pipe and will be chosen automatically if "pg_ctl" is not set but the program is found and the
version is recent enough.
NOTE: do NOT use this with PostgreSQL versions prior to version 9.0.
By default we will try to find "pg_ctl" in PostgresSQL directory.
initdb
Path to "initdb" program which is part of the PostreSQL distribution. Default is to try and find it in
PostgreSQL directory.
initdb_args
Arguments to pass to "initdb" program when creating a new PostgreSQL database cluster for
Test::PostgreSQL session.
Defaults to "-U postgres -A trust". See "dbowner".
extra_initdb_args
Extra args to be appended to "initdb_args". Default is empty.
pg_config
Configuration to place in "$base_dir/data/postgresql.conf". Use this to override PostgreSQL configuration
defaults, e.g. to speed up PostgreSQL database init and seeding one might use something like this:
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
|);
postmaster
Path to "postmaster" which is part of the PostgreSQL distribution. If not set, the programs are
automatically searched by looking up $PATH and other prefixed directories. Since "postmaster" is
deprecated in newer PostgreSQL versions "postgres" is used in preference to "postmaster".
postmaster_args
Defaults to "-h 127.0.0.1 -F".
extra_postmaster_args
Extra args to be appended to "postmaster_args". Default is empty.
psql
Path to "psql" client which is part of the PostgreSQL distribution.
"psql" can be used to run SQL scripts against the temporary database created by "new":
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;
psql_args
Command line arguments necessary for "psql" to connect to the correct PostgreSQL instance.
Defaults to "-U postgres -d test -h 127.0.0.1 -p $self->port".
See also "dbowner", "dbname", "host", "base_port".
extra_psql_args
Extra args to be appended to "psql_args".
run_psql_args
Arguments specific for "run_psql" invocation, used mostly to set up and seed database schema after
PostgreSQL instance is launched and configured.
Default is "-1Xqb -v ON_ERROR_STOP=1". This means:
• 1: Run all SQL statements in passed scripts as single transaction
• X: Skip ".psqlrc" files
• q: Run quietly, print only notices and errors on stderr (if any)
• b: Echo SQL statements that cause PostgreSQL exceptions (version 9.5+)
• -v ON_ERROR_STOP=1: Stop processing SQL statements after the first error
seed_scripts
Arrayref with the list of SQL scripts to run after the database was instanced and set up. Default is
"[]".
NOTE that "psql" older than 9.6 does not support multiple "-c" and "-f" switches in arguments so
"seed_scripts" 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.
auto_start
Integer value that controls whether PostgreSQL server is started and setup after creating
"Test::PostgreSQL" instance. Possible values:
0 Do not start PostgreSQL.
1 Start PostgreSQL but do not run "setup".
2 Start PostgreSQL and run "setup".
Default is 2.