How to set up a Postgres database on your Mac
Installing Postgres on a Mac is mostly the same as Windows — bar a few Catalina quirks I'll show you how to dodge.
- Download the PostgreSQL installer from EnterpriseDB and keep the default install and data directories unless you know what you're doing
- If a previous install left a Postgres data folder behind, move or delete the leftover folder in the Library before re-running the installer
- On Catalina, let Stack Builder download the PostGIS plugin but skip its install, then run the unzipped installer manually so it prompts correctly for credentials
- Postgres doesn't show as a normal app — launch it via PG_ADMIN4 in the Applications/Postgres folder and watch for the elephant icon to confirm the server is running
- Connect Tableau Prep to localhost with database and username 'postgresql' to write a table, using Replace Data to avoid appending duplicate rows on re-runs
0:00Hey, it's Tim here.
0:01In today's video, I'm going to be showing
0:03you how to
0:03install PostgreSQL on the Mac.
0:06Now, if you've watched my previous video
0:08for how to do it
0:09on Windows and maybe you don't have a
0:10Windows machine,
0:11this is the video for you.
0:12Otherwise, if not, check out the Windows
0:14video,
0:14and it's pretty much the same guide.
0:16The steps are very, very similar.
0:18We just have a few quirks for Mac that we
0:20have to take care of.
0:21To do this, you just head to the download
0:23page.
0:24What we're going to do once we're here,
0:26I'm going to click that a couple of times
0:27together,
0:28we're going to go to the Mac OS page,
0:30hit the download installer,
0:32and you'll get to this page.
0:33This is actually a page hosted by
0:36enterprise.db.com.
0:38The version I'm installing is 12.4.
0:40You'll see that I've actually downloaded it
0:42here already.
0:43If I just highlight this for you here at
0:44the bottom left-hand side,
0:46you can see that I've already got the
0:48installer on my desktop,
0:49just to make this video go a little bit
0:51faster.
0:51But if I go ahead and show where that is on
0:54my laptop,
0:54you can see that it's right there on my
0:56desktop.
0:57Once you've installed that file,
0:59you can go ahead and close your browser and
1:01just double-click
1:02the installer file that should now be on
1:04your desktop.
1:05I'm just going to minimize this window.
1:07When you do that,
1:09when you double-click that window,
1:10you'll get this package open up.
1:14You just need to go ahead and click on
1:15this box to actually run the installer.
1:18Now, what the installer does is it actually
1:20installs a few things.
1:22It installs Postgres, but it also installs
1:25another plugin manager which goes and
1:28gets specific add-ons for Postgres for you.
1:32We're going to go ahead and open the
1:34application.
1:34It's going to give us a warning because I
1:36've
1:36downloaded this from the net.
1:37MacOS Catalina seems to think
1:40anything from the Internet is not good for
1:42you.
1:43Let's just wait for that installer to pop
1:46up.
1:47It should be some square page
1:50here with the EDB on the left and Postgres
1:52on the right.
1:53Obviously, this graphic might change.
1:55But once this is up, you'll get a setup
1:57window,
1:57very similar to Windows actually.
1:59Go ahead and hit "Next".
2:01It's going to ask you for the install
2:04directory.
2:05Leave this as default.
2:06Unless you know what you're doing,
2:07just leave these defaults as they are.
2:09It's going to install these four things.
2:11Remember I mentioned that it's going to
2:13install a package manager.
2:14One of those is called Stack Builder,
2:16which goes and gets specific plugins
2:19and helps you build your environment as
2:21well.
2:22I'm going to go ahead and hit "Next".
2:25I'm going to go ahead and hit "Next"
2:29and you'll get another data directory.
2:31These two are important.
2:32Where is it going to install Postgres
2:34and where is it going to install the data?
2:36Go ahead and hit "Next".
2:38Now, you'll see here that I've already got
2:40a data directory in my computer.
2:43This is because I had a previous version
2:45of Postgres already installed.
2:46What I'm going to do is I'm actually just
2:48going to change this.
2:49Let's just go ahead and type in a "2"
2:53and I can go ahead and hit "Next".
2:55Actually, what I could do,
2:57if I'm just trying to be smart here,
2:58what I could do is actually go and see what
3:02we have here.
3:04If I hit "Cancel" and I just go to that
3:07directory,
3:08you might be able to fix this.
3:09If you've already installed Postgres in the
3:10past,
3:11you might have the same problem as me.
3:12Basically, Postgres is the file
3:16that you need to be able to install.
3:19It's already there, but for whatever reason
3:22,
3:22it's not actually able to overwrite it.
3:24You need to go to the library folder here
3:27and you're looking for the folder called
3:29Postgres SQL.
3:30Then you've got here the different version
3:32and here you can see that it's actually got
3:34that folder.
3:35If I just move that to the bin,
3:37give it my password here,
3:39and then go back to the installer and just
3:43delete the "2"
3:44and then hit "Next",
3:45you'll see this actually progresses quite
3:48well.
3:48Now, I'm thinking about that just for one
3:51second
3:52and I'm thinking, have I actually broken
3:54this installer?
3:54But maybe not. Let's just go ahead and
3:56progress.
3:57I think we should be okay.
3:59If we have, I'll show you how to fix this
4:01as well.
4:02It's another key step.
4:03The ports, just leave it as it is, default
4:06locale.
4:07And so here we are.
4:08We've got the install directory, Postgres.
4:10Yes, this is all right.
4:13And the data directory is separate.
4:14Yes, that's correct.
4:16So go ahead and hit "Next",
4:18and then that just runs the installer.
4:21I think everything's going to work fine.
4:22We managed to get through that error.
4:24Essentially, the folder was already there,
4:26so I just went and deleted it.
4:28It's a leftover from a previous install
4:30that I did for this demo.
4:31So once this is done, we'll hop back into
4:34the video
4:34and we'll carry on from there.
4:36Okay, it looks like the install is pretty
4:39much done.
4:40It's on the last final few steps.
4:42And when this finishes,
4:44we'll then get the option to install
4:46something called Stack Builder.
4:47We ticked the box earlier to enable this,
4:49but what Stack Builder does is it
4:51essentially helps you
4:53build your Postgres environment
4:55based on a bunch of variables.
4:57But in order to do that,
4:58you might want to install certain
4:59applications.
5:00So let's go ahead and finish this.
5:03We've ticked the box for Stack Builder.
5:05Let's go ahead and hit my password.
5:07And Stack Builder launches,
5:10and it's going to ask which version of Post
5:12gres you've got,
5:13which is version 12.
5:14It's the only option there.
5:15And this is essentially what Stack Builder
5:17does.
5:18It allows you to add plugins or settings
5:20and configurations and drivers
5:22for your particular installation of Post
5:24gres.
5:24And in this case, I'd like to tick the Post
5:27GIS plugin
5:29because this will allow us to do some
5:31spatial functions
5:33on our database.
5:34So go ahead and hit next.
5:36But the key thing here is I need to pay
5:37attention
5:38to where it's downloading this
5:39because I'm not actually going to let
5:41the installer finish this installation.
5:43And Catalina actually bugs out if you let
5:45it do this.
5:46So we're going to manually finish the
5:48installation,
5:49but we're going to let it download to this
5:51directory here
5:52in my user folder.
5:53So go ahead and hit next.
5:55I'm going to tick the box to skip the
5:56installation,
5:57and this is done.
5:58Hit next.
5:59It'll go ahead and get the file.
6:01And that's pretty much it
6:02from the first parts of this installer.
6:05Postgres is installed,
6:06but we need to go finish installing our
6:08little plugins
6:09that we've just requested.
6:11So go ahead and open your finder, head to
6:14the folder,
6:15and you'll see that this is the file
6:16that it downloaded for us.
6:18We just need to go ahead and unzip that.
6:21Now, I actually unzipped this earlier on
6:23today,
6:23so I've actually already got it in my
6:25downloads folder.
6:26But if I go ahead and double-click this
6:28installer,
6:29you will now see now this runs the correct
6:32procedure
6:33because it asks for my username and
6:34password.
6:35It actually runs this properly.
6:36Whereas before, if you let the previous
6:38installer run it,
6:39it actually errors out.
6:40So again, we're just waiting for the pop-up
6:42to appear.
6:44You hit next.
6:45This is a much smaller installation,
6:48and it's asking for the password now
6:50for the actual database we've already got
6:51installed.
6:52So I'll go ahead and give it that password.
6:55Hit next.
6:56And that's pretty much it, actually.
6:58It's a very fast install in this particular
7:00case.
7:00I've got a decent laptop,
7:02so it's able to get through this fairly
7:04quickly.
7:04And now this is done.
7:06We've got a working database on our laptop
7:08that we can now play around with Tableau or
7:11Tableau Prep.
7:12Now, when we finish this, you might then
7:14wonder,
7:15well, as a Mac user, how do I open up Post
7:17gres?
7:18How do I see that it's running?
7:19How do I know that it's working?
7:20Well, if you hit Command + Space,
7:22that brings up Spotlight, or in my case,
7:24Alfred,
7:25which I've used to replace Spotlight.
7:27And I'm just going to type in Postgres,
7:29and you'll see that nothing comes up, okay?
7:32Nothing comes up here.
7:33And that's fundamentally
7:34because when you actually install Postgres,
7:36it doesn't appear as a traditional
7:38application.
7:39So what we need to do
7:41is actually go to the Applications folder,
7:44and in the Applications folder,
7:45we should find a directory titled Postgres,
7:48and there it is.
7:49It's this folder right here.
7:52Now, if I double-click that and open it,
7:53you'll see that I've got several files.
7:57So don't delete any of these
8:00because they're essentially put there by
8:02Postgres.
8:02If you want to uninstall Postgres, don't
8:04just delete these.
8:05You actually need to go and delete another
8:08folder
8:08in the Library section,
8:09which I'll maybe show you at the very end
8:11of the video.
8:11But to launch Postgres, just hit PG_ADMIN4,
8:15and what you can do is you can drag this
8:17onto your toolbar
8:18if you'd like to be able to access it,
8:20or if you run it once,
8:22then you can just right-click on the icon
8:24and keep it on the dock.
8:26Okay, now what it's done,
8:32having launched Postgres, is two things.
8:34It's opened up the browser, and it's not
8:37only done that.
8:38There's a little elephant icon here on the
8:40top right-hand side.
8:41If you just look at where my mouse is
8:42getting large,
8:43just here you can see that there's an
8:45elephant icon,
8:45and that means the Postgres server is
8:47running,
8:48but it needs our password again.
8:49So let's go ahead and enter that and hit
8:52Enter,
8:52and that's it pretty much.
8:54We're in. It's working, and you can see
8:57this is our traditional sort of database
9:00setup
9:00here on the left-hand side,
9:02and you'll find that I've got no tables in
9:04there,
9:05so let's open up Tableau Prep,
9:06and let's write a table to this database.
9:10I'm just going to open up Tableau Prep 2020
9:13.3.
9:14You actually do need the latest version of
9:15Tableau Prep
9:16in order to do this, so if you haven't got
9:182020.3
9:19or if you're watching this in the future,
9:22anything higher than that,
9:23then you won't be able to follow along,
9:25but you can just sort of watch and see how
9:27I do this
9:28just to see that the database is working.
9:31So I'm going to go ahead and close the
9:32registration item,
9:34hit Superstore, and essentially,
9:36this is a standard sort of prep flow.
9:38I'm just going to put this up to sort of
9:40fill the screen,
9:41and I'm going to click on this final output
9:43here on the very end, and the key thing
9:45here,
9:46we just need to change this output from
9:48writing a file
9:49to writing to the database.
9:50So you can see that's the option over here,
9:53and so it's over here on the left-hand side
9:55,
9:55so I'm going to select that database table,
9:58and I'm going to select PostgreSQL,
10:01and the thing to type here is localhost.
10:04If you're running PostgreSQL on your
10:05computer,
10:06localhost basically means this machine.
10:08The name of the database is, surprise,
10:10surprise,
10:10PostgreSQL with one S.
10:12The username is also PostgreSQL with one S,
10:15and my password, I'll just enter that in
10:17here now,
10:18and hit Sign In, and if everything works
10:20properly,
10:21you should just be able to log in.
10:23That sort of initial sort of change on the
10:25screen
10:26was Tableau basically running off the query
10:28to the database to make sure that
10:29everything is there,
10:31and so now we can select a table to write
10:33to.
10:34I'll just call this New Table.
10:36It won't find the new table, and so in this
10:38case,
10:38I'll just hit Create New Table,
10:41and then every time you run the flow,
10:43you can give it an option.
10:44In this case, it's just going to keep app
10:46ending information
10:46to the bottom of the table, right?
10:48So I'm just going to hit Replace Data, okay
10:51,
10:51because if there's no data in the database,
10:53and it's obviously going to put the data
10:54there,
10:55but if you run this flow again,
10:56you don't want to keep writing more rows.
10:59What you actually want to do is expunge the
11:01data,
11:01so go ahead and hit Run Flow,
11:03and now this should successfully complete.
11:06That's all done, and now if I switch over
11:11to my Postgres view, I just hit Refresh,
11:15reload the website, that's absolutely fine.
11:18Then this little hierarchy on the left-hand
11:20side
11:20will change to reflect that I've got a new
11:24database,
11:25so let's just open up this hierarchy,
11:27and you can see that my tables
11:29now have this New Table option
11:31just over here on the left-hand side,
11:33and I've got even the new columns
11:34that we just saw here in Tableau Prep
11:36running and working nicely.
11:38So that's pretty much it.
11:39That's how to install Postgres SQL on your
11:41Mac.
11:42Now, earlier on, I did say I'd show you
11:43how to uninstall this.
11:45If you close all the windows,
11:47let's say you want to get rid of this,
11:48you don't want it on your machine anymore,
11:50you just need to go to your root directory.
11:52So the root directory is basically the hard
11:54drive.
11:55In this case, it's Macintosh HD.
11:57If you've got a Mac and you've never, ever
11:59sort of formatted it or changed anything
12:02default about it,
12:03it should always be called Macintosh HD,
12:05and this is just basically the hard drive.
12:06Then you want to head to Library,
12:08and once you're in the library,
12:09you're looking for the folder called Post
12:11gres,
12:11and in there, you'll have the version of
12:14Postgres,
12:15and if you go into that folder,
12:16you'll see here that this is the uninstall
12:19er,
12:19and when you double-click this uninstaller,
12:21what it will actually do is, again,
12:22ask you for username and password,
12:25and then at the very, very end of this,
12:27it'll ask you what you'd like to remove,
12:29and you can either remove everything
12:31or just specific components that you've
12:33actually installed.
12:34So here, if I tick the individual
12:35components,
12:36it will then ask me, well,
12:37which component would you like to remove?
12:39And then from there on, once you've done
12:41that,
12:41it basically goes ahead and correctly delet
12:44es
12:44the files off your Mac and makes sure
12:46that it doesn't have any remnant
12:48information
12:48like an old database, an old password,
12:51and maybe even things like the
12:52configuration.
12:53It just makes sure you've got a clean start
12:55when it comes to Postgres.
12:57That's it for the video.
12:58I hope you've enjoyed this.
12:59If you like the video, hit Subscribe.
13:01If you don't like the video,
13:02let me know what you'd like to see more of
13:04in the comments below,
13:05and I've really enjoyed getting questions
13:06from the audience,
13:07so if you've got any questions on this
13:08particular video,
13:10by all means, ask away in the comments,
13:11and I try and do my best to go through
13:13every comment.
13:13I read every single one of them.
13:15I don't necessarily have time to respond to
13:17all of them,
13:18but I do read every single comment,
13:19so leave them there,
13:20and I'll try and get to them as soon as I
13:22can.
13:22All right, thanks for watching,
13:23and I'll catch you in the next one.
In this video, I’m showing you how to setup a Postgres Database on your Windows 10 machine for testing purposes. See the sections below. For Windows check out this video. https://youtu.be/4J0V3AaiOns0:00 Intro 0:20 Download Postgres installer1:03 Run the installer / DMG 4:47 Add plugins with stackbuilder. 7:54 Run Postgres -------Join my Discord Server. https://discord.gg/shBuxXr it’s a little sparse at the moment but hang in there.