Guide For Postgres SQL
1. Getting Started
Installing postgresql on macOS (using Homebrew):
brew install postgresql
Then start the service:
brew services start postgresql
The next command should fail for you:
psql
by saying something like:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "talkohavy" does not exist
That's because installing postgresql
using brew creates a database named postgres
.
Now, try running:
psql postgres
and you'll be logged in! 🙂
You'll see something like:
psql (14.13 (Homebrew))
Type "help" for help.
postgres=#
Let's list all the available databases to prove postgres is one of them:
\list
or:
\l
for short.
You should see something like:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------+----------+---------+-------+-------------------------
postgres | talkohavy | UTF8 | C | C |
template0 | talkohavy | UTF8 | C | C | =c/talkohavy +
| | | | | talkohavy=CTc/talkohavy
template1 | talkohavy | UTF8 | C | C | =c/talkohavy +
| | | | | talkohavy=CTc/talkohavy
(3 rows)
Let's create a database for your machine name:
CREATE DATABASE talkohavy;
List out your databases again to see that it was actually created:
\list