Welcome back.
We're going to start setting up Postgres on our computer so that just like we did with servers in
Front End we're going to have a terminal that's running our front end and a Back End that is running
our server, but also another terminal that is running a database because as you remember these are just
computers running somewhere. In the same way that we ran our server on our computer.
We can also run our database on our computer.
And in this video we're going to get us set up with Postgres. Now
MongoDB has gotten popular,
however nothing beats a relational database for really developing your knowledge of databases.
Once you understand relational databases it gives you really really good tools and mental models to
work with MongoDB. MongoDB is very, very simple.
You can think of it as a JSON data structure where we just have JSON that looks like an object
and we store that information there. With SQL and relational databases
it's more complex than that.
So if you understand this, you are miles ahead when it comes to understanding databases.
So we're going to be focusing on that because the principles are still the same for MongoDB.
All right.
So let's get Postgres set up on our computer.
The first thing we want to do is download something called a GUI.
So a graphical user interface for Postgres. And this exists for pretty much any database out there.
I like PSequel because it's free.
It's really, really good for Mac and it's very light and simple.
I'll also make sure to add notes on how to download something like this and Postgres in general
if you're using a Windows machine. But otherwise just click on the download link, it will be completely
fast.
Just open it up and you'll have something like this that I'm going to be using throughout the course.
But there's many, many options and you can take a look for it.
You just search for PostgreSQL GUI.
And once you have PSequel installed you'll have it in your application folder and you can follow along.
Now let's go back to the terminal. In order to have Postgres installed - there's many, many ways and
again I'll provide some notes on how you can do it.
But the best way especially on Mac is to use Brew which we've already talked about.
Every time you do something with homebrew- again it's a way to download packages from the Internet on
your terminal.
You always want to make sure that you do a brew update to make sure that everything is updated.
And also a brew doctor which just makes sure everything is working on your system.
Let's clear that. Perfect.
Once you have that set up we're going to just say Brew install
postgresql and this will install for us
Postgres. And you see over here that I already have Postgres installed.
But if it's your first time it'll run through the commands and then actually at the end tell you exactly
how to start using it.
But in our case I'll just tell you. It'll be much easier. To start Postgres.
You need to do 'brew services start postgresql' and don't worry this isn't Postgres specific. Any database
that you are downloading you're essentially downloading the software and then you want to start the service.
Each one has its own commands but it's as simple as Googling and figuring out how to run the database.
So we've started postgresql.
It looks like
I've already started the service and just to show you if I actually do stop here, it will stop the postgres
service.
And lets do start again and you can see that it's starting. Now in order for us to use Postgres we
need to create a database.
And the way we do that is to use the 'Createdb' command that has come once we've installed Postgres.
And here we can call it whatever we want.
So let's call it test.
It's going to create the DB.
And there you go. Here's the cool part
if I go back to my PSequel, open this up. Let me close this.
I have over here PSequel.
And it asks for the host which is the link to where the database is located.
In my case it's located at my localhost, right.
It's running on my computer.
So you want it to be localhost and the port number.
This is the default port number of 5 4 3 2.
Remember, how we had port 3000 and 3001 for the front end and backend.
It's similar to that.
It's opening up a port for it to listen to a database.
And this is the standard port for Postgres that you'll see.
So when I did the 'Start postgresql' and 'createdb' the default of '5432' was already set.
I can actually set what ports and change it up.
But we want to keep everything standard so we'll keep it the way it is.
If I now go to the database and we called it 'test' so again we'll do test database hit connect.
All right.
We're connected to the database but there's not much in here is there.
But at least we know that we're connected to localhost test.
And another way to connect to this, remember this is a GUI- a graphical user interface and I'm showing
you this because it's really good for demo purposes but I want you to get comfortable working with the
terminal as well. In order to do the same thing we just did with the GUI,
We can type in 'psql' again which is a command that we'll get when we install Postgres and we'll
say which database we want to connect to.
In our case *it will be the 'test'.
And there you go.
Just like when we run node and it changes terminals.
Now we're inside of Postgres that's running on our computer but we don't know any commands yet, do
we?
So in the next video we're going to learn some SQL commands and finally create some tables in our
Postgres database.
I'll see in that one, bye-bye.