How to Mac
In this tutorial we will learn to install Postgres.app to use PostgreSQL database on Mac.
Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac app. -- https://postgresapp.com
Visit postgresapp.com and download the software on your Mac.
Run the installer and move the Postgres.app into the Applications directory.
Postgres.app will install on your Mac with the following default settings.
Host | localhost |
Port | 5432 |
User | your system user name |
Database | same as user |
Password | none |
Connection URL | postgresql://localhost |
Open the Postgres.app and you will see the following.
To start the server and list out the database click on the Start button. You will now see your databases.
In the above image you can see the database that is there on my Mac.
To connect to a database using psql just double click on the database.
In the following example I have double clicked on yusufshakeel database and I get to see the following in the terminal.
To list all the databases in the terminal we can use the \l
command like the following.
yusufshakeel=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+--------------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
yusufshakeel | yusufshakeel | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
To switch or connect to a new database in our PostgreSQL local server we can use the \c
command followed by the database name.
In the following example I am connecting from yusufshakeel
database to postgres
database.
yusufshakeel=# \c postgres;
You are now connected to database "postgres" as user "yusufshakeel".
When you are done with your work and want to stop the PostgreSQL server then click on the Stop button.
Alright, this brings us to the end of this tutorial. Please share this tutorial if you find it interesting and helpful. Thanks for reading. Have fun developing.
ADVERTISEMENT