From b8a3b20bed6232eb2b0b46b351662d88848e08c7 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 8 Jan 2016 16:32:50 -0600 Subject: [PATCH] Add Sleeping as a postgres til. --- README.md | 1 + postgres/sleeping.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 postgres/sleeping.md diff --git a/README.md b/README.md index 77ce5f1..6953f6c 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Restarting Sequences When Truncating Tables](postgres/restarting-sequences-when-truncating-tables.md) - [Send A Command To psql](postgres/send-a-command-to-psql.md) - [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md) +- [Sleeping](postgres/sleeping.md) - [Special Math Operators](postgres/special-math-operators.md) - [String Contains Another String](postgres/string-contains-another-string.md) - [Temporarily Disable Triggers](postgres/temporarily-disable-triggers.md) diff --git a/postgres/sleeping.md b/postgres/sleeping.md new file mode 100644 index 0000000..4ca08f8 --- /dev/null +++ b/postgres/sleeping.md @@ -0,0 +1,32 @@ +# Sleeping + +Generally you want your SQL statements to run against your database as +quickly as possible. For those times when you are doing some sort of +debugging or just want your queries to look very computationally expensive, +PostgreSQL offers the `pg_sleep` function. + +To sleep for 5 seconds, try the following: + +```sql +> select now(); select pg_sleep(5); select now(); + now +------------------------------- + 2016-01-08 16:30:21.251081-06 +(1 row) + +Time: 0.274 ms + pg_sleep +---------- + +(1 row) + +Time: 5001.459 ms + now +------------------------------- + 2016-01-08 16:30:26.252953-06 +(1 row) + +Time: 0.260 ms +``` + +As you'll notice, the `pg_sleep` statement took about 5 seconds.