title: How does initdb of PostgreSQL work? How to use it for testing?
body: <p>Many suggestions for integration testing which includes Postgres Database say that I can <code>initdb</code> a new whole cluster in RAM disk and work on it.</p>
  
  <p>As far as I understand <code>initdb</code> is a new folder like thing related to databases.</p>
  
  <p>According to Postgres docs:</p>
  
  <blockquote>
    <p><code>initdb</code> creates a new PostgreSQL database cluster. A database cluster is a collection of databases that are managed by a single server instance.</p>
  </blockquote>
  
  <p>Does it create a new server?  Or a new Database?</p>
  
  <p><a href="https://i.stack.imgur.com/SsEjB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SsEjB.png" alt="db server"></a></p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>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?</p>
  
  <hr>
  
  <p>How can I use it to set it up for testing? </p>