I bought Mastering Postgres because I use Postgres a lot and wanted to support Aaron and his content. I already learned more than I expected and have been very impressed with the quantity and work Aaron put in.Timo Strackfeldt
Shorten dev cycles with branching and zero-downtime schema migrations.
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. And 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. And then 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. And so 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.
Now, 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. And then down here we see some indexes. And so we're gonna build these up as we go. We'll do this together, but this is a nice way to describe the table.
And then finally, the last thing I wanna show you is if you did select star from users limit 10, it's a mess, right? And so you can change this, you can change this output format to auto if you do \x auto
. And then we were to run that again, you'll see it gets a lot nicer. And then 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.
So 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. And so 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. And I'll leave a few links down below. You can tinker. You can tinker with a lot. So, 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. And if you want to use this, I would encourage you to customize it to your heart's content. But throughout the rest of this course, we're gonna be using TablePlus as we go.