{"id":25776146,"url":"https://github.com/yandex-qatools/postgresql-embedded","last_synced_at":"2025-02-27T06:05:39.784Z","repository":{"id":23616346,"uuid":"26985704","full_name":"yandex-qatools/postgresql-embedded","owner":"yandex-qatools","description":"Embedded PostgreSQL Server","archived":true,"fork":false,"pushed_at":"2020-01-07T13:18:54.000Z","size":311,"stargazers_count":493,"open_issues_count":52,"forks_count":90,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-06-21T15:32:25.380Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yandex-qatools.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2014-11-22T02:08:15.000Z","updated_at":"2024-04-17T00:58:11.000Z","dependencies_parsed_at":"2022-08-22T02:11:00.260Z","dependency_job_id":null,"html_url":"https://github.com/yandex-qatools/postgresql-embedded","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-qatools%2Fpostgresql-embedded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-qatools%2Fpostgresql-embedded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-qatools%2Fpostgresql-embedded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-qatools%2Fpostgresql-embedded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yandex-qatools","download_url":"https://codeload.github.com/yandex-qatools/postgresql-embedded/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240987435,"owners_count":19889333,"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","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":[],"created_at":"2025-02-27T06:01:18.537Z","updated_at":"2025-02-27T06:05:39.779Z","avatar_url":"https://github.com/yandex-qatools.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":[],"readme":"# Embedded PostgreSQL Server\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.embed/postgresql-embedded/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.embed/postgresql-embedded)\n[![Build status](https://travis-ci.org/yandex-qatools/postgresql-embedded.svg?branch=master)](https://travis-ci.org/yandex-qatools/postgresql-embedded/)\n[![Windows build status](https://ci.appveyor.com/api/projects/status/00ov87k6fe2euwvo?svg=true)](https://ci.appveyor.com/project/smecsia/postgresql-embedded)\n\nEmbedded PostgreSQL server provides a platform neutral way for running postgres binaries in unittests.\nThis library is based on [Flapdoodle OSS's embed process](https://github.com/flapdoodle-oss/de.flapdoodle.embed.process). \n\n## Note: this project is not being actively maintained anymore\nSorry for any inconvinience, but this project needs active maintainers. If anyone is interested in becoming the maintainer - please let me ([@smecsia](https://github.com/smecsia)) know.\n\n## Officially recommended alternative\nPlease be adviced that the main maintainer of this project has successfuly migrated to the use of [Test Containers project](https://www.testcontainers.org/modules/databases/postgres/). This is the best possible alternative nowadays.\n\n## Motivation\n\n* It's much easier than installing specific version manually\n* You can choose the version right from the code\n* You can start your development environment with the PostgreSQL embedded with the single command\n\n### Maven\n\nAdd the following dependency to your pom.xml:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eru.yandex.qatools.embed\u003c/groupId\u003e\n    \u003cartifactId\u003epostgresql-embedded\u003c/artifactId\u003e\n    \u003cversion\u003e2.10\u003c/version\u003e\n\u003c/dependency\u003e\n```\n### Gradle\n\nAdd a line to build.gradle:\n```groovy\ncompile 'ru.yandex.qatools.embed:postgresql-embedded:2.10'\n```\n\n## Howto\n\nHere is the example of how to launch and use the embedded PostgreSQL instance\n```java\n// starting Postgres\nfinal EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6);\n// predefined data directory\n// final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6, \"/path/to/predefined/data/directory\");\nfinal String url = postgres.start(\"localhost\", 5432, \"dbName\", \"userName\", \"password\");\n\n// connecting to a running Postgres and feeding up the database\nfinal Connection conn = DriverManager.getConnection(url);\nconn.createStatement().execute(\"CREATE TABLE films (code char(5));\");\nconn.createStatement().execute(\"INSERT INTO films VALUES ('movie');\");\n\n// ... or you can execute SQL files...\n//postgres.getProcess().importFromFile(new File(\"someFile.sql\"))\n// ... or even SQL files with PSQL variables in them...\n//postgres.getProcess().importFromFileWithArgs(new File(\"someFile.sql\"), \"-v\", \"tblName=someTable\")\n// ... or even restore database from dump file\n//postgres.getProcess().restoreFromFile(new File(\"src/test/resources/test.binary_dump\"))\n\n// performing some assertions\nfinal Statement statement = conn.createStatement();\nassertThat(statement.execute(\"SELECT * FROM films;\"), is(true));\nassertThat(statement.getResultSet().next(), is(true));\nassertThat(statement.getResultSet().getString(\"code\"), is(\"movie\"));\n\n// close db connection\nconn.close();\n// stop Postgres\npostgres.stop();\n```\n\nNote that EmbeddedPostgres implements [java.lang.AutoCloseable](https://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html), \nwhich means that you can use it with a [try-with-resources](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) \nstatement (in Java \u003e= 7) to have it automatically stopped.\n\n### How to avoid archive extraction on every run\n\nYou can specify the cached artifact store to avoid archives downloading and extraction (in case if a directory remains on every run).\n```java\nfinal EmbeddedPostgres postgres = new EmbeddedPostgres();\npostgres.start(cachedRuntimeConfig(\"/path/to/my/extracted/postgres\"));\n```\n\n### How to configure logging\n\nJust configure your own `slf4j` appenders. Here is the example of typical `src/test/resources/log4j.properties` file:\n\n```java\n# suppress inspection \"UnusedProperty\" for whole file\nlog4j.rootLogger=DEBUG, stdout\n\n# reduce logging for postgresql-embedded\nlog4j.logger.ru.yandex.qatools.embed=INFO\nlog4j.logger.de.flapdoodle.embed=INFO\n\n# Direct log messages to stdout\nlog4j.appender.stdout=org.apache.log4j.ConsoleAppender\nlog4j.appender.stdout.Target=System.out\nlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout\nlog4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\nlog4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer\n```\n\n### How to use your custom version of PostgreSQL\n\nPass the required `IVersion` interface implementation as a first argument of the `EmbeddedPostgres` object:\n\n```java\nfinal EmbeddedPostgres postgres = new EmbeddedPostgres(() -\u003e (IS_OS_WINDOWS) ? \"9.6.2-2\" : \"9.6.2-1\");\n```\n\n### Known issues\n* A lot of issues have been reported for this library under Windows. Please try to use the suggested way of start up and use\nthe cached artifact storage (to avoid extraction of the archive as extraction is extremely slow under Windows): \n```java\npostgres.start(cachedRuntimeConfig(\"C:\\\\Users\\\\vasya\\\\pgembedded-installation\"));\n```\n\n* PostgreSQL server is known to not start under the privileged user (which means you cannot start it under root/Administrator of your system):  \n\n\u003e `initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. Since the server cannot be run as root, you must not run initdb as root either. (It will in fact refuse to do so.)` \n  ([link](http://www.postgresql.org/docs/9.5/static/app-initdb.html)).   \n  \n  However some users have launched it successfully on Windows under Administrator, so you can try anyway. \n  \n### Supported Versions\n\n* 11.2: on Mac OS X and Windows 64 bit\n* 10.7, 9.6.12, 9.5.16: on Linux, Windows, Mac OS X\n* any custom version\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandex-qatools%2Fpostgresql-embedded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyandex-qatools%2Fpostgresql-embedded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandex-qatools%2Fpostgresql-embedded/lists"}