Mastering Postgres
Introduction
Introduction to the course
Overview of course structure
Postgres vs. everyone
The psql CLI
Data Types
Introduction to schema
Integers
Numeric
Floating point
Storing money
NaNs and infinity
Casting types
Characters types
Check constraints
Domain types
Charsets and collations
Binary data
UUIDs
Boolean
Enums
Timestamps
Timezones
Dates and times
Advanced Data Types
Intervals
Serial type
Sequences
Identity
Network and mac addresses
JSON
Arrays
Generated columns
Text search types
Bit string
Ranges
Composite types
Nulls
Unique constraints
Exclusion constraints
Foreign key constraints
Indexing
Introduction to indexes
Heaps and CTIDs
B-Tree overview
Primary keys vs. secondary indexes
Primary key types
Where to add indexes
Index selectivity
Composite indexes
Composite range
Combining multiple indexes
Covering indexes
Partial indexes
Index ordering
Ordering nulls in indexes
Advanced Indexing
Functional indexes
Duplicate indexes
Hash indexes
Naming indexes
Understanding Query Plans
Introduction to explain
Explain structure
Scan nodes
Costs and rows
Explain analyze
Generating Results
Introduction to queries
Cross joins
Inner joins
Outer joins
Subqueries
Lateral joins
ROWS FROM
Filling gaps in sequences
Subquery elimination
Combining queries
Set generating functions
Indexing joins
Advanced SQL
Introduction to advanced SQL
Grouping
Grouping sets, rollups, cubes
Window functions
CTEs
CTEs with window functions
Recursive CTE
Hierarchical recursive CTE
Handling nulls
Row value syntax
Views
Materialized views
Removing duplicate rows
Upsert
Returning keyword
COALESCE + generated column
Full Text Search
Introduction to full text search
Searching with LIKE
Vectors, queries, and ranks
Websearch
Ranking
Indexing full text search
Highlighting
Advanced JSON
Intro to JSON
JSON vs JSONB
Validating JSON
Creating JSON objects + arrays
JSON extraction
JSON containment
JSON existence
JSON recordset
Updating JSON
Indexing JSON parts
GIN index
Vectors (pgvector)
Intro to pgvector
Vector embedding columns
Find related articles
Upsert vector embedding
Semantic search
Other operators
Vector indexes
Outro
Thank you
Bonus interviews
Heroku's glory days & Postgres vs the world (with Craig Kerstiens)
Creating a Postgres platform with Monica & Tudor from Xata.io
Bootstrapping an email service provider (with Jesse Hanley)
Next video (8)
Introduction
The psql CLI

Full Course

$
349
$399
USD, one-time fee
Mastering Postgres has dramatically improved my understanding of indexes. It has helped me make informed decisions around my queries and schema rather than blindly adding indexes and hoping for the best.
Dwight Watson
Dwight Watson

PostgreSQL database platform

Shorten dev cycles with branching and zero-downtime schema migrations.

Test Data

I've made my test data available for you to use and follow along.

Download
or
Use on Xata

Summary

Learn tips for making psql more user-friendly, with a brief tour of useful commands like `\d` to describe the database schema and `\x auto` to improve output readability. While TablePlus is my personal choice, the video encourages customizing psql settings to suit your preferences, including setting up a `psqlrc` file for consistent configuration across sessions.

Links

psql documentation

Video Transcript

In case you do wanna go down the psql route, I'm gonna give you just a few tips to make it a little bit nicer to show you around just a little bit. Like I said, I'm gonna use TablePlus throughout this video, but that's just a personal preference. I use TablePlus for everything.

If you wanna use psql, I'm gonna give you just a little bit of guidance here. To get connected, you're just gonna type psql. Then I'm gonna do, I'm gonna say connect to the demo database. Now, this is using default username, default password, default port, default everything because it is set up using that Postgres.app locally.

If you need to change any of those flags or parameters, you totally can. Once you're inside, you can do \? and that will give you some nice help text here. One thing that I do find incredibly useful is describing the database or the schema or the tables or anything like that. If you just do \d, you see here's the schema, the table name, what kind, this is a table, this is a sequence, and I'm the owner of everything, which is awesome.

If you want to describe a specific table, you can do that as well, which is very helpful. So, you can see the IDs and, I'm sorry, the columns, and all of their different types and whether it's nullable or not. Down here we see some indexes. We're gonna build these up as we go. We'll do this together, but this is a nice way to describe the table.

Finally, the last thing I wanna show you is if you did select * from users limit 10, it's a mess, right? You can change this, you can change this output format to auto if you do \x auto. We were to run that again, you'll see it gets a lot nicer. If we were to just, let's quit out of that, and if we were to just select ID, first name from users limit 10, you'll see it does look very, very nice.

That auto format will look and see how big is the output? How big is the terminal? What are we trying to show? And then pick the best format for that.

You can set up a psqlrc file. If you have a bunch of ways that you like to configure your psql, you can set that up in a file so that it does that upon load every time. I'll leave a few links down below. You can tinker. You can tinker with a lot. I'm gonna leave this here.

This is where we're gonna end it here because this is one of those things that is very dependent on user taste. If you want to use this, I would encourage you to customize it to your heart's content. Throughout the rest of this course, we're gonna be using TablePlus as we go.