How to Install Postgres on Mac
How to Install Postgres on Mac
For Mac, what would change is the method of installing postgres
If you already have Homebrew installed, you can install postgress with the command below, if you don’t have Homebrew installed click here to install it.
1
2
3
4
5
$ brew update
$ brew install postgresql
Step 1: Create postgres user:
1
2
3
$ sudo -u postgres createuser --interactive
You should see prompts as shown below:
1
2
3
4
5
Enter name of role to add: test
Shall the new role be a superuser? (y/n) y
Step 2: Create database
1
2
3
$ sudo -u postgres createdb test
1
2
3
4
5
$ sudo -u test psql
Step 3: Assign password to the postgres user
1
2
3
4
5
6
7
8
9
$ sudo -u postgres psql
postgres=# ALTER USER test with PASSWORD 'your-new-password';
Note: Creating a new postgres user is optional, you can make do with the default postgres user if you are want.
1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo -u postgres createdb test // or $ createdb test
$ sudo -u postgres psql
postgres=# ALTER USER postgres with PASSWORD 'your-new-password';
Then, your connection string would be postgres://postgres:your-new-password@localhost:5432/test
Thanks for reading!