Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PostgreSQL 11 Administration Cookbook

You're reading from  PostgreSQL 11 Administration Cookbook

Product type Book
Published in May 2019
Publisher Packt
ISBN-13 9781789537581
Pages 600 pages
Edition 1st Edition
Languages
Concepts
Authors (3):
Simon Riggs Simon Riggs
Profile icon Simon Riggs
Gianni Ciolli Gianni Ciolli
Profile icon Gianni Ciolli
Sudheer Kumar Meesala Sudheer Kumar Meesala
Profile icon Sudheer Kumar Meesala
View More author details
Toc

Table of Contents (19) Chapters close

Title Page
Copyright and Credits
About Packt
Contributors
Preface
1. First Steps 2. Exploring the Database 3. Configuration 4. Server Control 5. Tables and Data 6. Security 7. Database Administration 8. Monitoring and Diagnosis 9. Regular Maintenance 10. Performance and Concurrency 11. Backup and Recovery 12. Replication and Upgrades 1. Other Books You May Enjoy Index

Generating test data


DBAs frequently need to generate test data for a variety of reasons, whether it's for setting up a test database or just for generating a test case for a SQL performance issue.

How to do it...

To create a table of test data, we need the following:

  • Some rows
  • Some columns
  • Some order

The steps are as follows:

  1. First, generate a lot of rows of data. We use something named a set-returning function. You can write your own, though PostgreSQL includes a couple of very useful ones.
  2. You can generate a sequence of rows using a query like the following:
postgres=# SELECT * FROM generate_series(1,5);
 generate_series
-----------------
               1
               2
               3
               4
               5
(5 rows)
  1. Alternatively, you can generate a list of dates, like this:
postgres=# SELECT date(t)
FROM generate_series(now(),
now() + '1 week', '1 day') AS f(t);
date
------------
2018-04-24
2018-04-25
2018-04-26
2018-04-27
2018-04-28
2018-04-29
2018-04-30
2018-05-01
(8 rows)

 

 

  1. Then...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime