Many suggestions for integration testing which includes Postgres Database say that I can initdb
a new whole cluster in RAM disk and work on it.
As far as I understand initdb
is a new folder like thing related to databases.
According to Postgres docs:
initdb
creates a new PostgreSQL database cluster. A database cluster is a collection of databases that are managed by a single server instance.
Does it create a new server? Or a new Database?
Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalogue tables (tables that belong to the whole cluster rather than to any particular database), and creating the template1 and Postgres databases. When you later create a new database, everything in the template1 database is copied. (Therefore, anything installed in template1 is automatically copied into each database created later.) The Postgres database is a default database meant for use by users, utilities and third party applications.
Does the above sentence mean that from now on whatever database is created it is stored in that new "cluster"? If not how to create tables in such a cluster of RAM disk?
How can I use it to set it up for testing?
In the terminology your image uses (from pgAdmin?), initdb
would create the data directory for a new “server”.
In PostgreSQL, this is not called a server, but a database cluster. It has a data directory, which is created with initdb
. If you start the cluster with pg_ctl start
, a PostgreSQL server process (called postmaster) is started, which listens for incoming connections and starts backend processes that work on the data directory.
There can be more than one PostgreSQL database clusters on one machine, you just have to give them different port numbers.
It should be no problem to run initdb
to create a database cluster for your integration tests. After initdb
you have to edit postgresql.conf
appropriately (e.g. to set port
) and start the postmaster with pg_clt start -D <data directory>
.