The Postgres playground started with a fun idea of "I wonder if I can put Postgres in a web browser". It evolved to a full set of guided tutorials that you can follow along step by step with. We actually use Notion to power all of our tutorials and an in-house API. This means a new tutorial is as simple as some SQL and some markdown. But, did you know you can bring your own setup to the playground?
All of our curated tutorials exist directly on the main Crunchy Data Developer area. However, you can visit an empty Postgres playground directly at: https://www.crunchydata.com/developers/playground. This is a blank slate Postgres instance, utilizing compute and memory directly from your web browser. It is not persistent and not connected to a remote session.
If you pass in a parameter for a
sql file it, the playground will
automatically run that once the Postgres session is started.
We can take a very basic set of SQL, something like this:
CREATE TABLE example (
INSERT INTO example (data) VALUES ('hello');
INSERT INTO example (data) VALUES ('world');
You can build longer SQL files for full data inputs. If you run a pg_dump from an existing database, that file will also work.
Like a restore file, you can also list SET statements for the session
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
The easiest way to host a sql file online is to use the GitHub gist feature. You’ll create a new gist, give it a name. Then view the raw link. The raw view link is the URL we want for working with the playground.
My example my file is:
Now we can pass that into the playground and build a longer url with:
1 - The base playground URL:
2 - The sql parameter
3 - Your full gist URL
Resulting in this:
I’ve been really excited to see how many people are using the Postgres playground for education and training. Let us know how you’re using the playground on X @crunchydata.
December 15, 2023 •More by this author