{"id":32221832,"url":"https://github.com/tjc/test-postgresql","last_synced_at":"2025-10-22T08:59:46.030Z","repository":{"id":1650514,"uuid":"2376352","full_name":"TJC/Test-postgresql","owner":"TJC","description":"Fork of Test::postgresql","archived":false,"fork":false,"pushed_at":"2022-02-18T00:50:37.000Z","size":182,"stargazers_count":4,"open_issues_count":9,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-22T08:59:28.458Z","etag":null,"topics":["ci","perl","postgresql","testing"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Test::PostgreSQL","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TJC.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-13T05:37:51.000Z","updated_at":"2025-02-04T21:59:55.000Z","dependencies_parsed_at":"2022-09-09T18:00:42.341Z","dependency_job_id":null,"html_url":"https://github.com/TJC/Test-postgresql","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/TJC/Test-postgresql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TJC%2FTest-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TJC%2FTest-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TJC%2FTest-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TJC%2FTest-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TJC","download_url":"https://codeload.github.com/TJC/Test-postgresql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TJC%2FTest-postgresql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280409360,"owners_count":26325748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","perl","postgresql","testing"],"created_at":"2025-10-22T08:59:42.095Z","updated_at":"2025-10-22T08:59:46.025Z","avatar_url":"https://github.com/TJC.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://circleci.com/gh/TJC/Test-postgresql.svg)](https://circleci.com/gh/TJC/Test-postgresql)\n# NAME\n\nTest::PostgreSQL - PostgreSQL runner for tests\n\n# SYNOPSIS\n\n    use DBI;\n    use Test::PostgreSQL;\n    use Test::More;\n\n    # optionally\n    # (if not already set at shell):\n    #\n    # $ENV{POSTGRES_HOME} = '/path/to/my/pgsql/installation';\n\n    my $pgsql = eval { Test::PostgreSQL-\u003enew() }\n        or plan skip_all =\u003e $@;\n\n    plan tests =\u003e XXX;\n\n    my $dbh = DBI-\u003econnect($pgsql-\u003edsn);\n\n# DESCRIPTION\n\n`Test::PostgreSQL` automatically setups a PostgreSQL instance in a temporary\ndirectory, and destroys it when the perl script exits.\n\nThis module is a fork of Test::postgresql, which was abandoned by its author\nseveral years ago.\n\n# ATTRIBUTES\n\n`Test::PostgreSQL` object has the following attributes, overridable by passing\ncorresponding argument to constructor:\n\n## dbname\n\nDatabase name to use in this `Test::PostgreSQL` instance. Default is `test`.\n\n## dbowner\n\nDatabase owner user name. Default is `postgres`.\n\n## host\n\nHost name or IP address to use for PostgreSQL instance connections. Default is\n`127.0.0.1`.\n\n## base\\_dir\n\nBase directory under which the PostgreSQL instance is being created. The\nproperty can be passed as a parameter to the constructor, in which case the\ndirectory will not be removed at exit.\n\n## base\\_port\n\nConnection port number to start with. If the port is already used we will increment\nthe value and try again.\n\nDefault: `15432`.\n\n## unix\\_socket\n\nWhether to only connect via UNIX sockets; if false (the default),\nconnections can occur via localhost. \\[This changes the [\"dsn\"](#dsn)\nreturned to only give the UNIX socket directory, and avoids any issues with\nconflicting TCP ports on localhost.\\]\n\n## socket\\_dir\n\nUnix socket directory to use if [\"unix\\_socket\"](#unix_socket) is true. Default is `$base_dir/tmp`.\n\n## pg\\_ctl\n\nPath to `pg_ctl` program which is part of the PostgreSQL distribution.\n\nStarting with PostgreSQL version 9.0 `pg_ctl` can be used to start/stop\npostgres without having to use fork/pipe and will be chosen automatically\nif [\"pg\\_ctl\"](#pg_ctl) is not set but the program is found and the version is recent\nenough.\n\n**NOTE:** do NOT use this with PostgreSQL versions prior to version 9.0.\n\nBy default we will try to find `pg_ctl` in PostgresSQL directory.\n\n## initdb\n\nPath to `initdb` program which is part of the PostreSQL distribution. Default is\nto try and find it in PostgreSQL directory.\n\n## initdb\\_args\n\nArguments to pass to `initdb` program when creating a new PostgreSQL database\ncluster for Test::PostgreSQL session.\n\nDefaults to `-U postgres -A trust`. See [\"dbowner\"](#dbowner).\n\n## extra\\_initdb\\_args\n\nExtra args to be appended to [\"initdb\\_args\"](#initdb_args). Default is empty.\n\n## pg\\_config\n\nConfiguration to place in `$base_dir/data/postgresql.conf`. Use this to override\nPostgreSQL configuration defaults, e.g. to speed up PostgreSQL database init\nand seeding one might use something like this:\n\n    my $pgsql = Test::PostgreSQL-\u003enew(\n        pg_config =\u003e q|\n        # foo baroo mymse throbbozongo\n        fsync = off\n        synchronous_commit = off\n        full_page_writes = off\n        bgwriter_lru_maxpages = 0\n        shared_buffers = 512MB\n        effective_cache_size = 512MB\n        work_mem = 100MB\n    |);\n\n## postmaster\n\nPath to `postmaster` which is part of the PostgreSQL distribution. If not set,\nthe programs are automatically searched by looking up $PATH and other prefixed\ndirectories. Since `postmaster` is deprecated in newer PostgreSQL versions\n`postgres` is used in preference to `postmaster`.\n\n## postmaster\\_args\n\nDefaults to `-h 127.0.0.1 -F`.\n\n## extra\\_postmaster\\_args\n\nExtra args to be appended to [\"postmaster\\_args\"](#postmaster_args). Default is empty.\n\n## psql\n\nPath to `psql` client which is part of the PostgreSQL distribution.\n\n`psql` can be used to run SQL scripts against the temporary database created\nby [\"new\"](#new):\n\n    my $pgsql = Test::PostgreSQL-\u003enew();\n    my $psql = $pgsql-\u003epsql;\n    \n    my $out = `$psql -f /path/to/script.sql 2\u003e\u00261`;\n    \n    die \"Error executing script.sql: $out\" unless $? == 0;\n\n## psql\\_args\n\nCommand line arguments necessary for `psql` to connect to the correct PostgreSQL\ninstance.\n\nDefaults to `-U postgres -d test -h 127.0.0.1 -p $self-\u003eport`.\n\nSee also [\"dbowner\"](#dbowner), [\"dbname\"](#dbname), [\"host\"](#host), [\"base\\_port\"](#base_port).\n\n## extra\\_psql\\_args\n\nExtra args to be appended to [\"psql\\_args\"](#psql_args).\n\n## run\\_psql\\_args\n\nArguments specific for [\"run\\_psql\"](#run_psql) invocation, used mostly to set up and seed\ndatabase schema after PostgreSQL instance is launched and configured.\n\nDefault is `-1Xqb -v ON_ERROR_STOP=1`. This means:\n\n- 1: Run all SQL statements in passed scripts as single transaction\n- X: Skip `.psqlrc` files\n- q: Run quietly, print only notices and errors on stderr (if any)\n- b: Echo SQL statements that cause PostgreSQL exceptions (version 9.5+)\n- -v ON\\_ERROR\\_STOP=1: Stop processing SQL statements after the first error\n\n## seed\\_scripts\n\nArrayref with the list of SQL scripts to run after the database was instanced\nand set up. Default is `[]`.\n\n**NOTE** that `psql` older than 9.6 does not support multiple `-c` and `-f`\nswitches in arguments so `seed_scripts` will be executed one by one. This\nimplies multiple transactions instead of just one; if you need all seed statements\nto apply within a single transaction, combine them into one seed script.\n\n## auto\\_start\n\nInteger value that controls whether PostgreSQL server is started and setup\nafter creating `Test::PostgreSQL` instance. Possible values:\n\n- `0`\n\n    Do not start PostgreSQL.\n\n- `1`\n\n    Start PostgreSQL but do not run [\"setup\"](#setup).\n\n- `2`\n\n    Start PostgreSQL and run [\"setup\"](#setup).\n\n    Default is `2`.\n\n# METHODS\n\n## new\n\nCreate and run a PostgreSQL instance. The instance is terminated when the\nreturned object is being DESTROYed.  If required programs (initdb and\npostmaster) were not found, the function returns undef and sets appropriate\nmessage to $Test::PostgreSQL::errstr.\n\n## dsn\n\nBuilds and returns dsn by using given parameters (if any).  Default username is\n`postgres`, and dbname is `test` (an empty database).\n\n## uri\n\nBuilds and returns a connection URI using the given parameters (if any). See\n[URI::db](https://metacpan.org/pod/URI%3A%3Adb) for details about the format.\n\nDefault username is `postgres`, and dbname is `test` (an empty database).\n\n## pid\n\nReturns process id of PostgreSQL (or undef if not running).\n\n## port\n\nReturns TCP port number on which postmaster is accepting connections (or undef\nif not running).\n\n## start\n\nStarts postmaster.\n\n## stop\n\nStops postmaster.\n\n## setup\n\nSetups the PostgreSQL instance. Note that this method should be invoked _before_\n[\"start\"](#start).\n\n## run\\_psql\n\nExecute `psql` program with the given list of arguments. Usually this would be\nsomething like:\n\n    $pgsql-\u003erun_psql('-c', q|'INSERT INTO foo (bar) VALUES (42)'|);\n\nOr:\n\n    $pgsql-\u003erun_psql('-f', '/path/to/script.sql');\n\nNote that when using literal SQL statements with `-c` parameter you will need\nto escape them manually like shown above. `run_psql` will not quote them for you.\n\nThe actual command line to execute `psql` will be concatenated from [\"psql\\_args\"](#psql_args),\n[\"extra\\_psql\\_args\"](#extra_psql_args), and [\"run\\_psql\\_args\"](#run_psql_args).\n\n**NOTE** that `psql` older than 9.6 does not support multiple `-c` and/or `-f`\nswitches in arguments.\n\n## run\\_psql\\_scripts\n\nGiven a list of script file paths, invoke [\"run\\_psql\"](#run_psql) once with `-f 'script'`\nfor every path in PostgreSQL 9.6+, or once per `-f 'script'` for older PostgreSQL\nversions.\n\n# ENVIRONMENT\n\n## POSTGRES\\_HOME\n\nIf your postgres installation is not located in a well known path, or you have\nmany versions installed and want to run your tests against particular one, set\nthis environment variable to the desired path. For example:\n\n    export POSTGRES_HOME='/usr/local/pgsql94beta'\n\nThis is the same idea and variable name which is used by the installer of\n[DBD::Pg](https://metacpan.org/pod/DBD%3A%3APg).\n\n# AUTHOR\n\nToby Corkindale, Kazuho Oku, Peter Mottram, Alex Tokarev, plus various contributors.\n\n# COPYRIGHT\n\nCurrent version copyright © 2012-2015 Toby Corkindale.\n\nPrevious versions copyright (C) 2009 Cybozu Labs, Inc.\n\n# LICENSE\n\nThis module is free software, released under the Perl Artistic License 2.0.\nSee [http://www.perlfoundation.org/artistic\\_license\\_2\\_0](http://www.perlfoundation.org/artistic_license_2_0) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjc%2Ftest-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjc%2Ftest-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjc%2Ftest-postgresql/lists"}