From the course: Advanced PostgreSQL

macOS: Install PostgreSQL and PGAdmin 4 - PostgreSQL Tutorial

From the course: Advanced PostgreSQL

macOS: Install PostgreSQL and PGAdmin 4

Now, in order to work with PostgreSQL, you need to install the PostgreSQL server and pgAdmin 4, the development and administration platform that allows you to connect to the server, run queries and perform a bunch of other operations. In this movie, I'll show you how you can get set up with these for a mac machine. If you want to know how to get set up on Windows, I suggest you move on to the next movie in this chapter. Now, the easiest way to get set up with PostgreSQL on a mac is to head over to postgresapp.com/downloads.html. Here you'll be able to access and download the installer for PostgreSQL. Right here on this page, I see the latest version of PostgreSQL at the time of this recording, PostgreSQL 15. I'm going to go ahead and download the DMG file onto my local machine. Once the download is complete, I'm going to open up this DMG file. This will bring up a little window that will allow me to drag postgres into the applications folder and this will actually install postgres on my local mac machine. Once this is complete, you should be able to head over to the applications directory using your finder window and you should find Postgres right there. Let's double click on this and this will open up your PostgreSQL server. If you now notice the top left hand corner, I have the PostgreSQL server installed and it will run on port 5432. It's not actually running yet. For this, I'm going to head over and click on the "Initialize" button that you should see in the top right corner. And once this is done in a few seconds, you find that PostgreSQL 15 is now running and available on port 5432. Postgres has also set up a few databases for me to use. The loonycon database and the postgres database. If you click on server settings, you'll be able to see configuration details for this particular server version 15 and you can see the data directory config files, log files where exactly these are located on your machine. Now with our server up and running, let's head over and install the pgAdmin development and administration tool for Postgres. I'm going to head over to postgresql.org/ftppgadminpg4 and get the latest release of the tool. For me it's version 6.18. You might find a newer version available when you record. I am of course working on macOS, so I click through and here on this page I find the DMG file that will allow me to get set up with pgAdmin for 6.18. Once the download has completed successfully, go ahead and open up this DMG file. This will bring up a little wizard that you can use to install pgAdmin 4. Make sure you accept the terms and conditions and set this up. This should bring up a little window allowing you to drag pgAdmin 4 to your applications folder and this will actually install this on your mac local machine. And now if you open up the application folder, you should find pgAdmin 4 there along with the PostgresSQL server. Double click on "pgAdmin 4" so that you bring up the development platform that we are going to use. Now if you set a master password on pgAdmin 4, this will allow you to access all of the databases et cetera on PostgreSQL with just a single password. So that's exactly what I'm going to do here. At this point, I have the PostgreSQL server running and I have the pgAdmin tool opened up. I'm now going to connect my pgAdmin tool to the PostgreSQL server and I do this by clicking on "Add new server". This will bring up a dialog where I can give the server a meaningful name. I'm going to call it loony server. And in the connection tab you need to specify where your server is running. Now a server is of course running on our local machine, so localhost port 5432 is what I have specified here. I haven't configured any username so the default postgres username works. Go ahead and connect to our PostgreSQL server. We are now set up with pgAdmin, but I'm now going to switch over to the terminal window on my mac machine and get set up with psql which is a terminal based front end to PostgreSQL. Run the command that you see here on the screen to create a folder /etc/paths.d In this folder I'm going to create a file called Postgres App. And within that I'm going to specify the path to my PostgreSQL installation. This is under applications Postgres App Contents Versions Latest bin. After running this command, make sure that you configure your path environment variable to point to this bin folder. This will allow you to run your psql command. After having configured your path environment variable, you should be able to run the psql command and this will log you into the PostgreSQL command line client. And if you quit out of this client, well, you'll be back in your terminal window. At this point, we have the PostgreSQL server running on a mac. We have the pgAdmin tool installed and set up and we can run psql the terminal client for PostgreSQL.

Contents