# PostgreSQL ## Install ```bash npm install @testcontainers/postgresql --save-dev ``` ## Examples These examples use the following libraries: - [pg](https://www.npmjs.com/package/pg) npm install pg npm install @types/pg --save-dev Choose an image from the [container registry](https://hub.docker.com/_/postgres) and substitute `IMAGE`. ### Execute a query [](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:pgConnect ### Connect via URI [](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:pgUriConnect ### With database [](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:pgSetDatabase ### With username [](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:pgSetUsername ### With SSL !!! note `withSSL()` / `withSSLCert()` expect certificate/key files that already exist. They do not generate key material. [](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:pgSslConnect ### Snapshots !!! warning You should never pass the `"postgres"` system database as the container database name if you want to use snapshots. The Snapshot logic requires dropping the connected database and using the system database to run commands, which will not work if the database for the container is set to `"postgres"`. [](../../packages/modules/postgresql/src/postgresql-container-snapshot.test.ts) inside_block:createAndRestoreFromSnapshot