-
-
Notifications
You must be signed in to change notification settings - Fork 1
PostgreSQL Installation
Kotz edited this page Dec 28, 2021
·
2 revisions
This guide explains how to setup PostgreSQL on your machine. This is a one-time procedure, if you already have PostgreSQL installed on your machine, do not follow these steps a second time.
Follow the guide for your corresponding operational system.
- Download the latest version of PostgreSQL.
- Run the installer. During installation, you will be asked to define a password for the
postgresuser. Save the password somewhere safe, we will need it later.- There is no need to run the StackBuilder when the installation finishes.
- Search for
psqlon Windows, execute the first result (should be calledSQL Shell (psql)). - A terminal window should open. Hit
Enteruntil it asks for the password for thepostgresuser. Then enter the password (nothing will show up while you're typing it, that's normal) and hitEnter. - You should be logged into PostgreSQL's shell. It looks like this.
- Let's now create a PostgreSQL user. Type in the following command:
CREATE ROLE username LOGIN CREATEDB ENCRYPTED PASSWORD 'my_password';- Replace
usernamewith the actual name you want to use. - Replace
my_passwordwith the actual password you want to use for that user. - Remember both of these as the bot will use these credentials to create and access its database.
- When you're ready, hit
Enterto execute the command.
- Type in
quitto exit the shell. - That's it. You're done setting up PostgreSQL.
- Follow the most appropriate instructions for your distro.
- Once installation is done, type in the following command:
sudo -u postgres psql -c "CREATE ROLE $(whoami) LOGIN CREATEDB ENCRYPTED PASSWORD 'my_password';"- Replace
$(whoami)with the actual name you want to use. If you leave it there, it defaults to your local username. - Replace
my_passwordwith the actual password you want to use for that user. - Remember both of these as the bot will use these credentials to create and access its database.
- When you're ready, hit
Enterto execute the command.
- That's it. You're done setting up PostgreSQL.
There are two ways of installing PostgreSQL on a Macintosh, the first one being the preferable way. Use the second way if the first one doesn't work for any reason.
- Type in "terminal" on Spotlight, open the first result.
- If you don't already have Homebrew, you need to install it by running the following command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Input your user password and hit
Enter. When it asks for confirmation, hitEnteragain. - Wait for it to finish installing (it takes a while).
- (Optional) Once it finishes installing, install Cakebrew by running
brew install cakebrew --caskto have an easy way to manage your brew packages.
- (Optional) Once it finishes installing, install Cakebrew by running
- Now we will use Homebrew to install PostgreSQL. Run the following command:
brew install postgresql
- Then make PostgreSQL start automatically when you turn on your computer:
brew services start postgresql
- By default, Homebrew sets up the PostgreSQL's superuser to the same name as your current user account. This is fine, but may cause issues with most online guides since most of them assume your superuser is called
postgres. Let's remedy this by creating the user with the following command:psql -d postgres -U $(whoami) -c "CREATE ROLE postgres WITH LOGIN SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS ENCRYPTED PASSWORD 'my_password';"- Replace
my_passwordabove with the actual password you want for the superuser.
- Now lets "downgrade" the role that Homebrew created for us:
psql -U postgres -c "ALTER ROLE $(whoami) WITH LOGIN NOSUPERUSER NOCREATEROLE NOREPLICATION NOBYPASSRLS ENCRYPTED PASSWORD 'my_password';"- Replace
my_passwordabove with the actual password you want.
- That's it. You're done setting up PostgreSQL.
- Download the latest version of PostgreSQL.
- Mount the
.dmgfile and run the installer (double-click it). - Go through the setup wizard. During installation, you will be asked to define a password for the
postgresuser. Save the password somewhere safe, we will need it later.- There is no need to run the StackBuilder when the installation finishes.
- Search for
psqlon Spotlight, execute the first result (should be calledSQL Shell (psql)). - A terminal window should open. Hit
Enteruntil it asks for the password for thepostgresuser. Then enter the password (nothing will show up while you're typing it, that's normal) and hitEnter. - You should be logged into PostgreSQL's shell. It looks like this.
- Let's now create a PostgreSQL user. Type in the following command:
CREATE ROLE username LOGIN CREATEDB ENCRYPTED PASSWORD 'my_password';- Replace
usernamewith the actual name you want to use. - Replace
my_passwordwith the actual password you want to use for that user. - Remember both of these as the bot will use these credentials to create and access its database.
- When you're ready, hit
Enterto execute the command.
- Type in
quitto exit the shell. - That's it. You're done setting up PostgreSQL.

