Generating Data for Experiments

One of the best ways to learn about PostgreSQL is to conduct experiments on databases with large tables. For specific queries, you can then iterate on different index types, varying their definitions to cover different columns, orderings, and index options. Using the query planner, you can verify that the candidate indexes have the intended benefit or discard them.

Let’s explore that process. Create a temp schema locally if one doesn’t exist already from earlier work. Add a users table to the temp schema. Insert a large amount of rows into temp.users; ten million should do it! Run the following statements from psql to do that:

 CREATE​ ​SCHEMA​ ​IF​ ​NOT​ ​EXISTS​ temp;
 

Get High Performance PostgreSQL for Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.